The WSGI Protocol

Learn about WSGI protocol in Python.

Before considering a REST API, one needs to know the first layer of abstraction of the Python world when HTTP is involved: WSGI.

WSGI

WSGI stands for Web Server Gateway Interface. It started its life as part of PEP 0333, and was updated as part of PEP 3333. This PEP was designed to solve the problem of mixing frameworks and web servers. It makes sure there is a common protocol between web servers and web frameworks, so they are not necessarily tied together. Indeed, it would be a shame to be forced to provide a web server for each framework, wherein there is already a vast collection of likely better alternatives out there.

The WSGI protocol is pretty easy to understand, and this understanding is also valuable as all Python frameworks are based on it.

When a WSGI web server loads an application, it looks for an application object that is callable. Calling this object must return a result that is shipped back to the HTTP client.

Get hands-on with 1200+ tech skills courses.