Skip to main content
Read a Google Sheet with GoogleSheetsTools after configuring service-account or OAuth credentials.
Fresh setups must enable the Google Sheets API and configure Google credentials. The source’s OAuth redirect path is stale: InstalledAppFlow.run_local_server(port=8080) uses http://localhost:8080/, not http://localhost:8080/flowName=GeneralOAuthFlow. See the Google Sheets Python quickstart.
googlesheets_tools.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

4

Configure Google Sheets authentication

Enable the Google Sheets API. Then choose one credential flow: set GOOGLE_SERVICE_ACCOUNT_FILE to a service-account JSON key and share the target sheet with that account’s email; or create an OAuth desktop client, save its JSON as credentials.json beside the script, and authorize in the browser. With oauth_port=8080, use http://localhost:8080/ as the local redirect URI. If your OAuth client requires registered redirect URIs, register that exact URL.
5

Run the example

Save the code above as googlesheets_tools.py, then run:
Full source: cookbook/91_tools/googlesheets_tools.py