Python Google Sheets API: Append New Row

July 2, 2019
credentials = ...
service = build('sheets', 'v4', credentials=credentials)
sheet = service.spreadsheets()

SPREADSHEET_ID = ...
SHEET_NAME = ...

# append new row on empty row from Row 2 onwards
range_notation = f"'{SHEET_NAME}'!A2"
body = {
    'values': [
        ['New Col 01', 'New Col 02', 'New Col 03']
    ]
}

result = sheet.values().append(spreadsheetId=SPREADSHEET_ID,
                               range=range_notation,
                               body=body,
                               valueInputOption="RAW",
                               insertDataOption="INSERT_ROWS").execute()
print(f"newRows={result['updates']['updatedRows']}")

NOTE: Refer Setup and Access Google Sheets API With Python.

NOTE: Refer Android (Java/Kotlin) Google Sheets API: Append New Row

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.