I was trying to figure out steps involved in deploying a typical Flask framework based Python web application in a production environment. This writeup has details of my findings.
Flask framework does have a built-in server. But it is suitable only for development purposes and cannot be used in a production environment as it does not scale well. So to deploy a Flask based web application in production, we need to pick a WSGI compliant server.
What is WSGI?
WSGI stands for Web Server Gateway Interface. It is a standard specification that the web server has to implement to run a Python web application. A typical web server does not have the ability to run Python web applications. Historically, Apache server's module implementation called mod_python used to be the only web server option for running Python web applications. The Python community recognized the need for standardization around this and came up with the WSGI interface. With this WSGI standard, web servers have to implement the server side of the WSGI interface and Flask application object is the actual WSGI application. Flask derives WSGI application functionality from Werkzeug which is a comprehensive WSGI web application library.
Below illustration shows what happens when a user makes a request to a Python web application hosted in a production environment:
There are several WSGI compliant server options to choose from to host Python web applications. Also, both hosted and self-hosted options are available. Below link from Flask documentation website has a list of deployment options along with their deployment steps.