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.

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?

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