module documentation

A WSGI and HTTP server for use **during development only**. This server is convenient to use, but is not designed to be particularly stable, secure, or efficient. Use a dedicate WSGI server and HTTP server when deploying to production. It provides features like interactive debugging and code reloading. Use ``run_simple`` to start the server. Put this in a ``run.py`` script: .. code-block:: python from myapp import create_app from werkzeug import run_simple

Class BaseWSGIServer A WSGI server that that handles one request at a time.
Class DechunkedInput An input stream that handles Transfer-Encoding 'chunked'
Class ForkingWSGIServer A WSGI server that handles concurrent requests in separate forked processes.
Class ThreadedWSGIServer A WSGI server that handles concurrent requests in separate threads.
Class WSGIRequestHandler A request handler that implements WSGI dispatching.
Function generate_adhoc_ssl_context Generates an adhoc SSL context for the development server.
Function generate_adhoc_ssl_pair Undocumented
Function get_interface_ip Get the IP address of an external interface. Used when binding to 0.0.0.0 or ::1 to show a more useful URL.
Function get_sockaddr Return a fully qualified socket address that can be passed to :func:`socket.bind`.
Function is_running_from_reloader Check if the server is running as a subprocess within the Werkzeug reloader.
Function is_ssl_error Checks if the given error (or the current one) is an SSL error.
Function load_ssl_context Loads SSL context from cert/private key files and optional protocol. Many parameters are directly taken from the API of :py:class:`ssl.SSLContext`.
Function make_server Create an appropriate WSGI server instance based on the value of ``threaded`` and ``processes``.
Function make_ssl_devcert Creates an SSL key for development. This should be used instead of the ``'adhoc'`` key which generates a new cert on each server start. It accepts a path for where it should store the key and cert and either a host or CN...
Function run_simple Start a development server for a WSGI application. Various optional features can be enabled.
Function select_address_family Return ``AF_INET4``, ``AF_INET6``, or ``AF_UNIX`` depending on the host and port.
Constant LISTEN_QUEUE Undocumented
Variable can_fork Undocumented
Function _ansi_style Undocumented
Type Alias _TSSLContextArg Undocumented
Variable _log_add_style Undocumented
def generate_adhoc_ssl_context() -> ssl.SSLContext: (source)

Generates an adhoc SSL context for the development server.

def generate_adhoc_ssl_pair(cn: t.Optional[str] = None) -> t.Tuple[Certificate, RSAPrivateKeyWithSerialization]: (source)

Undocumented

def get_interface_ip(family: socket.AddressFamily) -> str: (source)

Get the IP address of an external interface. Used when binding to 0.0.0.0 or ::1 to show a more useful URL. :meta private:

def get_sockaddr(host: str, port: int, family: socket.AddressFamily) -> t.Union[t.Tuple[str, int], str]: (source)

Return a fully qualified socket address that can be passed to :func:`socket.bind`.

def is_running_from_reloader() -> bool: (source)

Check if the server is running as a subprocess within the Werkzeug reloader. .. versionadded:: 0.10

def is_ssl_error(error: t.Optional[Exception] = None) -> bool: (source)

Checks if the given error (or the current one) is an SSL error.

def load_ssl_context(cert_file: str, pkey_file: t.Optional[str] = None, protocol: t.Optional[int] = None) -> ssl.SSLContext: (source)

Loads SSL context from cert/private key files and optional protocol. Many parameters are directly taken from the API of :py:class:`ssl.SSLContext`. :param cert_file: Path of the certificate to use. :param pkey_file: Path of the private key to use. If not given, the key will be obtained from the certificate file. :param protocol: A ``PROTOCOL`` constant from the :mod:`ssl` module. Defaults to :data:`ssl.PROTOCOL_TLS_SERVER`.

def make_server(host: str, port: int, app: WSGIApplication, threaded: bool = False, processes: int = 1, request_handler: t.Optional[t.Type[WSGIRequestHandler]] = None, passthrough_errors: bool = False, ssl_context: t.Optional[_TSSLContextArg] = None, fd: t.Optional[int] = None) -> BaseWSGIServer: (source)

Create an appropriate WSGI server instance based on the value of ``threaded`` and ``processes``. This is called from :func:`run_simple`, but can be used separately to have access to the server object, such as to run it in a separate thread. See :func:`run_simple` for parameter docs.

def make_ssl_devcert(base_path: str, host: t.Optional[str] = None, cn: t.Optional[str] = None) -> t.Tuple[str, str]: (source)

Creates an SSL key for development. This should be used instead of the ``'adhoc'`` key which generates a new cert on each server start. It accepts a path for where it should store the key and cert and either a host or CN. If a host is given it will use the CN ``*.host/CN=host``. For more information see :func:`run_simple`. .. versionadded:: 0.9 :param base_path: the path to the certificate and key. The extension ``.crt`` is added for the certificate, ``.key`` is added for the key. :param host: the name of the host. This can be used as an alternative for the `cn`. :param cn: the `CN` to use.

def run_simple(hostname: str, port: int, application: WSGIApplication, use_reloader: bool = False, use_debugger: bool = False, use_evalex: bool = True, extra_files: t.Optional[t.Iterable[str]] = None, exclude_patterns: t.Optional[t.Iterable[str]] = None, reloader_interval: int = 1, reloader_type: str = 'auto', threaded: bool = False, processes: int = 1, request_handler: t.Optional[t.Type[WSGIRequestHandler]] = None, static_files: t.Optional[t.Dict[str, t.Union[str, t.Tuple[str, str]]]] = None, passthrough_errors: bool = False, ssl_context: t.Optional[_TSSLContextArg] = None): (source)

Start a development server for a WSGI application. Various optional features can be enabled. .. warning:: Do not use the development server when deploying to production. It is intended for use only during local development. It is not designed to be particularly efficient, stable, or secure. :param hostname: The host to bind to, for example ``'localhost'``. Can be a domain, IPv4 or IPv6 address, or file path starting with ``unix://`` for a Unix socket. :param port: The port to bind to, for example ``8080``. Using ``0`` tells the OS to pick a random free port. :param application: The WSGI application to run. :param use_reloader: Use a reloader process to restart the server process when files are changed. :param use_debugger: Use Werkzeug's debugger, which will show formatted tracebacks on unhandled exceptions. :param use_evalex: Make the debugger interactive. A Python terminal can be opened for any frame in the traceback. Some protection is provided by requiring a PIN, but this should never be enabled on a publicly visible server. :param extra_files: The reloader will watch these files for changes in addition to Python modules. For example, watch a configuration file. :param exclude_patterns: The reloader will ignore changes to any files matching these :mod:`fnmatch` patterns. For example, ignore cache files. :param reloader_interval: How often the reloader tries to check for changes. :param reloader_type: The reloader to use. The ``'stat'`` reloader is built in, but may require significant CPU to watch files. The ``'watchdog'`` reloader is much more efficient but requires installing the ``watchdog`` package first. :param threaded: Handle concurrent requests using threads. Cannot be used with ``processes``. :param processes: Handle concurrent requests using up to this number of processes. Cannot be used with ``threaded``. :param request_handler: Use a different :class:`~BaseHTTPServer.BaseHTTPRequestHandler` subclass to handle requests. :param static_files: A dict mapping URL prefixes to directories to serve static files from using :class:`~werkzeug.middleware.SharedDataMiddleware`. :param passthrough_errors: Don't catch unhandled exceptions at the server level, let the serve crash instead. If ``use_debugger`` is enabled, the debugger will still catch such errors. :param ssl_context: Configure TLS to serve over HTTPS. Can be an :class:`ssl.SSLContext` object, a ``(cert_file, key_file)`` tuple to create a typical context, or the string ``'adhoc'`` to generate a temporary self-signed certificate. .. versionchanged:: 2.1 Instructions are shown for dealing with an "address already in use" error. .. versionchanged:: 2.1 Running on ``0.0.0.0`` or ``::`` shows the loopback IP in addition to a real IP. .. versionchanged:: 2.1 The command-line interface was removed. .. versionchanged:: 2.0 Running on ``0.0.0.0`` or ``::`` shows a real IP address that was bound as well as a warning not to run the development server in production. .. versionchanged:: 2.0 The ``exclude_patterns`` parameter was added. .. versionchanged:: 0.15 Bind to a Unix socket by passing a ``hostname`` that starts with ``unix://``. .. versionchanged:: 0.10 Improved the reloader and added support for changing the backend through the ``reloader_type`` parameter. .. versionchanged:: 0.9 A command-line interface was added. .. versionchanged:: 0.8 ``ssl_context`` can be a tuple of paths to the certificate and private key files. .. versionchanged:: 0.6 The ``ssl_context`` parameter was added. .. versionchanged:: 0.5 The ``static_files`` and ``passthrough_errors`` parameters were added.

def select_address_family(host: str, port: int) -> socket.AddressFamily: (source)

Return ``AF_INET4``, ``AF_INET6``, or ``AF_UNIX`` depending on the host and port.

LISTEN_QUEUE: int = (source)

Undocumented

Value
128
can_fork = (source)

Undocumented

def _ansi_style(value: str, *styles: str) -> str: (source)

Undocumented

_TSSLContextArg = (source)

Undocumented

Value
t.Optional[t.Union['ssl.SSLContext',
                   t.Tuple[str, t.Optional[str]],
                   'te.Literal[\'adhoc\']']]
_log_add_style: bool = (source)

Undocumented