There are popular servers written in Python that contain WSGI applications and serve HTTP. These servers stand alone when they run; you can proxy to them from your web server.
Gunicorn is a WSGI and HTTP server for UNIX. Below is an example of configuration file with recommended settings.
from multiprocessing import cpu_count # The sockets to bind: bind: list[str] = ["0.0.0.0:8080"] # The maximum number of pending connections: backlog: int = 65535 # Load application code before the worker processes are forked: preload_app: bool = True # The number of worker processes for handling requests: workers: int = cpu_count() # The number of worker threads for handling requests: threads: int = workers * 2
By default, a file named
gunicorn.conf.py will be read from the same
directory where Gunicorn is being run.
$ gunicorn your_project:app
Gunicorn provides many options for configuring the server,
either through a configuration file or with command line options.
gunicorn --help or see the documentation for more information.
uWSGI is a fast application server written in C. Below is an example of configuration file with recommended settings.
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <uwsgi> <http-socket>0.0.0.0:8080</http-socket> <module>your_project</module> <callable>app</callable> <optimize>2</optimize> <processes>%k</processes> <threads>%(processes * 2)</threads> <offload-threads>1</offload-threads> <post-buffering>8192</post-buffering> <harakiri>300</harakiri> <harakiri-verbose/> <listen>65535</listen> <so-keepalive/> <tcp-nodelay/> <limit-post>52428800</limit-post> <!-- 50 megabytes --> <master/> <strict/> <vacuum/> <pcre-jit/> <thunder-lock/> <auto-procname/> <enable-threads/> <disable-logging/> <single-interpreter/> </uwsgi>
To run uWSGI, you must specify the path to the configuration file.
$ uwsgi --xml uwsgi.xml
Keep in mind that uWSGI is an enormous project with hundreds of features and configurations. If you want to use all the features, check out the full documentation.
If you want to deploy your application to another WSGI server, look up the documentation about how to use a WSGI application with it.