Again, this is mostly a reminder for my own work.
One common use case is to quickly set up a web server to host your app at various stages of development.
This is only a low-functioning, generally insecure server option...
python3 -m http.server -d ~/dev/myCurrentApplication/ 8080 --bind 127.0.0.1
Gunicorn https://gunicorn.org/
Gunicorn is a Python WSGI HTTP Server for UNIX.
Install using pip
$ pip3 install gunicorn
Start the app using gunicorn:
$ gunicorn --bind 0.0.0.0:8001 run:app
Point your browser at http://localhost:8001
.
Waitress (think Gunicorn for Windows), a production-quality pure-Python WSGI server. It has no dependencies outside the Python standard library.
Install using pip
$ pip3 install waitress
Start the app using waitress-serve
$ waitress-serve --port=8001 run:app
Point your browser at http://localhost:8001
.
uWSGI, performant WSGI server implementation for UNIX.
Install using pip
Install the latest stable release:
$ pip3 install uwsgi
Or install the latest LTS (long term support) release:
pip3 install https://projects.unbit.it/downloads/uwsgi-lts.tar.gz
Start uWSGI to run an HTTP server/router passing requests to your Flask application:
uwsgi --http 127.0.0.1:8001 --wsgi-file myflaskapp.py --callable app
Or start uWSGI to run an HTTP server/router passing requests to your native WSGI application:
$ uwsgi --http 127.0.0.1:8001 --wsgi-file helloworld.py
Point your browser at http://localhost:8001
.
uWSGI has lots of startup options to enhance performance and production readiness. See:
- The WSGI QuickStart for some of them: https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
- Another primer: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04
The examples above assume Flask, but there are options: https://rapidapi.com/blog/best-python-api-frameworks/