Asynchronous Server Gateway Interface
Calling convention for web servers From Wikipedia, the free encyclopedia
Calling convention for web servers From Wikipedia, the free encyclopedia
The Asynchronous Server Gateway Interface (ASGI) is a calling convention for web servers to forward requests to asynchronous-capable Python frameworks, and applications. It is built as a successor to the Web Server Gateway Interface (WSGI).
The topic of this article may not meet Wikipedia's general notability guideline. (December 2023) |
Version | 3.0 |
---|---|
Developer | ASGI Team |
Release date | 2019-03-04[1] |
Website | asgi |
License | public domain[2] |
Status | Draft |
Where WSGI provided a standard for synchronous Python application, ASGI provides one for both asynchronous and synchronous applications, with a WSGI backwards-compatibility implementation and multiple servers and application frameworks.
An ASGI-compatible "Hello, World!" application written in Python:
async def application(scope, receive, send):
event = await receive()
...
await send({"type": "websocket.send", ...})
Where:
application
, which takes three parameters (unlike in WSGI which takes only two), scope
, receive
and send
.
scope
is a dict
containing details about current connection, like the protocol, headers, etc.receive
and send
are asynchronous callables which let the application receive and send messages from/to the client.await
keyword is used because the operation is asynchronous.ASGI is also designed to be a superset of WSGI, and there's a defined way of translating between the two, allowing WSGI applications to be run inside ASGI servers through a translation wrapper (provided in the asgiref library). A threadpool can be used to run the synchronous WSGI applications away from the async event loop.
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.