Python Workshops for Beginners/Saturday October 25th lecture

From OpenHatch wiki
< Python Workshops for Beginners
Revision as of 23:27, 21 October 2014 by imported>Ehashman
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Welcome to the second Saturday lecture of the Python Workshops for Beginners! For about an hour and a half, we'll learn about "Application Programming Interfaces" (or APIs) so we can use them for some data science exercises in the afternoon.

Resources[edit]

Lecture Outline[edit]

  1. Introduction to APIs
    • definition of API: just an interface for programs
    • definition of web API
      • way to ask for data (almost always a URL)
      • way to get data back (almost always in a format called JSON)
      • every API is different, and documented
    • to use APIs to build a dataset we will need:
      • all our tools from last session: variables, etc
      • the ability to open urls on the web
      • the ability to create custom URLS
      • the ability to save to files
      • the ability to understand (i.e., parse) JSON data that APIs usually give us
  2. New programming concepts:
    • urllib2 and urlopen
    • interpolate variables into a string using % and %()s
    • open files and write to them
  3. placekitten.com
    • API that takes specially crafted URLs and gives appropriately sized picture of kittens
    • example of placekitten in browser
      • visit the API documentation
      • kittens of different sizes
      • kittens in greyscale or color
    • show how to use place
    • write a small program to grab arbitrary square from placekitten by asking for the size on standard in
  4. Other APIs
    • every API is different, so read the documentation!
    • for popular APIs, there are python modules that help you make requests and parse json!
    • rate limiting
    • authentication
    • text encoding issues