asgi-examples
asgi-examples copied to clipboard
A collection of example ASGI applications
asgi-examples
ASGI (Asynchronous Server Gateway Interface) examples and information.
ASGI application example
Here are two examples of writing an ASGI application in its simplest form.
As a function
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
As a class
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!"})
Frameworks / Adapters / Middlewares
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
Servers
Tools
- uvicorn-gunicorn-fastapi-docker
- uvicorn-gunicorn-starlette-docker
- uvicorn-gunicorn-docker
- asgi-scope
Running the applications
An ASGI server is required to run the examples. For example, to run an application using uvicorn, use the following command:
$ uvicorn app:app
Reference
Below are links to various ASGI-related projects and information.
Specification
Misc
- 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
Discussions
Contributing
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.