gitmyhub

uvloop

Cython ★ 12k updated 1mo ago

Ultra fast asyncio event loop.

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.

PythonCythonlibuvasynciosetup: easycomplexity 2/5

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.

Where it fits