Top Banner
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
25

asyncio community, one year later

Aug 16, 2015

Download

Technology

Victor Stinner
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  1. 1. 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
  2. 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
  3. 3. Python 3.4.0: March 2014 Bare: almost no library Asyncio launch
  4. 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. 5. Most famous and successful library HTTP client and server HTTPS Client and server Websocket https://aiohttp.rtfd.org/ aiohttp
  6. 6. @asyncio.coroutine def fetch_page(url): req = yield from aiohttp.request('GET', url) assert req.status == 200 return (yield from req.read()) aiohttp client example
  7. 7. MySQL: aiomysql PostgreSQL: aiopg (based on psycopg2) SQL drivers
  8. 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
  9. 9. peewee: peewee-async SQLAlchemy: aiopg.sa ORM
  10. 10. memcached: aiomemcache redis: aioredis redis: asyncio-redis Key-value stores
  11. 11. @asyncio.coroutine def wait_each_command(): foo = yield from redis.get('foo') bar = yield from redis.incr('bar') return foo, bar aioredis example
  12. 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
  13. 13. CouchDB: aiocouchdb MongoDB: asyncio-mongodb NoSQL
  14. 14. DNS: aiodns (async resolver) IRC: bottom IRC: irc3 SSH: AsyncSSH XMPP (Jabber): slixmpp Clients
  15. 15. AMI: panoramisk (AMI and FastAGI) AMQP: aioamqp ElasticSearch: aioes Etcd: aioetcd Google Hangouts: hangups More clients
  16. 16. aiopyramid aiowsgi interest Muffin API hour Web frameworks nacho Pulsar rainfall Vase
  17. 17. aiohttp.web AutobahnPython websockets WebSocket-for-Python Websockets
  18. 18. FastAGI (Asterisk): panoramisk IRC: irc3.irc3d HTTP: aiohttp SSH: AsyncSSH Servers
  19. 19. @asyncio.coroutine def hello(request): return web.Response(body=b"Hello, world") app = web.Application() app.router.add_route('GET', '/', hello) aiohttp server
  20. 20. @asyncio.coroutine def stats(request): body = yield from get_stats() return web.Response(body=body) app.router.add_route('GET', '/stats', stats) aiohttp server
  21. 21. asynctest: for unittest pytest-asyncio: for pytest aiotest (test asyncio implementation) Unit tests
  22. 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. 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. 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?
  25. 25. 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]