Deploying Quart¶
It is not recommended to run Quart directly (via
run()
) in production. Instead it is recommended
that Quart be run using Hypercorn or an alternative ASGI
server. This is becuase the run()
enables
features that help development yet slow production
performance. Hypercorn is installed with Quart and will be used to
serve requests in development mode by default (e.g. with
run()
).
To use Quart with an ASGI server simply point the server at the Quart
application, for example for a simple application in a file called
example.py
,
from quart import Quart
app = Quart(__name__)
@app.route('/')
async def hello():
return 'Hello World'
you can run with Hypercorn using,
hypercorn example:app
See the Hypercorn docs.
Alternative ASGI Servers¶
Server name |
HTTP/2 |
Server Push |
Websocket Response |
---|---|---|---|
✓ |
✓ |
✓ |
|
✗ |
✗ |
✗ |
|
✓ |
✗ |
✗ |
HTTP/2 deployment¶
Most web browsers only support HTTP/2 over a TLS connection with TLSv1.2 or better and certain ciphers. So to use these features with Quart you must chose an ASGI server that implements HTTP/2 and use SSL.
Serverless deployment¶
To deploy Quart in an AWS Lambda & API Gateway setting you will need to use a specialised ASGI function adapter. Mangum is recommended for this and can be as simple as,
from mangum import Mangum
from quart import Quart
app = Quart(__name__)
@app.route("/")
async def index():
return "Hello, world!"
handler = Mangum(app) # optionally set debug=True