types-gunicorn

raw JSON →
25.3.0.20260508 verified Sat May 09 auth: no python

Typing stubs for gunicorn (version 25.3.0.20260508). Provides type annotations for gunicorn's API, enabling static type checking in Python projects. Part of the typeshed project and updated regularly to match new gunicorn releases.

pip install types-gunicorn
error Module 'gunicorn' has no attribute 'SERVER_SOFTWARE'
cause The stub file for gunicorn does not expose the _gunicorn module or some internal constants.
fix
Use 'from gunicorn import SERVER_SOFTWARE' if it exists at runtime, and add a type: ignore if needed.
error Cannot find reference 'BaseApplication' in 'gunicorn.app'
cause Missing stub for gunicorn.app or incorrect import path.
fix
Ensure you have imported from gunicorn.app.base import BaseApplication, not gunicorn.app.BaseApplication.
error Type of 'app' is partially unknown
cause Stubs may not cover all gunicorn internals; type checker infers Any for some parts.
fix
Explicitly annotate variables or use --strict-optional to enforce type checking.
gotcha Stubs are not a runtime replacement: installing types-gunicorn does not install gunicorn itself. You must separately install gunicorn (e.g., pip install gunicorn).
fix Run pip install gunicorn types-gunicorn.
gotcha The stub version numbers follow the pattern MAJOR.MINOR.PATCH.DATE, where the first three components correspond to the gunicorn version they are bundled with. Do not pin stubs to an exact date unless necessary; they are forward-compatible with that gunicorn major/minor.
fix Use >= matching, e.g., types-gunicorn>=25.3.0, to get latest stubs for that gunicorn version.
gotcha Third-party stubs (like types-*) are unofficial and may have incomplete coverage or minor mismatches with gunicorn internals. For dynamic attributes, you may need to add # type: ignore.
fix When type errors occur on valid gunicorn code, add a comment to ignore the line, e.g., # type: ignore[attr-defined].

Creates a minimal gunicorn application using BaseApplication with proper type annotations.

import gunicorn
from gunicorn.app.base import BaseApplication

class MyApp(BaseApplication):
    def __init__(self, app, options=None):
        self.application = app
        self.options = options or {}
        super().__init__()

    def load_config(self):
        cfg = self.cfg
        for key, value in self.options.items():
            if key in cfg.settings:
                cfg.set(key.lower(), value)

    def load(self):
        return self.application

def dummy_app(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return [b'Hello, World!']

if __name__ == '__main__':
    app = MyApp(dummy_app, {'bind': 'localhost:8000', 'workers': 2})
    app.run()