ASGI interface module
From the docs:
ASGI (Asynchronous Server Gateway Interface) is a spiritual successor to WSGI, intended to provide a standard interface between async-capable Python web servers, frameworks, and applications.
Heard about this from here:
If you are starting a new project, you might benefit from a newer and faster framework based on ASGI instead of WSGI (Flask and Django are WSGI-based).
...Also, if you want to use new technologies like WebSockets it would be easier (and possible) with a newer framework based on ASGI, like FastAPI or Starlette. As the standard ASGI was designed to be able to handle asynchronous code like the one needed for WebSockets.
Check out Starlette, Uvicorn, or FastAPI to see how it is implemented. It looks like FastAPI depends on Starlette, and Starlette is using Anyio as an underlying library. This module: asgiref also looks useful.
The current reference server is Daphne:
The current ASGI reference server, written in Twisted and maintained as part of the Django Channels project. Supports HTTP/1, HTTP/2, and WebSockets.
https://github.com/Jaymon/endpoints/issues/118
Links I had open
- Tornado Async support issue - still open as of October 10, 2021
- Python ASGI web frameworks benchmark - Something called blacksheep is the fastest
- ASGI spec - There is some good stuff here on how to implement the spec if you click around, I think I prefer this pdf though which is just this information but all in one document (even if it is a pdf)
- Daphne webserver - This is what I have been using to test Endpoints's ASGI interface
-
Django's ASGI handler - look here for inspiration on how to handle an ASGI request, specifically the
ASGIHandlerclass - a2wsgi github - Convert WSGI app to ASGI app or ASGI app to WSGI app.
Search
- tornado or asgi
- asgi daphne says version 3 but lools to be 2
Some notes I had open while messing with Daphne:
daphne -b 0.0.0.0 -p 4000 asgi:application
pip install daphne
request object:
args (1) =
(
0:
{
'type': "http",
'http_version': "1.1",
'method': "GET",
'path': "/foo/bar",
'raw_path': b'/foo/bar',
'root_path': "",
'scheme': "http",
'query_string': b'',
'headers':
[
0:
(
0: b'host',
1: b'localhost:4000'
),
1:
(
0: b'user-agent',
1: b'curl/7.58.0'
),
2:
(
0: b'accept',
1: b'*/*'
)
],
'client':
[
0: "127.0.0.1",
1: 33958
],
'server':
[
0: "127.0.0.1",
1: 4000
],
'asgi':
{
'version': "3.0"
}
}
)