Learning Python Network Programming

(Sean Pound) #1

APIs in Action


When we talk about APIs in relation to Python, we usually refer to the classes and
the functions that a module presents to us to interact with. In this chapter, we'll be
talking about something different, that is, web APIs.


A web API is a type of API that you interact with through the HTTP protocol.
Nowadays, many web services provide a set of HTTP calls, which are designed to
be used programmatically by clients, that is, they are meant to be used by machines
rather than by humans. Through these interfaces it's possible to automate interaction
with the services and to perform tasks such as extracting data, configuring the
service in some way, and uploading your own content into the service.


In this chapter, we'll look at:



  • Two popular data exchange formats used by web APIs: XML and JSON

  • How to interact with two major web APIs: Amazon S3 and Twitter

  • How to pull data from HTML pages when an API is not available

  • How to make life easier for the webmasters that provide these APIs
    and websites


There are hundreds of services that offer web APIs. A quite comprehensive and ever-
growing list of these services can be found at http://www.programmableweb.com.


We're going to start by introducing how XML is used in Python, and then we will
explain an XML-based API called the Amazon S3 API.

Free download pdf