WSGI (Flask)
WSGI (Web Server Gateway Interface) is the Python standard that lets web servers talk to Python web applications. A Flask app is a WSGI application, which is why servers like gunicorn, uWSGI, and Werkzeug can run it.
Flask
WSGI defines a simple contract: a web app is a callable that takes an environ dict (the request) and a start_response function, and returns the response body. This standard means any WSGI server can run any WSGI framework, including Flask, Django, and Pyramid.
Flask implements this contract for you. The Flask object is itself the WSGI callable (via app.wsgi_app), so you point a production server at it — typically as the import string 'module:app' — and the server handles networking while Flask handles routing and logic.
WSGI is synchronous; for async views and websockets Python uses the newer ASGI standard, which Flask supports partially and frameworks like FastAPI use natively.
Syntax
gunicorn "myapp:app" # myapp.py defines appExamples
Python
# A WSGI app is just a callable:
def simple_app(environ, start_response):
start_response("200 OK", [("Content-Type", "text/plain")])
return [b"Hello WSGI"]
# Flask's app is a fancier version of this callable.