A Python client library for Google's discovery-based APIs, currently at version 2.193.0, with weekly releases. Note: This library is in maintenance mode; for new development, consider using Cloud Client Libraries for Python.
pip install google-api-python-clientVerified import paths — ran on the pinned version, not inferred.
Quickstart example to list files from Google Drive using the API client.
Use Cloud Client Libraries for Python for new development.
Use 'from googleapiclient.discovery import build' for correct import.
Use different quote types for the f-string and its contents (e.g., f"Your item is {item['name']}" or f'{item["name"]}') or escape the inner quotes (e.g., f'{item[\'name\']})'.Ensure Application Default Credentials are set up in your environment by following the instructions at https://cloud.google.com/docs/authentication/external/set-up-adc. This often involves setting the GOOGLE_APPLICATION_CREDENTIALS environment variable or authenticating with `gcloud auth application-default login`.
Ensure the `google-api-python-client` package is installed: `pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib`
Go to the Google Cloud Console (console.cloud.google.com), navigate to 'APIs & Services' -> 'Library', search for the API you need (e.g., 'Gmail API', 'Google Sheets API'), and click 'Enable'. Verify that you are using the correct project ID in your code and in the console.
The user needs to re-authorize your application. Delete any stored `token.json` or `.pickle` files, which will force a new authorization flow to obtain a fresh refresh token. Ensure your application's OAuth consent screen is configured for production if applicable, as testing applications have limited refresh token lifetimes.
Check the quotas for the relevant API in the Google Cloud Console under 'APIs & Services' -> 'Quotas'. You may need to request a quota increase if your usage demands it, or implement exponential backoff and retry logic in your application to handle temporary rate limits gracefully.