Asyncio community, one year later - EuroPython, 2015, Bilbao

25
EuroPython 2015, Bilbao Victor Stinner [email protected] Distributed under CC BY-SA license: http://creativecommons.org/licenses/by-sa/3.0/ Asyncio community one year later

Transcript of Asyncio community, one year later - EuroPython, 2015, Bilbao

Page 1: Asyncio community, one year later - EuroPython, 2015, Bilbao

EuroPython 2015, Bilbao

Victor [email protected]

Distributed under CC BY-SA license: http://creativecommons.org/licenses/by-sa/3.0/

Asyncio communityone year later

Page 2: Asyncio community, one year later - EuroPython, 2015, Bilbao

Python core developer since 5 yearsSenior Software Engineer at Red HatPort OpenStack to Python 3Working remotely from South of France

Victor Stinner

Page 3: Asyncio community, one year later - EuroPython, 2015, Bilbao

Python 3.4.0: March 2014Bare: almost no library

Asyncio launch

Page 4: Asyncio community, one year later - EuroPython, 2015, Bilbao

python-tulip mailing list (Google Group)#asyncio IRC channel on Freenodehttps://github.com/python/asyncioPython bug tracker (bugs.python.org)More and more conferences!

Community

Page 5: Asyncio community, one year later - EuroPython, 2015, Bilbao

Most famous and successful libraryHTTP client and serverHTTPSClient and server Websockethttps://aiohttp.rtfd.org/

aiohttp

Page 6: Asyncio community, one year later - EuroPython, 2015, Bilbao

@asyncio.coroutinedef fetch_page(url): req = yield from aiohttp.request('GET', url) assert req.status == 200 return (yield from req.read())

aiohttp client example

Page 7: Asyncio community, one year later - EuroPython, 2015, Bilbao

MySQL: aiomysqlPostgreSQL: aiopg (based on psycopg2)

SQL drivers

Page 8: Asyncio community, one year later - EuroPython, 2015, Bilbao

dsn = 'dbname=aiopg host=127.0.0.1 user=…'

@asyncio.coroutinedef 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

Page 9: Asyncio community, one year later - EuroPython, 2015, Bilbao

peewee: peewee-asyncSQLAlchemy: aiopg.sa

ORM

Page 10: Asyncio community, one year later - EuroPython, 2015, Bilbao

memcached: aiomemcacheredis: aioredisredis: asyncio-redis

Key-value stores

Page 11: Asyncio community, one year later - EuroPython, 2015, Bilbao

@asyncio.coroutinedef wait_each_command(): foo = yield from redis.get('foo') bar = yield from redis.incr('bar') return foo, bar

aioredis example

Page 12: Asyncio community, one year later - EuroPython, 2015, Bilbao

@asyncio.coroutinedef pipelined(): get = redis.get('foo') incr = redis.incr('bar') foo, bar = yield from asyncio.gather(get, incr) return foo, bar

aioredis pipeline example

Page 13: Asyncio community, one year later - EuroPython, 2015, Bilbao

CouchDB: aiocouchdbMongoDB: asyncio-mongodb

NoSQL

Page 14: Asyncio community, one year later - EuroPython, 2015, Bilbao

DNS: aiodns (async resolver)IRC: bottomIRC: irc3SSH: AsyncSSHXMPP (Jabber): slixmpp

Clients

Page 15: Asyncio community, one year later - EuroPython, 2015, Bilbao

AMI: panoramisk (AMI and FastAGI)AMQP: aioamqpElasticSearch: aioesEtcd: aioetcdGoogle Hangouts: hangups

More clients

Page 16: Asyncio community, one year later - EuroPython, 2015, Bilbao

aiopyramidaiowsgiinterestMuffin

API hour

Web frameworks

nachoPulsarrainfallVase

Page 17: Asyncio community, one year later - EuroPython, 2015, Bilbao

aiohttp.webAutobahnPythonwebsocketsWebSocket-for-Python

Websockets

Page 18: Asyncio community, one year later - EuroPython, 2015, Bilbao

FastAGI (Asterisk): panoramiskIRC: irc3.irc3dHTTP: aiohttpSSH: AsyncSSH

Servers

Page 19: Asyncio community, one year later - EuroPython, 2015, Bilbao

@asyncio.coroutinedef hello(request): return web.Response(body=b"Hello, world")

app = web.Application()app.router.add_route('GET', '/', hello)

aiohttp server

Page 20: Asyncio community, one year later - EuroPython, 2015, Bilbao

@asyncio.coroutinedef stats(request): body = yield from get_stats() return web.Response(body=body)

app.router.add_route('GET', '/stats', stats)

aiohttp server

Page 21: Asyncio community, one year later - EuroPython, 2015, Bilbao

asynctest: for unittestpytest-asyncio: for pytest

aiotest (test asyncio implementation)

Unit tests

Page 22: Asyncio community, one year later - EuroPython, 2015, Bilbao

Trollius is the Python 2 port of asyncioWork on Python 2.6 – 3.5Use “yield From(...)”instead of “yield from ...”Only a few asyncio libraries are compatible with trolliusOnly use it if you cannot port your application to Python 3

Trollius

Page 23: Asyncio community, one year later - EuroPython, 2015, Bilbao

Ludovic Gasc ran benchmark on Flask, Django and API Hour (asyncio)API Hour is as fast or much fasterBest case: API-Hour handles 5x more requests per secondJSON serialization: 400k req/s API-Hour vs 70-79k for Django-FlaskDetails: http://blog.gmludo.eu/

Benchmarks

Page 24: Asyncio community, one year later - EuroPython, 2015, Bilbao

Need tutorials and more documentationPort more stdlib modules to asyncio: ftplib, poplib, imaplib, nntplib, smtplib, telnetlib, xmlrpclib, etc.Interoperability with Twisted

How can you help?

Page 25: Asyncio community, one year later - EuroPython, 2015, Bilbao

Questions?http://www.asyncio.org/

github.com/python/asyncio/wiki/ThirdParty

Distributed under CC BY-SA license: http://creativecommons.org/licenses/by-sa/3.0/

Contact :

[email protected]