Uvicorn
Lightning-fast ASGI server for Python built on uvloop and httptools, running async web apps.
Official Documentation ↗uvicorn 0.30+ / Python 3.9+(ASGI). Check the official docs for the latest API surface.Installation
pip install uvicornMethods
No methods match this filter.
Overview
Uvicorn is an ASGI server for async Python frameworks. It uses uvloop for the event loop and httptools for parsing when available, providing high throughput for I/O-bound applications.
Core Methods
Run programmatically with uvicorn.run or from the command line. Options control host, port, workers, reload and proxy header trust. Reload is for development only.
Usage Notes
Use a process manager or container orchestration for production process supervision, tune workers to CPU for sync workloads, and set proxy settings when behind a load balancer.
Common Pitfalls
Using reload in production wastes resources and is not meant for it. More workers than needed multiply memory and can exceed database connection limits. Trusting proxy headers from any source lets clients spoof their address.
FAQ
- When should I use multiple workers?
- Workers use multiple processes for CPU scaling, suited to sync or CPU-bound handlers. For async I/O-bound apps a single worker is often enough, and workers must not share state.
- What is the difference between reload and workers?
- Reload watches files for development and runs a single process. Workers run multiple processes for production. They cannot be combined because reload needs to manage a single app process.
- How do I run behind a proxy?
- Enable proxy headers so the app trusts X-Forwarded-For and related headers from a known proxy, and configure forwarded-allow-ips to avoid spoofed client addresses.
Report a problem with this API docOpens a pre-filled issue on GitHub.