This articlerelies excessively onreferences toprimary sources. Please improve this article by addingsecondary or tertiary sources. Find sources: "Asynchronous Server Gateway Interface" – news ·newspapers ·books ·scholar ·JSTOR(June 2025) (Learn how and when to remove this message) |
Version | 3.0 |
---|---|
Developer | ASGI Team |
Release date | 2019-03-04[1] |
Website | asgi |
License | public domain[2] |
Status | Draft |
TheAsynchronous Server Gateway Interface (ASGI) is a calling convention forweb servers to forward requests toasynchronous-capablePython frameworks, and applications. It is built as a successor to theWeb Server Gateway Interface (WSGI).
WhereWSGI provided a standard for synchronousPython applications, ASGI provides one for both asynchronous and synchronous applications, with aWSGI backwards-compatibility implementation and multiple servers and application frameworks.
An ASGI-compatible "Hello, World!" application written inPython:
asyncdefapplication(scope,receive,send):event=awaitreceive()...awaitsend({"type":"websocket.send",...})
Where:
application
, which takes three parameters (unlike in WSGI which takes only two),scope
,receive
andsend
.scope
is adict
containing details about current connection, like the protocol, headers, etc.receive
andsend
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 ofWSGI, and there's a defined way of translating between the two, allowingWSGI applications to be run inside ASGI servers through a translation wrapper (provided in the asgiref library). A threadpool can be used to run the synchronousWSGI applications away from the async event loop.