Member-only story
Introduction to Waitress: A WSGI Server for Python 2 and 3
Self-host and serve your Flask server to a production WSGI server

If you have been running your Flask server via the command line:
python myapp.py
You will see the following output:
When you are running publicly, it is highly recommended not to use the development server provided by Werkzeug as it is not meant for production. The development server is not efficient, stable, or secure.
You can choose either to deploy it on a third-party host such as Heroku or self-host it with a standalone container.
Waitress is one example of such a container that works for both Windows and Linux. Based on the official documentation, Waitress is meant to be:
“… a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones that live in the Python standard library. It runs on CPython on Unix and Windows.”
This tutorial contains three sections:
- Setup
- Basic usage
- Conclusion
1. Setup
The installation is pretty simple. It is highly recommended to create a virtual environment before you install Waitress via the pip install
command.
pip install waitress
You should be able to install it easily without any problem. Let’s move on to the next section to find out more about basic usage.
2. Basic Usage
You need to first import waitress
via the following command:
from waitress import serve
I will be using app
as the variable name for the Flask server. Modify this according to the name that you have set.
app = Flask(__name__)
Comment out the app.run
in your main server and add the following code.
By default, Waitress
binds to any IPv4 address on port 8080. You can omit the host
and port
…