Friday 11 a.m.–11:40 a.m.

await kittens()

Lee Symes

Audience level:
Intermediate

Description

This talk will work through getting pictures(of kittens and other cute things) off Flickr using asyncio in Python 3.5. Showing how to build up from synchronous code to asynchronous code and how to make use of Python 3.5's new language features like async for and async with.

Abstract

This talk will work through getting pictures(of kittens and other cute things) off Flickr using asyncio in Python 3.5. Showing how to build up from synchronous code to asynchronous code and how to make use of Python 3.5's new language features like async for and async with.

This talk will focus on the implementation in Python 3.5(and up), however most of its content will carry back to Python 3.3.

Proposed Talk Outline:

  1. Getting kittens from Flickr using requests. Present a simple python script for downloading images as a baseline to improve on.
  2. Switching out requests for aiohttp, an HTTP request library for asyncio. Nothing running in parallel, but start using the async/await constructs.
  3. Making it faster, by running each kitten request in parallel. Now start using the parallel nature of asyncio to make the pictures download faster.
  4. Building more complicated workflows by downloading images from multiple search terms at once. Show how to take the code above and run it in parallel to download results of multiple search terms at once.
  5. Showing how the new async constructs in Python 3.5, can make code easy to read and understand. Take the search result code to the next level by using async for to automatically handle pagination whilst keeping the code simple, readable and pythonic.