Uvicorn
FastAPI apps are ASGI applications, and Uvicorn is a fast ASGI server that runs them. Uvicorn is not a framework - it speaks the ASGI protocol, loads your app, handles the network, and calls your endpoints. FastAPI provides the routing and validation; Uvicorn provides the process.
Install
pip install "uvicorn[standard]"
The [standard] extra adds uvloop and httptools for better performance.
Run an App
uvicorn main:app --reload
The main:app argument is module.attribute: the module main and the app object inside it. Common flags:
- --reload - restart on code changes (development only).
- --host 0.0.0.0 - listen on all network interfaces.
- --port 8000 - change the port.
- --workers 4 - run multiple worker processes (production; requires an async app).
Production Patterns
For a small deployment, run Uvicorn behind a process manager or in a container:
# inside Docker
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]
For larger deployments, put a reverse proxy (nginx, Caddy, Traefik) in front: terminate TLS, serve static files, and proxy to Uvicorn workers.
Uvicorn vs Gunicorn
Gunicorn is a WSGI process manager for sync frameworks like Flask. For ASGI apps you can either run Uvicorn directly with --workers, or run Gunicorn with the uvicorn worker class (gunicorn -k uvicorn.workers.UvicornWorker main:app) to get Gunicorn's process supervision. For most services, Uvicorn with --workers is sufficient.
Summary
Uvicorn is the ASGI server that runs FastAPI: pip install "uvicorn[standard]", then uvicorn main:app --reload in development and uvicorn main:app --host 0.0.0.0 --workers N in production, usually behind a reverse proxy for TLS and static files.