In [2]:
# I keep this as a cell in my title slide so I can rerun
# it easily if I make changes, but it's low enough it won't
# be visible in presentation mode.
%run talktools
Excited about the incredibly array of APIs but don't know how to use them? Although APIs serve many purposes, there are common approaches to consuming any APIs that you will learn in this workshop. We will survey the many types of available APIs and concentrate on a few important examples of APIs. In this workshop, we will use Python, a commonly used and powerful language for working with APIs. Even if you don't know Python, you'll still pick up any basic concepts that you can apply the next time you encounter another API to use.
Goal is to present an introduction on how to use APIs with a focus on using the Python programming language.
There are many APIs (over 11000 listed in API Directory of ProgrammableWeb) -- hence, it'd be impossible to cover how to consume all of them.
I have been on the faculty for the School of Information, UC Berkeley and I do software engineering for https://unglue.it. I'll be writing again for programmableweb.com very soon. I'm very much interested in open data, open source, and teaching people about these subjects -- as well as creating tools for creative thinking.
working through examples:
Look at the following URL in a web browser for comparison:
http://rpc.geocoder.us/service/csv?address=1600+Pennsylvania+Ave,+Washington+DC
See my writeup on Geocoding for more info.
In [3]:
url = "http://rpc.geocoder.us/service/csv?address=1600+Pennsylvania+Ave,+Washington+DC"
In [4]:
# let's break out the address explicitly
import urllib
url = "http://rpc.geocoder.us/service/csv?" + \
urllib.urlencode({
'address':'1600 Pennsylvania Ave, Washington DC'
})
url
Out[4]:
In [5]:
import requests
r = requests.get(url).content
r.split(",")
Out[5]: