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:

from myapp import create_app
from werkzeug import run_simple
Class ​Base​WSGIServer Simple single-threaded, single-process WSGI server.
Class ​Dechunked​Input An input stream that handles Transfer-Encoding 'chunked'
Class ​Forking​WSGIServer A WSGI server that does forking.
Class ​Threaded​WSGIServer A WSGI server that does threading.
Class ​WSGIRequest​Handler 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 socket.bind.
Function is​_running​_from​_reloader Checks if the application is running from within the Werkzeug reloader subprocess.
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 ssl.SSLContext.
Function main A simple command-line interface for run_simple.
Function make​_server Create a new server instance that is either threaded, or forks or just processes one request after another.
Function make​_ssl​_devcert No summary
Function run​_simple Start a WSGI application. Optional features include a reloader, multithreading and fork support.
Function run​_with​_reloader Run a process with the reloader. This is not a public API, do not use this function.
Function select​_address​_family Return AF_INET4, AF_INET6, or AF_UNIX depending on the host and port.
Constant LISTEN​_QUEUE Undocumented
Variable af​_unix Undocumented
Variable can​_fork Undocumented
Variable can​_open​_by​_fd Undocumented
Variable ssl Undocumented
Class _​Ssl​Dummy Undocumented
Function ​_ansi​_style Undocumented
Variable ​_log​_add​_style Undocumented
Variable _​TSSLContext​Arg Undocumented
def generate_adhoc_ssl_context():
Generates an adhoc SSL context for the development server.
Returns
ssl.SSLContextUndocumented
def generate_adhoc_ssl_pair(cn=None):

Undocumented

Parameters
cn:t.Optional[str]Undocumented
Returns
t.Tuple[Certificate, RSAPrivateKeyWithSerialization]Undocumented
def get_interface_ip(family):
Get the IP address of an external interface. Used when binding to 0.0.0.0 or ::1 to show a more useful URL.
Parameters
family:socket.AddressFamilyUndocumented
Returns
strUndocumented
Unknown Field: meta
private
def get_sockaddr(host, port, family):
Return a fully qualified socket address that can be passed to socket.bind.
Parameters
host:strUndocumented
port:intUndocumented
family:socket.AddressFamilyUndocumented
Returns
t.Union[t.Tuple[str, int], str]Undocumented
def is_running_from_reloader():

Checks if the application is running from within the Werkzeug reloader subprocess.

New in version 0.10.
Returns
boolUndocumented
def is_ssl_error(error=None):
Checks if the given error (or the current one) is an SSL error.
Parameters
error:t.Optional[Exception]Undocumented
Returns
boolUndocumented
def load_ssl_context(cert_file, pkey_file=None, protocol=None):
Loads SSL context from cert/private key files and optional protocol. Many parameters are directly taken from the API of ssl.SSLContext.
Parameters
cert​_file:strPath of the certificate to use.
pkey​_file:t.Optional[str]Path of the private key to use. If not given, the key will be obtained from the certificate file.
protocol:t.Optional[int]A PROTOCOL constant from the ssl module. Defaults to ssl.PROTOCOL_TLS_SERVER.
Returns
ssl.SSLContextUndocumented
def main():
A simple command-line interface for run_simple.
def make_server(host, port, app, threaded=False, processes=1, request_handler=None, passthrough_errors=False, ssl_context=None, fd=None):
Create a new server instance that is either threaded, or forks or just processes one request after another.
Parameters
host:strUndocumented
port:intUndocumented
app:WSGIApplicationUndocumented
threaded:boolUndocumented
processes:intUndocumented
request​_handler:t.Optional[t.Type[WSGIRequestHandler]]Undocumented
passthrough​_errors:boolUndocumented
ssl​_context:t.Optional[_TSSLContextArg]Undocumented
fd:t.Optional[int]Undocumented
Returns
BaseWSGIServerUndocumented
def make_ssl_devcert(base_path, host=None, cn=None):

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 run_simple.

New in version 0.9.
Parameters
base​_path:strthe path to the certificate and key. The extension .crt is added for the certificate, .key is added for the key.
host:t.Optional[str]the name of the host. This can be used as an alternative for the cn.
cn:t.Optional[str]the CN to use.
Returns
t.Tuple[str, str]Undocumented
def run_simple(hostname, port, application, use_reloader=False, use_debugger=False, use_evalex=True, extra_files=None, exclude_patterns=None, reloader_interval=1, reloader_type='auto', threaded=False, processes=1, request_handler=None, static_files=None, passthrough_errors=False, ssl_context=None):

Start a WSGI application. Optional features include a reloader, multithreading and fork support.

This function has a command-line interface too:

python -m werkzeug.serving --help
Changed in version 2.0: Added exclude_patterns parameter.
New in version 0.5: static_files was added to simplify serving of static files as well as passthrough_errors.
New in version 0.6: support for SSL was added.
New in version 0.8: Added support for automatically loading a SSL context from certificate file and private key.
New in version 0.9: Added command-line interface.
New in version 0.10: Improved the reloader and added support for changing the backend through the reloader_type parameter. See :ref:`reloader` for more information.
Changed in version 0.15: Bind to a Unix socket by passing a path that starts with unix:// as the hostname.
Parameters
hostname:strThe host to bind to, for example 'localhost'. If the value is a path that starts with unix:// it will bind to a Unix socket instead of a TCP socket..
port:intThe port for the server. eg: 8080
application:WSGIApplicationthe WSGI application to execute
use​_reloader:boolshould the server automatically restart the python process if modules were changed?
use​_debugger:boolshould the werkzeug debugging system be used?
use​_evalex:boolshould the exception evaluation feature be enabled?
extra​_files:t.Optional[t.Iterable[str]]a list of files the reloader should watch additionally to the modules. For example configuration files.
exclude​_patterns:t.Optional[t.Iterable[str]]List of fnmatch patterns to ignore when running the reloader. For example, ignore cache files that shouldn't reload when updated.
reloader​_interval:intthe interval for the reloader in seconds.
reloader​_type:strthe type of reloader to use. The default is auto detection. Valid values are 'stat' and 'watchdog'. See :ref:`reloader` for more information.
threaded:boolshould the process handle each request in a separate thread?
processes:intif greater than 1 then handle each request in a new process up to this maximum number of concurrent processes.
request​_handler:t.Optional[t.Type[WSGIRequestHandler]]optional parameter that can be used to replace the default one. You can use this to replace it with a different ~BaseHTTPServer.BaseHTTPRequestHandler subclass.
static​_files:t.Optional[t.Dict[str, t.Union[str, t.Tuple[str, str]]]]a list or dict of paths for static files. This works exactly like SharedDataMiddleware, it's actually just wrapping the application in that middleware before serving.
passthrough​_errors:boolset this to True to disable the error catching. This means that the server will die on errors but it can be useful to hook debuggers in (pdb etc.)
ssl​_context:t.Optional[_TSSLContextArg]an SSL context for the connection. Either an ssl.SSLContext, a tuple in the form (cert_file, pkey_file), the string 'adhoc' if the server should automatically create one, or None to disable SSL (which is the default).
def run_with_reloader(*args, **kwargs):

Run a process with the reloader. This is not a public API, do not use this function.

Deprecated since version 2.0: Will be removed in Werkzeug 2.1.
Parameters
*args:t.AnyUndocumented
**kwargs:t.AnyUndocumented
def select_address_family(host, port):
Return AF_INET4, AF_INET6, or AF_UNIX depending on the host and port.
Parameters
host:strUndocumented
port:intUndocumented
Returns
socket.AddressFamilyUndocumented
LISTEN_QUEUE: int =

Undocumented

Value
128
af_unix =

Undocumented

can_fork =

Undocumented

can_open_by_fd =

Undocumented

ssl =

Undocumented

def _ansi_style(value, *styles):

Undocumented

Parameters
value:strUndocumented
*styles:strUndocumented
Returns
strUndocumented
_log_add_style: bool =

Undocumented

_TSSLContextArg =

Undocumented