Python Google Sheets API: Get Sheet Id by Sheet Name

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

SPREADSHEET_ID = ...
SHEET_NAME = ...

spreadsheet = service.spreadsheets().get(spreadsheetId=SPREADSHEET_ID).execute()
sheet_id = None
for _sheet in spreadsheet['sheets']:
    if _sheet['properties']['title'] == sheet_name:
        sheet_id = _sheet['properties']['sheetId']

print(f"{SHEET_NAME}={sheet_id}")

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

NOTE: Refer Android (Java/Kotlin) Google Sheets API: Get Sheet Name or Id.

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