The goal of WSGI is to facilitate easy interconnection of existing servers and applications or frameworks, not to create a new web framework.
The two sides of WSGI
The WSGI interface has two sides:
- the server or gateway side, and
- the application or framework side.
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. |
Links
wsgiref is the reference implementation for WSGI.
WSGIUtils are standalone utility libraries to ease WSGI application development:
- wsgiServer, a multi-threaded WSGI web server based on SimpleHTTPServer (=
http.server
?)
- wsgiAdaptor, a simple WSGI application that provides basic authentication, signed cookies and persistent sessions.
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.