Embracing ASGI with Quart; Introducing Hypercorn

Philip Jones
Jun 17, 2018 · 2 min read

The latest release of Quart, 0.6.0, changes Quart to be a pure ASGI framework and introduces Hypercorn as an ASGI server based on the serving code previously in Quart. This means that you can continue to use Hypercorn to serve Quart, or switch to any other ASGI framework-server combination.

It is now possible for uvicorn to serve Quart, allowing for a a nice logo combination.

What is ASGI?

ASGI, Asynchronous Server Gateway Interface, is a specification that defines how web servers can asynchronously interface with web applications or frameworks. It is inspired by WSGI, Web Server Gateway Interface, which has been actively used in Python since 2003. ASGI itself comes in two very distinct forms, the deprecated version 1.0 and the newer version 2.0 that Quart and Hypercorn implement.

WSGI was introduced at a time when Python had many web frameworks that were also servers. This was considered a problem as the choice of the framework limited the choice of web server and vice versa. This is the same position we are in today with async frameworks such as Sanic or AIOHTTP. This situation has arisen as the WSGI specification cannot be applied to async frameworks, however the ASGI specification can be.

As with the introduction of WSGI, the existence of ASGI does nothing to address the current state rather existing frameworks must adapt. Hopefully Quart doing so will encourage others to follow suite.

ASGI Servers

An ASGI server is responsible for receiving data as raw bytes and interpreting the bytes in terms of the HTTP or Websocket protocol. Once it has done so it can then send this information to the ASGI Framework.

Currently there are three ASGI servers, Hypercorn, Uvicorn, and Daphne. These mostly differ in the choice of HTTP/Websocket parser.

ASGI Frameworks

An ASGI Framework is responsible for receiving messages from the ASGI server, acting on them and returning messages indicating how the server should respond.

Currently there are three ASGI frameworks, Django Channels, Quart, and APIStar. These are significantly different, and represent distinct use cases.

Introducing Hypercorn

Hypercorn is the Quart serving code spun out as a standalone ASGI server. It is the only ASGI server to support the websocket-response and HTTP/2 server push ASGI-extensions.

Hypercorn is based on the very robust hyper, h11, h2, and wsproto libraries. It can also optionally be used with uvloop for additional performance. The intention is for Hypercorm to be a very robust ASGI server.

To use Hypercorn simply pip install hypercorn and then run hypercorn module:app replacing module and app with the name of the module an ASGI framework application is defined within. Otherwise see the Hypercorn docs.

Philip Jones

Written by

Head of Engineering at Octopus Wealth. Maintainer of Quart, Hypercorn and various other Python HTTP projects.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade