cheroot.wsgi module

This class holds Cheroot WSGI server implementation.

Simplest example on how to use this server:

from cheroot import wsgi

def my_crazy_app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type','text/plain')]
    start_response(status, response_headers)
    return [b'Hello world!']

addr = '', 8070
server = wsgi.Server(addr, my_crazy_app)

The Cheroot WSGI server can serve as many WSGI applications as you want in one instance by using a PathInfoDispatcher:

path_map = {
    '/': my_crazy_app,
    '/blog': my_blog_app,
d = wsgi.PathInfoDispatcher(path_map)
server = wsgi.Server(addr, d)
class cheroot.wsgi.Gateway(req)

Bases: cheroot.server.Gateway

A base class to interface HTTPServer with WSGI.

classmethod gateway_map()

Create a mapping of gateways and their versions.

dict[tuple[int,int],class]: map of gateway version and
corresponding class

Return a new environ dict targeting the given wsgi.version.


Process the current request.

From PEP 333:

The start_response callable must not actually transmit the response headers. Instead, it must store them for the server or gateway to transmit only after the first iteration of the application return value that yields a NON-EMPTY string, or upon the application’s first invocation of the write() callable.
start_response(status, headers, exc_info=None)

WSGI callable to begin the HTTP response.


WSGI callable to write unbuffered data to the client.

This method is also used internally by start_response (to write data from the iterable returned by the WSGI application).

class cheroot.wsgi.Gateway_10(req)

Bases: cheroot.wsgi.Gateway

A Gateway class to interface HTTPServer with WSGI 1.0.x.


Return a new environ dict targeting the given wsgi.version.

version = (1, 0)
class cheroot.wsgi.Gateway_u0(req)

Bases: cheroot.wsgi.Gateway_10

A Gateway class to interface HTTPServer with WSGI u.0.

WSGI u.0 is an experimental protocol, which uses unicode for keys and values in both Python 2 and Python 3.


Return a new environ dict targeting the given wsgi.version.

version = ('u', 0)
class cheroot.wsgi.PathInfoDispatcher(apps)

Bases: object

A WSGI dispatcher for dispatch based on the PATH_INFO.

class cheroot.wsgi.Server(bind_addr, wsgi_app, numthreads=10, server_name=None, max=-1, request_queue_size=5, timeout=10, shutdown_timeout=5, accepted_queue_size=-1, accepted_queue_timeout=10, peercreds_enabled=False, peercreds_resolve_enabled=False)

Bases: cheroot.server.HTTPServer

A subclass of HTTPServer which calls a WSGI application.


Set minimum number of threads.

wsgi_version = (1, 0)

The version of WSGI to produce.


alias of cheroot.wsgi.Gateway


alias of cheroot.wsgi.Gateway_10


alias of cheroot.wsgi.Gateway_u0


alias of cheroot.wsgi.PathInfoDispatcher


alias of cheroot.wsgi.Server

Indices and tables