API Reference
Gunicorn
A pre-fork WSGI HTTP server for Python and the standard production runner for Flask and Django apps.
Official Documentation ↗CompatibilityThis documentation covers version
v21. Check the official docs for the latest API surface.Installation
pip
pip install gunicornMethods
No methods match this filter.
Gunicorn forks worker processes behind a master, providing process supervision and graceful reloads.
Key Features
- Pre-fork worker model with a master process
- Sync and async worker classes
- Graceful reload and config files
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Security
Official security statements captured from the package documentation:
- 官方 Settings 页 Security 章节:限制请求头数量用于缓解 DDoS — “This parameter is used to limit the number of headers in a request to prevent DDOS attack.” (source: https://docs.gunicorn.org/en/stable/settings.html, fetched 2026-11-08T18:03:00+08:00)
- 官方 Settings 页 Security 章节:限制请求行长度用于防止 DDoS — “This parameter can be used to prevent any DDOS attack.” (source: https://docs.gunicorn.org/en/stable/settings.html, fetched 2026-11-08T18:03:00+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T18:03:00+08:00 via WebFetch https://docs.gunicorn.org/en/stable/run.html;WebFetch https://docs.gunicorn.org/en/stable/settings.html;WebFetch https://raw.githubusercontent.com/benoitc/gunicorn/master/examples/example_config.py.
gunicorn (CLI)→ signature from https://docs.gunicorn.org/en/stable/run.html; official text: “Basic usage: $ gunicorn [ OPTIONS ] [ WSGI_APP ] Where WSGI_APP is of the pattern $(MODULE_NAME):$(VARIABLE_NAME). The module name can be a full dotted path.”gunicorn.conf.py→ signature from https://raw.githubusercontent.com/benoitc/gunicorn/master/examples/example_config.py; official text: “bind = ‘127.0.0.1:8000’ backlog = 2048 … workers = 1 worker_class = ‘sync’ worker_connections = 1000 timeout = 30 keepalive = 2”server hooks→ signature from https://docs.gunicorn.org/en/stable/settings.html; official text: “on_starting Default: def on_starting(server): pass Called just before the master process is initialized. The callable needs to accept a single instance variable for the Arbiter.”
FAQ
- How many workers should I use?
- A common starting point is (2 x CPU cores) + 1 for sync workers, then measure and tune based on memory and latency.
- Why does my app hang on deploy?
- A worker exceeding the timeout is killed and restarted. Raise timeout for long requests or move the work to a background queue.
- What is the difference between sync and gthread workers?
- Sync handles one request per worker at a time; gthread uses threads and suits IO-bound apps that are not async.
Report a problem with this API docOpens a pre-filled issue on GitHub.