Skip to content

Instantly share code, notes, and snippets.

@Jwpe
Last active August 29, 2015 13:59
Show Gist options
  • Save Jwpe/10686662 to your computer and use it in GitHub Desktop.
Save Jwpe/10686662 to your computer and use it in GitHub Desktop.
Contact an API using requests!
# Here we import the 'requests' library. This allows us to visit URLs
# straight from Python. Note that this must be installed using pip,
# as described in the previous post
import requests
# We define a variable which represents the URL we want to get data from
api_url = 'http://api.crunchbase.com/v/1/company/trackmaven.js'
# Next we make a dictionary of parameters that are needed to contact the
# API - in this case, all we need is the key that tells the API we are
# a registered user. Replace <my_api_key> with our key.
parameters = {
'api_key': '<my_api_key>'
}
# This is the big one - using requests, we get data from the API by
# visiting 'api_url' and sending it the required parameters. Once
# the request is made, the 'response' object will hold all of the data
# we get back from
response = requests.get(api_url, params=parameters)
# We print out a dictionary of the JSON data that we got back from the
# API.
print response.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment