gitmyhub

gunicorn

Python ★ 11k updated 1d ago

gunicorn 'Green Unicorn' is a WSGI HTTP Server for UNIX, fast clients and sleepy applications.

Gunicorn is a Python web server that sits between nginx and your Python app, handling incoming HTTP requests and distributing them across worker processes so multiple users can be served at the same time.

PythonWSGIASGIgeventHTTP/2setup: easycomplexity 2/5

Gunicorn, short for Green Unicorn, is a web server for Python applications. Its specific job is to sit between a reverse proxy like nginx and your Python web application, handling the work of accepting incoming HTTP requests and passing them to your app code. It follows a standard called WSGI, which defines how Python web frameworks and web servers talk to each other, meaning it works with Django, Flask, Pyramid, and most other Python web frameworks without any special configuration.

The way Gunicorn manages work is called the pre-fork worker model. When it starts, it launches several worker processes that each wait for requests. This lets it handle multiple visitors at the same time across separate processes, which is important for running a real production website. You control how many workers run with a single flag. Several worker types are available: a basic synchronous worker, a threaded worker, an asynchronous worker using the gevent library, and an ASGI worker for newer Python frameworks like FastAPI and Starlette.

Version 25 added beta support for HTTP/2, the newer version of the web protocol that allows multiplexed streams, meaning multiple requests can share one connection. It also introduced a feature called Dirty Arbiters for workloads where individual requests take a long time, such as running machine learning models.

Installing Gunicorn is one pip command. Starting it requires pointing it at your application object with a command like gunicorn myapp:app. Full documentation covering quickstart, configuration, and deployment is available at the project's website.

Gunicorn is released under the MIT license and has been maintained by volunteers since 2010. The README notes it is volunteer-maintained and asks organizations running it in production to consider sponsoring the project.

Where it fits