How to Deploy Python Web Applications?

The deployment mainly involves these parts:

  1. Web applications

    Most of the time they are written using Python web frameworks, like Django, Flask, FastAPI.

  2. Web servers

    Like Gunicorn, Uvicorn. Their major feature is to handle HTTP/HTTPS protocol.

  3. 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.

  4. A TLS termination proxy

    In the product environment, you may need a TLS termination proxy, like Nginx, Caddy.

  5. 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 ServersWSGIASGIHTTP/2HTTP/3WebSocket
GunicornY
Apache + mod_wsgiY
DaphneYYY
HypercornYYY
UvicornYY

uWSGI is in maintenance mode.

Web ServersDjangoFlaskFastAPI
GunicornYYY (Gunicorn + Uvicorn)
Apache + mod_wsgiYY
DaphneY
HypercornY
UvicornYY

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.