An introduction to ASGI, Asynchronous Server Gateway Interface - Philip Jones - PyLondinium19
Channel: PyLondinium
Date: 2019-07-30

If you develop web applications in Python you will almost certainly be doing so using WSGI, with the most popular frameworks, Django and Flask, as well as the majority of others being based upon it. WSGI specifies the interface between servers and applications, simplified this interface is,

def application(environ, start_response):
    start_response("200 OK", [("Content-Type", "text/plain")])
    return b"Hello, World"
with the application called on each request. The request description and environment is specified in the environ dict and the start_response is called to send the response status code and headers before the body, which is returned by the application.

ASGI also aims to specify the interface between servers and applications, only using the async/await syntax, the interface can be simplified to

async def application(scope, receive, send):
    await send({"type": "http.response.start", "status": 200, "headers": [(b"Content-Type", "text/plain")]})
    await send({"type": "http.response.body", "body": b"Hello World"})
with the application awaited on each request and scope fulfilling a similar role to environ.

In this talk I'll explain the above and how it limits WSGI and why ASGI is the solution. I'll also introduce the current ASGI ecosystem and features.

Outline
- Introduction to WSGI (basic code)
- WSGI ecosystem servers (Gunicorn, uWSGI, mod_wsgi) and frameworks (Flask, Django)
- WSGI limitations e.g. Websockets
- ASGI Introduction (basic code)
- ASGI development and history
- ASGI features, websockets, HTTP/2
- ASGI ecosystem servers (Hypercorn, Daphne, Uvicorn) and frameworks (Starlette, Django, Quart).

** Copyright belongs to the speaker **