| 1 |
.. _deployment: |
| 2 |
|
| 3 |
Deploying Quart |
| 4 |
=============== |
| 5 |
|
| 6 |
It is not recommended to run Quart directly (via |
| 7 |
:meth:`~quart.app.Quart.run`) in production. Instead it is recommended |
| 8 |
that Quart be run using `Hypercorn |
| 9 |
<https://github.com/pgjones/hypercorn>`_ or an alternative ASGI |
| 10 |
server. This is because the :meth:`~quart.app.Quart.run` enables |
| 11 |
features that help development yet slow production |
| 12 |
performance. Hypercorn is installed with Quart and will be used to |
| 13 |
serve requests in development mode by default (e.g. with |
| 14 |
:meth:`~quart.app.Quart.run`). |
| 15 |
|
| 16 |
To use Quart with an ASGI server simply point the server at the Quart |
| 17 |
application, for example, |
| 18 |
|
| 19 |
.. code-block:: python |
| 20 |
:caption: example.py |
| 21 |
|
| 22 |
from quart import Quart |
| 23 |
|
| 24 |
app = Quart(__name__) |
| 25 |
|
| 26 |
@app.route('/') |
| 27 |
async def hello(): |
| 28 |
return 'Hello World' |
| 29 |
|
| 30 |
you can run with Hypercorn using, |
| 31 |
|
| 32 |
.. code-block:: bash |
| 33 |
|
| 34 |
hypercorn example:app |
| 35 |
|
| 36 |
See the `Hypercorn docs <https://hypercorn.readthedocs.io/>`_. |
| 37 |
|
| 38 |
Alternative ASGI Servers |
| 39 |
------------------------ |
| 40 |
|
| 41 |
Alongside `Hypercorn <https://github.com/pgjones/hypercorn>`_, `Daphne |
| 42 |
<https://github.com/django/daphne>`_, and `Uvicorn |
| 43 |
<https://github.com/encode/uvicorn>`_ are available ASGI servers that |
| 44 |
work with Quart. |
| 45 |
|
| 46 |
Serverless deployment |
| 47 |
--------------------- |
| 48 |
|
| 49 |
To deploy Quart in an AWS Lambda & API Gateway setting you will need to use a specialised |
| 50 |
ASGI function adapter. `Mangum <https://github.com/erm/mangum>`_ is |
| 51 |
recommended for this and can be as simple as, |
| 52 |
|
| 53 |
.. code-block:: python |
| 54 |
|
| 55 |
from mangum import Mangum |
| 56 |
from quart import Quart |
| 57 |
|
| 58 |
app = Quart(__name__) |
| 59 |
|
| 60 |
@app.route("/") |
| 61 |
async def index(): |
| 62 |
return "Hello, world!" |
| 63 |
|
| 64 |
handler = Mangum(app) # optionally set debug=True |