2. PEP 3333

The WSGI protocol is described in PEP 3333.

Phillip J. Eby created PEP 333 – Python Web Server Gateway Interface v1.0 in 2003. PEP 333 proposes a simple and universal interface between web servers and web applications or frameworks, akin to the Java “servlet” API. The main design goal for WSGI - the Python Web Server Gateway Interface - was simplicity, based on the argument that it must be easy for both web server and framework authors and maintainers to add the new and therefore unused WSGI interface to their software.

PEP 3333 – Python Web Server Gateway Interface v1.0.1 dates from 2010 and updates PEP 333 by adding rules for the proper handling of strings and unicode in Python 3 and by incorporating some long-standing de facto amendments to the WSGI protocol.

The WSGI specification identifies two sides: a “server” or “gateway” side, and an “application” or “framework” side. The server side invokes a callable object that is provided by the application side. The application callable is called once for each HTTP request received from a client. It takes two arguments:

  • A Python builtin dict containing CGI style environment variables

  • a callable accepting two required positional arguments containing the HTTP response status and headers, and one optional argument containing error information provided by the application in case of an exception

Note

In Zope4, this callable is defined as ZPublisher.WSGIPublisher.publish_module. The main entry point for creating the Zope WSGI application is Zope2.Startup.run.make_wsgi_app. This function will set up the Zope instance from zope.conf and return the publish_module callable.