Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Asynchronous Server Gateway Interface

From Wikipedia, the free encyclopedia
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)
Calling convention for web servers
ASGI Specification
Version3.0
DeveloperASGI Team
Release date2019-03-04[1]
Websiteasgi.readthedocs.io/en/latest/specs/index.html
Licensepublic domain[2]
StatusDraft

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.

Example

[edit]

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

asyncdefapplication(scope,receive,send):event=awaitreceive()...awaitsend({"type":"websocket.send",...})

Where:

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

See also

[edit]

References

[edit]
  1. ^"Version History".
  2. ^"Copyright".GitHub. Retrieved2022-09-14.

External links

[edit]
Implementations
IDEs
Topics
Designer
.NET
C++
ColdFusion
Common Lisp
Haskell
Java
JavaScript
Perl
PHP
Python
Ruby
Rust
Scala
Smalltalk
Other languages
Retrieved from "https://en.wikipedia.org/w/index.php?title=Asynchronous_Server_Gateway_Interface&oldid=1295689745"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp