Python guide

    Read Google Sheets as JSON in Python

    Use Python requests to send a public Google Sheet URL to SheetsDB. A successful response becomes a list of dictionaries when the first row contains headers.

    By Zainul Ariffin
    Result: With hasHeader set to true, each Sheet row is returned as a Python dictionary after calling response.json().

    Install requests

    Shell
    python -m pip install requests

    Store the API key outside the script

    Shell
    export SHEETSDB_API_KEY='your_api_key'
    export GOOGLE_SHEET_URL='https://docs.google.com/spreadsheets/d/.../edit'

    Fetch the rows

    Python
    import os
    import requests
    
    response = requests.post(
        "https://www.sheetsdb.io/api/v1/getsheet",
        headers={
            "Authorization": f"Bearer {os.environ['SHEETSDB_API_KEY']}",
            "Content-Type": "application/json",
        },
        json={
            "sheetRef": os.environ["GOOGLE_SHEET_URL"],
            "hasHeader": True,
        },
        timeout=20,
    )
    
    if response.ok:
        rows = response.json()
        for row in rows:
            print(row)
    else:
        error = response.json()
        print(response.status_code, error.get("code"), error.get("error"))

    Timeouts and retries

    The example sets a 20-second client timeout. SheetsDB stops waiting for Google after 15 seconds and returns GOOGLE_REQUEST_TIMEOUT. Retry a temporary 502 or 504 with a short delay. For 429 responses, wait for the Retry-After value.

    Data types

    Cell values can arrive as strings, numbers, booleans, empty strings, or null, and a missing trailing cell may be omitted. Validate each row before inserting it into a typed model or database.