uvloop

Fast implementation of asyncio event loop on top of libuv

MIT License 83 个版本 Python >=3.8.1
安装
pip install uvloop
poetry add uvloop
pipenv install uvloop
conda install uvloop
描述

.. image:: https://img.shields.io/github/actions/workflow/status/MagicStack/uvloop/tests.yml?branch=master :target: https://github.com/MagicStack/uvloop/actions/workflows/tests.yml?query=branch%3Amaster

.. image:: https://img.shields.io/pypi/v/uvloop.svg :target: https://pypi.python.org/pypi/uvloop

.. image:: https://pepy.tech/badge/uvloop :target: https://pepy.tech/project/uvloop :alt: PyPI - Downloads

uvloop is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is implemented in Cython and uses libuv under the hood.

The project documentation can be found here <http://uvloop.readthedocs.org/>. Please also check out the wiki <https://github.com/MagicStack/uvloop/wiki>.

Performance

uvloop makes asyncio 2-4x faster.

.. image:: https://raw.githubusercontent.com/MagicStack/uvloop/master/performance.png :target: http://magic.io/blog/uvloop-blazing-fast-python-networking/

The above chart shows the performance of an echo server with different message sizes. The sockets benchmark uses loop.sock_recv() and loop.sock_sendall() methods; the streams benchmark uses asyncio high-level streams, created by the asyncio.start_server() function; and the protocol benchmark uses loop.create_server() with a simple echo protocol. Read more about uvloop in a blog post <http://magic.io/blog/uvloop-blazing-fast-python-networking/>_ about it.

Installation

uvloop requires Python 3.8 or greater and is available on PyPI. Use pip to install it::

$ pip install uvloop

Note that it is highly recommended to upgrade pip before installing uvloop with::

$ pip install -U pip

Using uvloop

As of uvloop 0.18, the preferred way of using it is via the uvloop.run() helper function:

.. code:: python

import uvloop

async def main():
    # Main entry-point.
    ...

uvloop.run(main())

uvloop.run() works by simply configuring asyncio.run() to use uvloop, passing all of the arguments to it, such as debug, e.g. uvloop.run(main(), debug=True).

With Python 3.11 and earlier the following alternative snippet can be used:

.. code:: python

import asyncio
import sys

import uvloop

async def main():
    # Main entry-point.
    ...

if sys.version_info >= (3, 11):
    with asyncio.Runner(loop_factory=uvloop.new_event_loop) as runner:
        runner.run(main())
else:
    uvloop.install()
    asyncio.run(main())

Building From Source

To build uvloop, you'll need Python 3.8 or greater:

  1. Clone the repository:

    .. code::

    $ git clone --recursive git@github.com:MagicStack/uvloop.git $ cd uvloop

  2. Create a virtual environment and activate it:

    .. code::

    $ python3 -m venv uvloop-dev $ source uvloop-dev/bin/activate

  3. Install development dependencies:

    .. code::

    $ pip install -e .[dev]

  4. Build and run tests:

    .. code::

    $ make $ make test

License

uvloop is dual-licensed under MIT and Apache 2.0 licenses.

版本列表
0.22.1 2025-10-16
0.21.0 2024-10-14
0.21.0b1 2024-09-03
0.20.0 2024-08-15
0.19.0 2023-10-22
0.18.0 2023-10-13
0.17.0 2022-09-14
0.16.0 2021-08-10
0.15.3 2021-07-13
0.15.2 2021-02-19
0.15.1 2021-02-15
0.15.0 2021-02-10
0.14.0 2019-11-05
0.14.0rc2 2019-10-29
0.14.0rc1 2019-10-25
0.13.0 2019-08-14
0.13.0rc1 2019-04-25
0.12.2 2019-03-20
0.12.1 2019-02-12
0.12.0 2019-01-21
0.12.0rc1 2018-10-31
0.11.3 2018-10-31
0.11.2 2018-08-07
0.11.1 2018-08-02
0.11.0 2018-07-04
0.10.3 2018-08-07
0.10.2 2018-06-25
0.10.1 2018-06-01
0.10.0 2018-05-30
0.9.1 2017-11-29
0.9.0 2017-11-26
0.8.1 2017-09-12
0.8.0 2017-02-09
0.7.2 2017-01-05
0.7.1 2017-01-02
0.7.0 2016-12-24
0.6.8 2016-12-23
0.6.7 2016-11-28
0.6.6 2016-11-28
0.6.5 2016-11-10
0.6.1 2016-11-10
0.6.0 2016-11-06
0.5.5 2016-11-06
0.5.4 2016-10-05
0.5.3 2016-08-24
0.5.2 2016-08-11
0.5.1 2016-08-10
0.5.0 2016-07-19
0.4.34 2016-07-12
0.4.33 2016-07-05
0.4.32 2016-07-04
0.4.31 2016-06-28
0.4.30 2016-06-09
0.4.29 2016-05-29
0.4.28 2016-05-23
0.4.27 2016-05-23
0.4.26 2016-05-21
0.4.25 2016-05-19
0.4.24 2016-05-16
0.4.23 2016-05-14
0.4.22 2016-05-14
0.4.21 2016-05-13
0.4.20 2016-05-13
0.4.19 2016-05-11
0.4.18 2016-05-11
0.4.17 2016-05-11
0.4.16 2016-05-09
0.4.15 2016-05-09
0.4.14 2016-05-07
0.4.13 2016-05-05
0.4.12 2016-05-05
0.4.11 2016-05-04
0.4.10 2016-05-04
0.4.9 2016-04-28
0.4.8 2016-04-28
0.4.7 2016-04-19
0.4.6 2016-04-14
0.4.5 2016-04-14
0.4.4 2016-04-12
0.4.3 2016-04-12
0.4.2 2016-04-12
0.4.1 2016-04-12