Python: Requesting and parsing data from API

iOSTom
Python + Data Science + Web
3 min readOct 12, 2018

--

One of my favorite things to-do in my spare time is to look at data. I really enjoy asking questions and trying to provide an answer by analyzing data. In this article I will talk about how I request data from propublica, opensecrets and the steps I took to parse the response.

After reading this article you will be able to

  1. Use requests to get data
  2. Parse a get request response

Requests library

It makes performing get requests very easy. I installed requests with pip and made the library available to the project with import.

  1. Make a get request to Propublica that returns all senators

I created a function called all_senators(), that goes to propublica and requests data about all senators who are currently serving. I created a variable to hold the url and created a dictionary to hold my api key. To make a get request I passed the url and headers and received a response object.

--

--

iOSTom
Python + Data Science + Web

iOS Developer, Go, Java, C#, Blockchain enthusiast, Data junkie