Skip to content
hostcomplex

WSGI vs ASGI

Maarten Soetens 2 min read

What WSGI and ASGI Are

WSGI (Web Server Gateway Interface) and ASGI (Asynchronous Server Gateway Interface) are standards that define how a Python web application receives requests from a server and returns responses. Because both are standard, a framework can run on any compatible server, and a server can run any compatible framework.

WSGI has been the standard for Python web applications for many years and is described in PEP 3333. ASGI extends the same idea to asynchronous code, which is needed for features such as long-lived connections and WebSockets that WSGI was not designed to handle.

Application Servers: Gunicorn, Uvicorn and Others

An application server is the program that implements the interface and runs the Python code. Gunicorn is a widely used WSGI server, and it runs several worker processes so that multiple requests can be handled at once. Uvicorn is a common ASGI server built on asynchronous I/O. Other servers, such as Hypercorn, also support ASGI.

These servers usually sit behind a web server such as Nginx or Apache. The web server handles encryption, static files and traffic from many visitors, then passes application requests to Gunicorn or Uvicorn. This is the same division of labour described in web server vs application server.

Why Async Support Matters for Python Hosting

In a WSGI application, each worker handles one request at a time. If a request waits for a slow external API or a database query, that worker stays occupied. To handle more simultaneous visitors, you add more workers, and each worker uses more memory.

An ASGI application can pause while it waits for input or output and serve other requests in the meantime. This is valuable for chat features, streaming responses and APIs that call several external services. For a typical site that renders pages from a local database, WSGI remains a sound and common choice. For the wider picture, see Python for web development.

Frequently asked questions

Does Django support ASGI?

Yes. Django supports both WSGI and ASGI, so an application can run under either type of server. Its synchronous views work with WSGI, and current Django releases also support asynchronous views under ASGI. Check the documentation for the version you use, because these details change over time.

Should I choose WSGI or ASGI?

Choose WSGI for conventional applications that render pages with synchronous database access, since its tooling is mature and widely deployed. Choose ASGI when you need WebSockets, streaming or many concurrent requests that spend time waiting. Your framework may decide the question, because Flask is built on WSGI while FastAPI is built on ASGI. For a comparison of two common Python frameworks, see Django vs Flask.

  • Two-Factor Authentication

    Two factor authentication hosting adds a second check to control panel, domain and CMS logins. Learn which methods are strongest and why 2FA helps.

  • What Is an A Record?

    What is an A record? Learn how this DNS record maps a hostname to an IPv4 address, why domains use several A records and the root and www pattern.

  • Billing and Automation Platforms

    What is WHMCS? Learn how this commercial billing and automation platform helps hosts sell plans, collect payments and create accounts automatically.