# Using APIs with Python Requests Module

DevFeed: [Using APIs with Python Requests Module](<https://devfeed.tech/articles/using-apis-with-python-requests-module-19992.md>)

Original publisher: [Read original article](<http://engineering.hackerearth.com/2014/08/21/python-requests-module/>)

Published: 2014-08-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [HackerEarth](<https://devfeed.tech/sources/hackerearth.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [API](<https://devfeed.tech/topics/api.md>), [HTTP](<https://devfeed.tech/topics/http.md>), [JSON](<https://devfeed.tech/topics/json.md>), [GitHub](<https://devfeed.tech/topics/github.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [api-documentation](<https://devfeed.tech/tags/api-documentation.md>), [apis](<https://devfeed.tech/tags/apis.md>), [docs](<https://devfeed.tech/tags/docs.md>), [github](<https://devfeed.tech/tags/github.md>), [http](<https://devfeed.tech/tags/http.md>), [json](<https://devfeed.tech/tags/json.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

A tutorial on using the Python Requests module to communicate with APIs over HTTP, with examples covering installation, GET and POST requests, response handling, JSON decoding, URL parameters, and GitHub pagination.

## Source excerpt

One of the most liked feature of the newly launched HackerEarth profile is the accounts connections through which you can boast about your coding activity in various platforms. Github and StackOverflow provide their API to pull out various kinds of data. The API documentation of Github and StackOverflow can be found here. Github : https://developer.github.com/v3/ StackOverflow : http://api.stackexchange.com/docs But what do we use to communicate with these APIs? Working with HTTP is a painful task. Python includes a module called urllib2 but working with it can become cumbersome. Requests was written by Kenneth Reitz which simplies the common use cases and the tool for HackerEarth to do all the HTTP operations. Here is a code by @kenneth himself distinguishing urllib2 and requests So, this above code clearly distinguishes why we went for the requests module. ###Installation Installing Requests via pip is fairly simple, just run this in your terminal. $ pip install requests ###Making your first Request First of all, you need to import requests >>> import requests Now let's make a GET requests to get Github's public timeline >>> r = requests.get('https://github.com/timeline.json') Now, we have Response object called r using which we can get all the information. Requests' simple API means that all forms of HTTP request are as obvious. For example, this is how you make an HTTP POST request: >>> r = requests.post("http://httpbin.org/post") Similarly the other HTTP request types: PUT, DELETE, HEAD and OPTIONS? >>> r = requests.put("http://httpbin.org/put") >>> r = requests.delete("http://httpbin.org/delete") >>> r = requests.head("http://httpbin.org/get") >>> r = requests.options("http://httpbin.org/get") Now, let's consider the GitHub timeline again: >>> import requests >>> r = requests.get('https://github.com/timeline.json') >>> r.text u'[{"created_at":"2014-06-08T20:50:27-07:00","payload":{"sha... Requests will automatically decode content from the server. The text enc