HOME

TheInfoList



OR:

The Asynchronous Server Gateway Interface (ASGI) is a calling convention for
web server A web server is computer software and underlying Computer hardware, hardware that accepts requests via Hypertext Transfer Protocol, HTTP (the network protocol created to distribute web content) or its secure variant HTTPS. A user agent, co ...
s to forward requests to
asynchronous Asynchrony is any dynamic far from synchronization. If and as parts of an asynchronous system become more synchronized, those parts or even the whole system can be said to be in sync. Asynchrony or asynchronous may refer to: Electronics and com ...
-capable
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (prog ...
frameworks, and applications. It is built as a successor to the
Web Server Gateway Interface The Web Server Gateway Interface (WSGI, pronounced ''whiskey'' or ) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, ...
(WSGI). Where
WSGI The Web Server Gateway Interface (WSGI, pronounced ''whiskey'' or ) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, ve ...
provided a standard for synchronous
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (prog ...
applications, ASGI provides one for both asynchronous and synchronous applications, with a
WSGI The Web Server Gateway Interface (WSGI, pronounced ''whiskey'' or ) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, ve ...
backwards-compatibility implementation and multiple servers and application frameworks.


Example

An ASGI-compatible " Hello, World!" application written in
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (prog ...
: async def application(scope, receive, send): event = await receive() ... await send() Where: * Line 1 defines an asynchronous function named , which takes three parameters (unlike in WSGI which takes only two), , and . ** is a containing details about current connection, like the protocol, headers, etc. ** and are asynchronous callables which let the application receive and send messages from/to the client. * Line 2 receives an incoming event, for example, HTTP request or WebSocket message. The keyword is used because the operation is asynchronous. * Line 4 asynchronously sends a response back to the client. In this case, it is a WebSocket communication.


Web Server Gateway Interface (WSGI) compatibility

ASGI is also designed to be a superset of
WSGI The Web Server Gateway Interface (WSGI, pronounced ''whiskey'' or ) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, ve ...
, and there's a defined way of translating between the two, allowing
WSGI The Web Server Gateway Interface (WSGI, pronounced ''whiskey'' or ) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, ve ...
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 The Web Server Gateway Interface (WSGI, pronounced ''whiskey'' or ) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, ve ...
applications away from the async event loop.


See also

*
Comparison of web frameworks Two comparisons of web frameworks are available: * Comparison of JavaScript-based web frameworks This is a comparison of web frameworks for front-end web development that are reliant on JavaScript code for their behavior. General in ...
*
FastCGI FastCGI is a binary protocol for interfacing interactive programs with a web server. It is a variation on the earlier Common Gateway Interface (CGI). FastCGI's main aim is to reduce the overhead related to interfacing between web server and CGI pr ...
*
Python (programming language) Python is a high-level programming language, high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Python is type system#DYNAMIC, dynamically type-checked a ...
* Web Server Gateway Interface (WSGI)


References


External links


Asynchronous Server Gateway Interface Documentation


{{Web frameworks Free software programmed in Python Python (programming language)