Note that before you can use datasheets you will need to set up your access keys as described in Getting OAuth Credentials.

Workbook Interactions

See all workbooks that exist

client = datasheets.Client()

# Optionally limit to a specific folder
client.fetch_workbooks_info(folder='Finance Reports')

This produces a pandas.DataFrame:


See all folders that exist


# Optionally limit to only folders you own

Get a workbook

workbook = client.fetch_workbook('Marketing Projections')

Create a workbook

client.create_workbook('Q2 Roadmap')

Delete a workbook

client.delete_workbook('Q2 Roadmap')

Get a workbook’s URL


Tab Interactions

See all tabs within a workbook

workbook = client.fetch_workbook('Marketing Projections')

This produces a pandas.DataFrame:


Get a tab

workbook.fetch_tab('Radio Spend')

Create a tab

workbook.create_tab('Podcast Performance')

Delete a tab

workbook.delete_tab('Podcast Performance')

Sharing and Unsharing

See who is shared on a workbook


This produces a pandas.DataFrame:


Share or unshare a workbook

workbook.share(email='', role='writer', notify=True,
               message="Here's the 2020 revenue projections you'd asked for")


Data Interactions

Get all data in a tab

tab = workbook.fetch_tab('Radio Spend')
df = tab.fetch_data()

# Optionally return a dict of rows, where the keys are the values of the first row of cells
data = tab.fetch_data(fmt='dict')

# Or return a list of headers (the values of the first row) and a list of rows
data = tab.fetch_data(fmt='list')

Add data to a tab

# Clear all data in a tab and replace it with a new data set

# Add more data to a tab

# For either command, optionally skip uploading the index for the DataFrame
tab.insert_data(df, index=False)

In addition, by setting autoformat=True within the insert_data or append_data methods the data set will be formatted within the tab as shown below:


The dimensions of the tab match the data set, the headers are formatted nicely, all cells are left-aligned, and column widths are auto-scaled to fit their contents.

Remove all data from a tab


Tab Formatting Interactions

# Add rows

# Add columns

# Change horizontal and vertical alignment of all cells in tab
tab.align_cells(horizontal='LEFT', vertical='MIDDLE')

# Alter the number of rows or columns in a tab; if new dimensions are smaller
# than current values the tab will be trimmed down to that size
tab.alter_dimensions(nrows=25, ncols=10)

# Shortcut to color headers dark gray, set all cells to use Proxima Nova size 10, left-align
# and middle-align all cells, resize columns to fit their data, and eliminate empty columns
# and rows from tab

# Resize widths of all columns in a tab to fit their data

# Change font and font size for all cells in a tab
tab.format_font(font='Proxima Nova', size=10)

# Set header rows in a tab to be dark gray with off-white text, font Proxima Nova size 10,
# left-aligned and middle-aligned, and rows will be made "frozen" so that when the user
# scrolls these rows stay visible

In addition, anything not explicitly supported by the datasheets library as a stand-alone method can be accomplished using the Workbook.batch_update method and referencing Google Sheets’ spreadsheets.batchUpdate method. More details and an example exist within the docstring for datasheets.Workbook.batch_update().