uvloop: Blazing fast Python networking — magicstack

TL;DR

asyncio is an asynchronous I/O framework shipping with the Python Standard Library. In this blog post, we introduce uvloop: a full, drop-in replacement for the asyncio event loop. uvloop is written in Cython and built on top of libuv.

uvloop makes asyncio fast. In fact, it is at least 2x faster than nodejs, gevent, as well as any other Python asynchronous framework. The performance of uvloop-based asyncio is close to that of Go programs.

asyncio & uvloop

The asyncio module, introduced by PEP 3156, is a collection of network transports, protocols, and streams abstractions, with a pluggable event loop. The event loop is the heart of asyncio. It provides APIs for:

  • scheduling calls,
  • transmitting data over the network,
  • performing DNS queries,
  • handling OS signals,
  • convenient abstractions to create servers and connections,
  • working with subprocesses asynchronously.

As of this moment, uvloop is only available on *nix platforms and Python 3.5.

uvloop is a drop-in replacement of the built-in asyncio event loop. You can install uvloop with pip:

$ pip install uvloop

Using uvloop in your asyncio code is as easy as:

import asyncio
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

The above snippet makes any asyncio.get_event_loop() call return an instance of uvloop.

Source: uvloop: Blazing fast Python networking — magicstack

 

Raony Guimaraes