YAY-PIs: Working with REST APIs in Python

Speakers: Shea Craig

Level: Intermediate, Lecture

Excerpt: Most network services have REST APIs that enable the intrepid to craft custom solutions to problems not solvable from that service’s console or web app. This talk will begin with making basic requests from the interpreter, using Sal as an example service. Next, we’ll make use of existing python API frameworks for Casper, Spotify, and Strava. Finally, we will discuss the design and implementation of wrappers for services which don’t already have one established, as well as adding a REST API to your existing services.

Description: Nearly every web service these days has an API for accessing data. These APIs become interesting whenever we think, “I wish this product could do…”. While we are limited to the endpoints made available by the service, creative use of this data can provide solutions to many problems that could not be solved through the product’s official console or app.

Python is a beautiful, expressive language, and we will use it for all of our API wrangling endeavors in this talk. First, we will go through the steps for accessing data just in the python interpreter, using both urllib and Requests. We will talk about working with JSON and XML, how and when to convert between bytes and unicode strings, and the eccentricities of python 2 vs. 3. We will also cover basic authentication.

Next, we will move to a higher level of abstraction and make use of some pre-made wrappers for popular REST APIs. We’ll look at OAUTH authentication, and how these tools can drastically improve your code quality and solution development speed.

The final section will involve writing your own wrappers and implementing RESTful services. We will look at how to create a REST API for an existing service you may have within your organization, going over an example Munki manifest manipulation service and an inventory system. Then we will talk about some of the python idioms and introspection features that can allow you to quickly wrap APIs that do not have a published framework already, as well as generic API wrappers like Tortilla and Hammock

Examples for this talk will come from Casper / Python-jss, Spotify / Spotipy, Strava / Stravalib, Munki, and Sal.

About the speaker

Shea Craig (Twitter: @shea_craig) – IT Systems Engineer – SAS

High Cleric of Vim, Destroyer of Burritos, Scourge of Coffee Beans.

This entry was posted in MacAdmins 2017 Sessions. Bookmark the permalink.