Skip to content

gsheet_add_row

jaybgager edited this page Oct 12, 2026 · 2 revisions

Adds the data from a Python list as a row to a tab in a Google sheet using the gspread package. Each list item will fill a cell in the first empty row of the chosen Google sheet tab.

Note

Google-sheet-related functions require a security token to be set up prior to use. Read the Google Sheets Setup for a guide on how to do this.

Arguments:

  • sheet_key (string, mandatory)
    • the unique key for identifying the google sheet
    • can be found in the url of the sheet between /d/ and /edit?
  • tab_name (string, mandatory)
    • the name of the tab you want to update within the google sheet
    • "tab" is an informal term, officially these are called "worksheets" within Google's documentation
  • row_data (list, mandatory)
    • a list of values that you want to append as a row to the end of the current data in the sheet
    • be aware that large integers passed may sometimes be converted to scientific notation
    • it's recommended to pass all data to the spreadsheet as strings if possible to avoid this
  • oauth (boolean, optional, default=False)
    • by default this function assumes you want to use a google service account for authentication
    • setting this to True attempts to use an OAuth token instead

Returns:

  • adds the passed list to the first empty row of the specified tab of the chosen sheet

Example

The following example uses this Google sheet.

First, we start with a blank Google sheet.

gsheet_add_row_example_initial

Then you can run the following code to populate it with your list.

INPUT:

import tracertools as tt

# creates the list to be added as a row
row_info = [
    "segment",
    "3d_volume",
    "cable_length",
    "synapses",
]

tt.gsheet_add_row(
    sheet_key = "1KM0xY9-yLe5fwiQit8yrwcg7vbvPDlZMEUnxf1BeFns",
    tab_name = "final_state",
    row_data = row_info,
)

You should now have a filled in sheet:

gsheet_add_row_example_final

Clone this wiki locally