With my recent dedicated introduction to the Python language I have become very appreciative of the highly composable nature of WSGI applications.
In a functional style you are able to compose a desired application from many different components, using the middleware ideology.
The benefits of this approach can be clearly seen in the contrived example depicted below, which is based on my previous Flask example.
As you can see we are able to secure a specified WSGI application with the provided ‘Auth’ middleware.
The advantages of using this loosely coupled approach allows us to easily replace the authentication implementation with an alternative (i.e. OAuth) in future builds, without alteration to encapsulated applications.