Read data from Quip Spreadsheet with Python

1.4k views Asked by At

I need to make a tool with Python which needs to read data from a given Quip. I have read the Quip Api documentation but I can't find anything code related.

Does anyone have a source of inspiration for this implementation?

I tried 2 different implementation from various sources but they are not working:

1.

import quip
import quipclient as quipclient



id = 'completed with id'
thread = 'TestSpreadsheet'
base_url = 'completed with base_url'

ACCES_TOKEN = "completed with the token"
client = quip.QuipClient(access_token=ACCES_TOKEN, base_url = base_url)
with open("template.html", "rt") as f:
    template = f.read()
jso = client.new_document(template, title="My Spreadsheet", type="spreadsheet")
thread_id = jso['thread']["id"] --> not sure where do I get that from


user = client.get_authenticated_user()
print(f'User: {user}')


client.update_spreadsheet_headers((thread_id, 'Name', 'Email'))
client.get_thread(id)
spreadsheet = client.get_first_spreadsheet(thread_id)
headers = client.get_spreadsheet_header_items(spreadsheet)
print(headers)
import quip
import pandas as pd
import numpy as np
import html5lib

token = 'completed with token'
base_url = 'completed with base url'
thread_id = not sure where do I get that from
client = quip.QuipClient(token, base_url = base_url)
rawdictionary = client.get_thread(thread_id)

dfs=pd.read_html(rawdictionary['html'])
raw_df = dfs[0]


1

There are 1 answers

0
Anupam Dewan On

In the latest version, Quip has put the thread ID in the url as well so for example: https://<your enterprise quip host>/<thread_id>/<your spreadsheet name>

So for exporting a spreadsheet to lets say a dataframe following would be helper code

import quipclient
import pandas as pd
import lxml

ACCESS_TOKEN = "XXXXX"
quip = quipclient.QuipClient(access_token=ACCESS_TOKEN, base_url='https://<your-quip-url>.com')
user = quip.get_authenticated_user()
spread_sheet = quip.get_thread(id = '<thread id from the url>')

spread_sheet_html_part = spread_sheet['html'] 
df = pd.read_html(spread_sheet_html_part)
main_table = df[0]
main_table.columns = main_table.iloc[0]
main_table = main_table[1:]
main_table.to_csv("final_result.csv",index=False)