ASGI (Asynchronous Server Gateway Interface) examples and information.
Here are two examples of writing an ASGI application in its simplest form.
def app(scope):
async def asgi(receive, send):
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [[b"content-type", b"text/plain"]],
}
)
await send({"type": "http.response.body", "body": b"Hello, world!"})
return asgi
class App:
def __init__(self, scope):
self.scope = scope
async def __call__(self, receive, send):
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [[b"content-type", b"text/plain"]],
}
)
await send({"type": "http.response.body", "body": b"Hello, world!"})
Below are various frameworks, adapters, and middlewares that use ASGI.
- Channels
- Starlette
- Quart
- Quart Trio
- Asgish
- FastAPI
- Responder
- Lemon
- Nardis
- Bocadillo
- Sentry ASGI
- Mangum
- Bonnette
- uvicorn-gunicorn-fastapi-docker
- uvicorn-gunicorn-starlette-docker
- uvicorn-gunicorn-docker
- asgi-scope
An ASGI server is required to run the examples. For example, to run an application using uvicorn
, use the following command:
$ uvicorn app:app
Below are links to various ASGI-related projects and information.
- A Django Async Roadmap
- Writing an ASGI Web Framework
- Embracing ASGI with Quart; Introducing Hypercorn
- Quart; an ASGI alternative to Flask
- An Asyncio socket tutorial
- Pyramid cookbook recipe
- Quart-Trio - A Trio based HTTP Framework
- Hello, ASGI - Introduction to the emerging ASGI standard
- Working with ASGI and HTTP
- Working with HTTP requests in ASGI
Please open an issue or pull request if you would like to contribute to the examples or README. The issue tracker may also be used for any informal ASGI-related discussions or questions.