Search notes:

PEP 3333 - Python Web Server Gateway Interface v1.0.1 (WSGI)

PEP 3333 proposes a simple and universal interface between webservers and Python web applications or frameworks, similar to the Java servlet API.
The goal of WSGI is to facilitate easy interconnection of existing servers and applications or frameworks, not to create a new web framework.

Callables

WSGI specifies a few callable interfaces. Their arguments are always positional and must not be called with argument names.

The two sides of WSGI

The WSGI interface has two sides:
The server side invokes a callable object that is provided by the application side.

Callable object of the application

The application's callable object has two arguments:
environ A dict whose key/value pairs correspond to (CGI style) environment variables and, additionally, with the following keys: wsgi.input (which contains the data of the body of POST requests), wsgi.errors, wsgi.version, wsgi.multithread, wsgi.multiprocess, wsgi.run_once
start_response A callable that accepts three parameters which is called by the callable object provided by the application side. The three parameters are status, response_headers and (default) exc_info. start_response returns a write(body_data) callable (but this callable should not be used as it exists for historical reasons only).
The arguments are positional, hence they're not required to be named exactly as listed above.
The callable object returns an iterable of zero or more byte strings.

Callable object passed as start_response

status Used to set the HTTP response's status code (such as 200 OK or 404 Not Found).
response_headers A list of tuples, each of which has two elements: the header's name and value.

Strings

WSGI defines two types of strings:

Stacking WSGI applications

WSGI compliant applications can be stacked:

TODO

The Pylons project build Web Technologies for Python environments.
The uwsgi (lowercase) protocol is the native protocol used by the uWSGI server.

See also

Gunicorn is a Python WSGI HTTP server running on Unix.
Serving images with WSGI.
Reading a POST request's data from environ['wsgi.input'].
ASGI (Asynchronous Server Gateway Interface) is the successor to WSGI. Unlike WSGI, ASGI provides a standard for asynchronous apps (but is backwards compatible to WSGI).
There's mod_wsgi for the Apache Webserver.
A small list of other interesting PEPs

Links

https://peps.python.org/pep-0249/
wsgiref is the reference implementation for WSGI.
WSGIUtils are standalone utility libraries to ease WSGI application development:
WebOb (which has largely replaced Paste) provides wrappers around the WSGI request environment, and an object to help create WSGI responses.
The objects map much of the specified behavior of HTTP, including header parsing, content negotiation and correct handling of conditional and range requests.

Index