← New search

Other meanings of Asynchronous Server Gateway Interface

Web Development

Asynchronous Server Gateway Interface

The Asynchronous Server Gateway Interface (ASGI) is a specification for asynchronous web servers and Python web frameworks, extending the Web Server Gateway Interface (WSGI) to support asynchronous request handling, WebSockets, and other long-lived connections. It defines a standard interface between Python web applications and servers, enabling them to communicate asynchronously and handle concurrent connections efficiently.

2019
First stable release
ASGI 2.0
3.0
Current major version
ASGI 3.0 (2020)
~100
Adopting frameworks
Estimated number of ASGI-compatible frameworks and servers
1

Core Concepts and Design

ASGI defines a callable that takes a single scope dictionary, a receive callable, and a send callable, returning an awaitable. The scope contains request metadata (e.g., method, path, headers), while receive and send are asynchronous functions for receiving and sending messages, enabling bidirectional communication. This design supports both HTTP and non-HTTP protocols like WebSockets, making it suitable for real-time applications.

The specification is split into two parts: the server side and the application side. Servers like Uvicorn and Daphne implement the ASGI protocol, while frameworks like Starlette and FastAPI provide application-level abstractions. ASGI is backward-compatible with WSGI through an adapter, allowing synchronous applications to run on ASGI servers.

2

History and Development

ASGI was proposed in 2016 by Andrew Godwin, a Django core developer, to address WSGI's limitations with asynchronous Python. WSGI, introduced in 2003, was synchronous and blocking, making it unsuitable for WebSockets and high-concurrency workloads. The first draft of ASGI was published in 2016, and version 2.0 was released in 2019, followed by version 3.0 in 2020, which clarified the specification and added support for lifespan events.

The specification is maintained by the ASGI organization on GitHub, with contributions from the Django and Starlette communities. It has been adopted by major frameworks, including Django (via Channels), FastAPI, and Quart, and is supported by servers such as Uvicorn, Hypercorn, and Daphne.

3

Adoption and Ecosystem

ASGI has become the standard for asynchronous Python web development, particularly for applications requiring real-time features like chat, live notifications, and streaming. FastAPI, built on Starlette, leverages ASGI for high-performance APIs, while Django Channels enables WebSocket support in Django. The ecosystem includes middleware, authentication, and database integrations that are ASGI-compatible.

ASGI also supports server-sent events and HTTP/2, and it is used in production by companies like Netflix and Instagram for scalable services. The specification's flexibility allows it to be implemented in other languages, though it is primarily a Python standard.

4

Lesser-known aspects

ASGI includes a lifespan protocol that manages application startup and shutdown, allowing resources like database connections to be initialized and cleaned up gracefully. This is often overlooked but critical for production deployments.

Another niche feature is the ability to run ASGI applications on multiple worker processes, with servers like Uvicorn supporting worker management. Additionally, ASGI's message format is extensible, enabling custom protocols beyond HTTP and WebSockets, such as raw TCP or UDP, though these are rarely used.

ASGI also has a testing suite, asgi-lifespan, and supports middleware that can wrap applications to add functionality like CORS or authentication.

Glossary

ASGI
Asynchronous Server Gateway Interface, a specification for asynchronous web servers and Python web frameworks.
WSGI
Web Server Gateway Interface, the predecessor of ASGI, designed for synchronous Python web applications.
WebSocket
A protocol providing full-duplex communication over a single TCP connection, supported by ASGI.
Uvicorn
A popular ASGI server implementation written in Python.
Lifespan
An ASGI protocol for handling application startup and shutdown events.

ASGI is a living specification; version 3.0 remains current as of 2025.