Uvicorn
By Encode / open-source community
Uvicorn is a lightning-fast ASGI (Asynchronous Server Gateway Interface) server for Python that runs asynchronous web applications and frameworks such as FastAPI and Starlette. It is built on top of uvloop, a fast drop-in replacement for…
Definition
Uvicorn is a lightning-fast ASGI (Asynchronous Server Gateway Interface) server for Python that runs asynchronous web applications and frameworks such as FastAPI and Starlette. It is built on top of uvloop, a fast drop-in replacement for the default asyncio event loop, and httptools, a high-performance HTTP parser, allowing it to handle concurrent connections without blocking on I/O the way traditional synchronous WSGI servers do. It is distributed as an open-source Python package and is typically installed alongside the framework it will serve.
Overview
Uvicorn exists because Python's older WSGI standard was designed for synchronous, one-request-per-thread applications and cannot natively support long-lived connections such as WebSockets or the kind of concurrent async request handling that modern APIs require. ASGI was created to fill that gap, and Uvicorn is the reference implementation most developers reach for to actually run an ASGI application in production or during local development. Mechanically, Uvicorn sits between the network and an ASGI-compliant Python application. It accepts incoming TCP connections, parses raw HTTP bytes into structured request objects using httptools, and hands them to the application as async callables that can `await` database calls, external API requests, or other I/O without tying up an OS thread. Under the hood it swaps in uvloop, a Cython-based event loop built on libuv, which measurably outperforms Python's stdlib asyncio loop for socket-heavy workloads. This combination is what lets a single Uvicorn worker process juggle thousands of concurrent connections. Within the Python web-serving landscape, Uvicorn is positioned as the async counterpart to Gunicorn's traditional sync worker model. It does not compete with frameworks like FastAPI or Django; it is the layer beneath them that actually speaks HTTP to the outside world. It is commonly paired with Gunicorn itself, using Gunicorn's process manager to supervise multiple Uvicorn worker processes, which adds pre-fork process management, graceful restarts, and worker health checks that Uvicorn alone does not provide. In practice, teams run Uvicorn directly during development for its fast reload and simple command-line invocation, and run it behind Gunicorn (via the `uvicorn.workers.UvicornWorker` class) or behind a reverse proxy such as Nginx in production for load balancing and TLS termination. It is the default recommended server for FastAPI applications and is widely used for async microservices, WebSocket-based real-time features, and streaming API responses. Uvicorn's main limitation is that it assumes the application code is genuinely async-friendly; blocking calls inside an async handler (a synchronous database driver, for example) will stall the entire event loop rather than just one request, unlike a thread-per-request WSGI server where a blocking call only ties up one thread. It also has a smaller surface of built-in process-management features than Gunicorn, which is why the two are frequently combined rather than treated as alternatives. Teams migrating an older synchronous codebase to Uvicorn often discover blocking calls they had not noticed, since a WSGI server would have hidden the cost behind extra threads or processes while Uvicorn surfaces it immediately as degraded throughput across all concurrent requests. For this reason, adopting Uvicorn is usually paired with an audit of the application's dependencies to confirm database drivers, HTTP clients, and file I/O libraries all offer genuinely async-compatible variants rather than synchronous code wrapped in a thread pool.
Key Features
- Implements the ASGI specification for async Python web applications
- Uses uvloop as a high-performance replacement for the default event loop
- Uses httptools for fast, low-level HTTP request parsing
- Supports HTTP/1.1 and WebSocket protocols out of the box
- Provides an auto-reload mode for local development workflows
- Can run standalone or as a worker class managed by Gunicorn
- Exposes a simple command-line interface and programmatic API
- Supports HTTPS via TLS certificate configuration