explaingit

magicstack/uvloop

11,783CythonAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

uvloop replaces Python's default asyncio event loop with one built on libuv, the same networking engine as Node.js, making asyncio programs 2 to 4 times faster with almost no code changes required.

Mindmap

mindmap
  root((uvloop))
    What It Does
      Faster asyncio loop
      Drop-in replacement
      No API changes
    Under the Hood
      Cython compiled
      libuv networking
      Node.js engine
    Performance
      2 to 4x faster
      More connections
      Lower CPU use
    Use Cases
      Web servers
      Async APIs
      Network services
    Audience
      Python developers
      Backend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Speed up an existing asyncio web server by swapping asyncio.run() for uvloop.run() with no other code changes.

USE CASE 2

Handle significantly more simultaneous connections on the same hardware for a Python async API service.

USE CASE 3

Reduce hosting costs by getting more throughput from a Python network service without rewriting it in another language.

USE CASE 4

Benchmark a Python async service before and after adding uvloop to measure the real-world performance difference.

Tech stack

PythonCythonlibuvasyncio

Getting it running

Difficulty · easy Time to first run · 5min

Building from source requires Cython and make, pip install is sufficient for standard use.

Dual-licensed MIT and Apache 2.0, use freely for any purpose, including commercial projects, under either license.

In plain English

uvloop is a Python library that speeds up programs built with asyncio, which is Python's built-in system for handling many things at once without blocking other work. Python's default asyncio event loop is adequate for many use cases, but uvloop replaces it with something faster, without requiring you to change how your program is structured. According to the project's benchmarks, uvloop makes asyncio programs run 2 to 4 times faster. It is built using Cython, a tool that lets Python code compile closer to the speed of C, and it relies on libuv, the same networking engine used inside Node.js. The combination of those two means network-heavy programs, like web servers or services that handle many simultaneous connections, can process significantly more requests with the same hardware. Using it requires almost no code changes. The standard way is to call uvloop.run() instead of asyncio.run() at the top of your program. The rest of your async code stays the same. For older Python versions (before 3.11), there is an alternative installation pattern shown in the README that also takes just a few lines to add. Installing it is a single pip command. It requires Python 3.8 or newer. The README also documents how to build it from source if you need to, which involves cloning the repository, setting up a virtual environment, and running make. The project is maintained by MagicStack and is dual-licensed under MIT and Apache 2.0, so it can be used in both open source and commercial projects. Full documentation is hosted separately on ReadTheDocs.

Copy-paste prompts

Prompt 1
I have an asyncio FastAPI app. Show me exactly how to add uvloop so it uses the faster event loop with the minimal code change.
Prompt 2
Benchmark my asyncio HTTP server with and without uvloop using wrk, and explain what the throughput difference means in practice.
Prompt 3
I'm on Python 3.9. Show me the older uvloop installation pattern from the README that sets the event loop policy before asyncio.run().
Prompt 4
My uvloop-powered service handles thousands of WebSocket connections. Walk me through profiling which coroutines are the bottleneck.
Prompt 5
Show me how to build uvloop from source in a Docker container so I can use it in a custom Python base image.
Open on GitHub → Explain another repo

← magicstack on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.