The deployment mainly involves these parts:
Web applications
Most of the time they are written using Python web frameworks, like Django, Flask, FastAPI.
Web servers
Like Gunicorn, Uvicorn. Their major feature is to handle HTTP/HTTPS protocol.
Specifications
They describe how a web server communicates with web applications.
WSGI (Web Server Gateway Interface)
It provides a standard for synchronous Python apps.
ASGI (Asynchronous Server Gateway Interface)
It provides a standard for both asynchronous and synchronous apps, with a WSGI backwards-compatibility implementation.
A TLS termination proxy
In the product environment, you may need a TLS termination proxy, like Nginx, Caddy.
A monitoring tool
In the product environment, you may need a tool to make sure the web server is run on startup and restart it after failures, like Supervisor, Systemd, Docker, Kubernetes.
Web Servers | WSGI | ASGI | HTTP/2 | HTTP/3 | WebSocket |
---|---|---|---|---|---|
Gunicorn | Y | ||||
Apache + mod_wsgi | Y | ||||
Daphne | Y | Y | Y | ||
Hypercorn | Y | Y | Y | ||
Uvicorn | Y | Y |
uWSGI is in maintenance mode.
Web Servers | Django | Flask | FastAPI |
---|---|---|---|
Gunicorn | Y | Y | Y (Gunicorn + Uvicorn) |
Apache + mod_wsgi | Y | Y | |
Daphne | Y | ||
Hypercorn | Y | ||
Uvicorn | Y | Y |
The web servers used by Django, Flask and FastAPI are selected based on recommendations in their official documentation.
If you’d like to use an ASGI server for Flask you will need to utilize WSGI to ASGI middleware.
Uvicorn has a Gunicorn-compatible worker class, when you use Gunicorn with Uvicorn for FastAPI, Gunicorn acts as a process manager, it would transmit the communication to the worker processes running the Uvicorn class.