The asyncio project was officially launched with the release of Python 3.4 in March 2014. The project was public before that under the name “tulip”. asyncio is just a core network library, it requires third party library to be usable for common protocols. One year later, asyncio has a strong community writing libraries on top of it.
The most advanced library is aiohttp which includes a complete HTTP client but also a HTTP server. There are also libraries to access asynchronously the file system, resolve names with DNS, have variables local to tasks, read-write locks, etc. There are clients for AMQP, Asterisk, ElasticSearch, IRC, XMPP (Jabber), etc. (and even an IRC server!). There are asynchronous drivers for all common databases, and even for some ORMs. As expected, there are tons of new web frameworks based on asyncio. It’s also possible to plug asyncio into Gtk, Qt, gevent, eventlet, gunicorn, tornado, etc.
I will also discuss use cases of asyncio in production and benchmarks. Spoiler: asyncio is not slow.
The asyncio library also evolved to become more usable: it has a better documentation, is easier to debug and has a few new functions. There is also a port to Python 2: trollius.
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
asyncio community, one year later
1. EuroPython 2015, Bilbao
Victor Stinner
vstinner@redhat.com
Distributed under CC BY-SA license: http://creativecommons.org/licenses/by-sa/3.0/
Asyncio community
one year later
2. Python core developer since 5 years
Senior Software Engineer at Red Hat
Port OpenStack to Python 3
Working remotely from South of
France
Victor Stinner
4. python-tulip mailing list (Google Group)
#asyncio IRC channel on Freenode
https://github.com/python/asyncio
Python bug tracker (bugs.python.org)
More and more conferences!
Community
5. Most famous and successful library
HTTP client and server
HTTPS
Client and server Websocket
https://aiohttp.rtfd.org/
aiohttp
8. dsn = 'dbname=aiopg host=127.0.0.1 user=…'
@asyncio.coroutine
def go():
pool = yield from aiopg.create_pool(dsn)
with (yield from pool.cursor()) as cur:
yield from cur.execute("SELECT 1")
row = yield from cur.fetchone()
assert row == (1,)
aiopg example
12. @asyncio.coroutine
def pipelined():
get = redis.get('foo')
incr = redis.incr('bar')
foo, bar = yield from asyncio.gather(get,
incr)
return foo, bar
aioredis pipeline example
22. Trollius is the Python 2 port of asyncio
Work on Python 2.6 – 3.5
Use “yield From(...)”
instead of “yield from ...”
Only a few asyncio libraries are
compatible with trollius
Only use it if you cannot port your
application to Python 3
Trollius
23. Ludovic Gasc ran benchmark on Flask,
Django and API Hour (asyncio)
API Hour is as fast or much faster
Best case: API-Hour handles 5x more
requests per second
JSON serialization: 400k req/s API-
Hour vs 70-79k for Django-Flask
Details: http://blog.gmludo.eu/
Benchmarks
24. Need tutorials and more
documentation
Port more stdlib modules to asyncio:
ftplib, poplib, imaplib, nntplib, smtplib,
telnetlib, xmlrpclib, etc.
Interoperability with Twisted
How can you help?