Other meanings of Asynchronous Server Gateway Interface
Web Development
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.
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.
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.
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.
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.
ASGI is a living specification; version 3.0 remains current as of 2025.
Help improve the encyclopedia. Reports go straight to the site manager.