File: deployment.rst

package info (click to toggle)
quart 0.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,888 kB
  • sloc: python: 8,644; makefile: 42; sh: 17; sql: 6
file content (64 lines) | stat: -rw-r--r-- 1,714 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
.. _deployment:

Deploying Quart
===============

It is not recommended to run Quart directly (via
:meth:`~quart.app.Quart.run`) in production. Instead it is recommended
that Quart be run using `Hypercorn
<https://github.com/pgjones/hypercorn>`_ or an alternative ASGI
server. This is because the :meth:`~quart.app.Quart.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
:meth:`~quart.app.Quart.run`).

To use Quart with an ASGI server simply point the server at the Quart
application, for example,

.. code-block:: python
   :caption: example.py

    from quart import Quart

    app = Quart(__name__)

    @app.route('/')
    async def hello():
        return 'Hello World'

you can run with Hypercorn using,

.. code-block:: bash

    hypercorn example:app

See the `Hypercorn docs <https://hypercorn.readthedocs.io/>`_.

Alternative ASGI Servers
------------------------

Alongside `Hypercorn <https://github.com/pgjones/hypercorn>`_, `Daphne
<https://github.com/django/daphne>`_, and `Uvicorn
<https://github.com/encode/uvicorn>`_ are available ASGI servers that
work with Quart.

Serverless deployment
---------------------

To deploy Quart in an AWS Lambda & API Gateway setting you will need to use a specialised
ASGI function adapter. `Mangum <https://github.com/erm/mangum>`_ is
recommended for this and can be as simple as,

.. code-block:: python

    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