Last active
July 27, 2018 06:26
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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