ASGI Specification
Version3.0
DeveloperASGI Team
Release date2019-03-04[1]
Websiteasgi.readthedocs.io/en/latest/specs/index.html
LicensePublic domain[2]
StatusDraft

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).

Where WSGI provided a standard for synchronous Python applications, ASGI provides one for both asynchronous and synchronous applications, with a WSGI backwards-compatibility implementation and multiple servers and application frameworks.

Example

edit

An ASGI-compatible "Hello, World!" application written in Python:

async def application(scope, receive, send):
    event = await receive()
    ...
    await send({"type": "websocket.send", ...})

Where:

  • Line 1 defines an asynchronous function named 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.
  • Line 2 receives an incoming event, for example, HTTP request or WebSocket message. The await 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

edit

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.

See also

edit

References

edit
  1. ^ "Version History".
  2. ^ "Copyright". GitHub. Retrieved 2022-09-14.
edit

📚 Artikel Terkait di Wikipedia

Time formatting and storage bugs

freeze. Until version 6.0, Microsoft's .NET platform had a bug that caused threadpool hill-climbing[clarification needed] to fail periodically after 49.7 days

Object pool pattern

there are a few objects that implement this pattern. System.Threading.ThreadPool is configured to have a predefined number of threads to allocate. When

Windows Native API

Language Support (similar to code pages). Pfx for prefix handling. Tp for threadpool handling. user32.dll and gdi32.dll include several other calls that execute

Apache Commons

Locale and a message key Scaffold Toolkit for building web applications ThreadPool Simple component for asynchronously dispatching work to another thread

Oxygene (programming language)

tasks must be distributed among several threads. The .NET Framework's ThreadPool class offered a way to efficiently work with several threads. The Task