WSGI refers to Web Server Gateway Interface. WSGI plays a vital role at the time when you deploy your Django or Flask application.

WSGI is a specification that describes the communication between web servers and Python web applications or frameworks. It explains how a web server communicates with python web applications/frameworks and how web applications/frameworks can be chained for processing a request.

Python standard WSGI has been explained in detail with PEP 3333.

📌 How does WSGI work?

So, to obtain a clear understanding of WSGI, let us assume a case scenario where you have a web application developed in Django or Flask application.

Since a web application is deployed in the web server, the figure below represents the web server that obtains requests from various users.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0e4a460c-8521-4c0f-80e8-83abb24489f1/Untitled.png

The above web server can be apache, NGINX, etc., server which is responsible for handling various static files and caching purposes. Furthermore, you can also use the server as a load balancer if you are willing to scale multiple applications.

Now a question arises—How can a web server interact with the Python application?

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/c4eec475-4735-44c4-91d9-3833aeefd3b7/Untitled.png

So, now a problem arises as a web server has to interact with a Python application.