pyuwsgi
pyuwsgi is the official Python package providing the uWSGI server, a fast, self-healing, and developer-friendly application server for web applications. It serves as a glue layer between Python web applications (WSGI) and various protocols like HTTP, SCGI, and FastCGI. The current stable version is 2.0.30.post1, and it generally follows the release cadence of the underlying uWSGI C core.
Warnings
- gotcha pyuwsgi provides the uWSGI server *executable*, not a Python library to import for server management. Attempting to `import uwsgi` to start or manage the server from your application code will not work as expected; the `uwsgi` module is for applications *already running within* a uWSGI instance to interact with the server environment (e.g., `uwsgi.log()`, `uwsgi.cache_get()`).
- gotcha Installation via `pip install pyuwsgi` often requires C compilers (like `gcc`) and Python development headers (e.g., `python3-dev` on Debian/Ubuntu, `build-essential`, or Xcode Command Line Tools on macOS) to be present on the system, as `pyuwsgi` is a C extension. Without these, `pip` might fail to compile and install the package.
- gotcha uWSGI offers a vast array of configuration options, typically managed via `.ini` files. While command-line arguments are suitable for simple cases, production deployments almost universally use `.ini` files for clarity, reusability, and advanced features (e.g., multiple processes, logging, master/worker management).
- gotcha For robust production environments, it's highly recommended to run uWSGI behind a reverse proxy server like Nginx or Caddy. The reverse proxy can handle static file serving, SSL/TLS termination, request buffering, and load balancing more efficiently and securely than uWSGI directly.
Install
-
pip install pyuwsgi
Imports
- uwsgi
import uwsgi
Quickstart
import os
def application(environ, start_response):
# A minimal WSGI application
status = '200 OK'
headers = [('Content-type', 'text/plain')]
start_response(status, headers)
return [b"Hello from uWSGI!"]
# To run this, save it as `app.py` and then run:
# uwsgi --http :8000 --wsgi-file app.py --callable application
# Or, if `uwsgi` executable isn't in your PATH:
# python -m uwsgi --http :8000 --wsgi-file app.py --callable application