Skip to content

Instantly share code, notes, and snippets.

@petehartnett
Last active November 17, 2022 23:39
Show Gist options
  • Save petehartnett/c65b9df479ddb2fd773c87f450394cc7 to your computer and use it in GitHub Desktop.
Save petehartnett/c65b9df479ddb2fd773c87f450394cc7 to your computer and use it in GitHub Desktop.
download a tulip table to CSV
from pprint import pprint
import tulip_api,csv
TABLE_ID = 'PDfAmYGTgCzXJWojk'
CREDENTIALS = 'YXBpa2V5LjJfdXh6W.....5maTZPX1I3dFhIaUhuVi1qV1B1QXpWdlI0YmVuNmlXag=='
CSV_FILE = 'mycsvfile.csv'
api = tulip_api.TulipAPI('petehartnett.tulip.co',auth=CREDENTIALS)
wi_table = tulip_api.TulipTable(api,TABLE_ID)
records = wi_table.get_records(limit=1)
cnt = 0
with open(CSV_FILE, 'w') as f: # You will need 'wb' mode in Python 2.x
w = csv.DictWriter(f, records[0].keys())
w.writeheader()
for row in wi_table.stream_records():
cnt +=1
if cnt%1000 == 0:
print("----Saved 1000 rows----")
elif cnt%100 == 0:
print("Saved 100 records")
w.writerow(row)
community-tulip-api
pprint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment