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

pippip install gunicorn

Methods

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.

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.