Hi ,

Ok, so to connect to use the smartsheet API within a python recipe or notebook you need:

Install the smartsheet python sdk (smartsheet-python-sdk)
An access token (more information here)
Now you should establish a connection by creating a client instance:

 

 

import smartsheet # You need a Token to authenticate with smartsheet. # In this case the token was stored as project custom variable. # You should replace it with your token string TOKEN = dataiku.get_custom_variables()['SMARTSHEET_TOKEN'] smartsheet_client = smartsheet.Smartsheet(TOKEN) smartsheet_client.errors_as_exceptions(True)

 


I would suggest now to follow the tutorials at the api documentation, but l'll add an example here.

Let's say you want to parse a sheet into a pandas dataframe. First you need the id (as string or integer) of the sheet of interest. You can get that from the url on the online smartsheet webapp, or list the sheets with their names and ids like this:

 

sheets = smartsheet_client.Sheets.list_sheets(include_all=True) for s in sheets.data: print(f"The sheet \"{s.name}\" has id {s.id}")


Once you have the id, you can create a function to automatize the parse process:

 

import pandas as pd # if you had not imported it before def simple_sheet_to_dataframe(sheet): col_names = [col.title for col in sheet.columns] rows = [] for row in sheet.rows: cells = [] for cell in row.cells: cells.append(cell.value) rows.append(cells) data_frame = pd.DataFrame(rows, columns=col_names) return data_frame


Now let's connect to the sheet and parse it into a dataframe:

sheet = smartsheet_client.Sheets.get_sheet(sheet_id) df = simple_sheet_to_dataframe(sheet) df.head() # explore the header


Hopefully this will help you to start. In the documentation you will find examples on how to add new sheets from excel or csv files, update sheets or delete them.

Cheers!