Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (34 sloc) 1.61 KB
import requests
# Hit a rest API endpoint
rest_endpoint = 'https://myservice/endpoint'
start_date = '2017-01-01'
end_date = '2019-12-31'
api_key = 'myAPIkey'
api_params = {'start_date' : start_date, 'end_date' : end_date, 'api_key': api_key}
response = requests.get(url=rest_endpoint, params=api_params)
# Some alternative possibilities depending on what your API needs (
# api_headers = { 'api_token' : api_token}
# response = requests.get(url=rest_endpoint, params=api_params, headers=api_headers)
# This could be with a payload if the API needs POST methods rather than GET
# response =, data=api_params)
# Check for a valid response, if not raise an Exception
if response.status_code >= 400:
# Grab the JSON from the response (if your API is returning plain-text or XML, use response.text)
rest_json = response.json()
# response_text = response.text
for first_level in rest_json:
data_in_first_level = rest_json[first_level]
# Get all the keys listed out
# In this example, there are many keys to pick from, but the 'data' key
# returns a list of lists, each representing a one-dimensional row of data
for second_level in data_in_first_level['data']:
for col in second_level:
print(col, type(col))
# Present any challenges with the structure -> SQL
# Present a SQL statement from table creation
# Allow for change of name and data type
# Present final table create SQL statement
You can’t perform that action at this time.