Skip to content

Instantly share code, notes, and snippets.

@fx86
Last active July 27, 2018 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fx86/c0809f5407fb9ba25909de0e02635819 to your computer and use it in GitHub Desktop.
Save fx86/c0809f5407fb9ba25909de0e02635819 to your computer and use it in GitHub Desktop.
Takes a Redash query ID and returns cached-data in a Pandas dataframe
# save your redash API key in a text file as below
api_key = open('api_key.config', 'r').readlines()[0]
def api_to_df(query_id, api_key=api_key):
'''
Takes a Redash query ID and returns cached-results
in a Pandas dataframe
'''
headers = {'Authorization': 'Key {}'.format(api_key)}
path = 'https://<redash-url>/api/queries/{:d}/results.csv'
path = path.format(query_id)
print("getting ", path)
txt = requests.get(path, headers=headers).text
return pd.read_csv(io.StringIO(txt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment