File: waitress.rst

package info (click to toggle)
python-werkzeug 2.2.2-3%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,248 kB
  • sloc: python: 22,177; javascript: 304; makefile: 32; xml: 16; sh: 10
file content (75 lines) | stat: -rw-r--r-- 2,328 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
65
66
67
68
69
70
71
72
73
74
75
Waitress
========

`Waitress`_ is a pure Python WSGI server.

*   It is easy to configure.
*   It supports Windows directly.
*   It is easy to install as it does not require additional dependencies
    or compilation.
*   It does not support streaming requests, full request data is always
    buffered.
*   It uses a single process with multiple thread workers.

This page outlines the basics of running Waitress. Be sure to read its
documentation and ``waitress-serve --help`` to understand what features
are available.

.. _Waitress: https://docs.pylonsproject.org/projects/waitress/


Installing
----------

Create a virtualenv, install your application, then install
``waitress``.

.. code-block:: text

    $ cd hello-app
    $ python -m venv venv
    $ . venv/bin/activate
    $ pip install .  # install your application
    $ pip install waitress


Running
-------

The only required argument to ``waitress-serve`` tells it how to load
your application. The syntax is ``{module}:{app}``. ``module`` is
the dotted import name to the module with your application. ``app`` is
the variable with the application. If you're using the app factory
pattern, use ``--call {module}:{factory}`` instead.

.. code-block:: text

    # equivalent to 'from hello import app'
    $ waitress-serve hello:app --host 127.0.0.1

    # equivalent to 'from hello import create_app; create_app()'
    $ waitress-serve --call hello:create_app --host 127.0.0.1

    Serving on http://127.0.0.1:8080

The ``--host`` option binds the server to local ``127.0.0.1`` only.

Logs for each request aren't shown, only errors are shown. Logging can
be configured through the Python interface instead of the command line.


Binding Externally
------------------

Waitress should not be run as root because it would cause your
application code to run as root, which is not secure. However, this
means it will not be possible to bind to port 80 or 443. Instead, a
reverse proxy such as :doc:`nginx` or :doc:`apache-httpd` should be used
in front of Waitress.

You can bind to all external IPs on a non-privileged port by not
specifying the ``--host`` option. Don't do this when using a revers
proxy setup, otherwise it will be possible to bypass the proxy.

``0.0.0.0`` is not a valid address to navigate to, you'd use a specific
IP address in your browser.