Gunicorn (short for "Green Unicorn") is a Python Web Server Gateway Interface (WSGI) HTTP server. It is a pre-fork worker model ported from Ruby's Unicorn project. The Gunicorn server is broadly compatible with a number of web frameworks, simply implemented, light on server resources, and fairly fast. It is often paired with nginx, as the two have complementary features.
Overview
Gunicorn is a production-ready WSGI HTTP server for UNIX systems. It acts as an intermediary between a web application written in Python and the outside web layer, forwarding HTTP requests to the application and returning responses. It is widely used to run Python web applications built on frameworks such as Django, Flask, and FastAPI in production environments.
History
Gunicorn was originally published by Benoit Chesneau on 20 February 2010. It was designed as a pre-fork worker model, a design pattern ported from Ruby's Unicorn project. The project is maintained by volunteer developers and is distributed under the MIT License.
Architecture
Gunicorn uses a pre-fork worker model, which consists of the following components:
- Master: The central process that manages the worker processes.
- Sync workers: Default worker type that handles one request at a time per worker.
- Async workers: Workers that can handle multiple concurrent requests.
- Tornado workers: Workers that integrate with the Tornado asynchronous networking library.
- AsyncIO workers: Workers that support Python's asyncio framework.
Features
- Natively supports WSGI, web2py, Django, and Paster
- Automatic worker process management
- Simple Python configuration
- Multiple worker configurations
- Various server hooks for extensibility
- Compatible with Python 2.6+ and Python 3.2+
Common Deployment
Gunicorn is frequently deployed behind a reverse proxy such as nginx. In this configuration, nginx handles static files, SSL termination, and incoming HTTP requests, while Gunicorn runs the Python application instances via the WSGI interface. This setup is a common production architecture for Python web applications.
Pronunciation
The name "Gunicorn" is pronounced either "jee-unicorn" or "gun-i-corn," as noted in the project's documentation and community discussions.
References
- Official website: gunicorn.org
- Repository: github.com/benoitc/gunicorn
- PyPI listing: pypi.org/project/gunicorn