Google API Client Library for Python
raw JSON → 2.193.0 verified Tue May 12 auth: no python install: verified quickstart: stale maintenance
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-client Common errors
error ModuleNotFoundError: No module named 'googleapiclient' ↓
cause The `googleapiclient` library or its dependencies are not installed, or the Python environment where the code is run does not have access to the installed packages.
fix
Ensure the
google-api-python-client package is installed: pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib error HttpError 403 when requesting ... returned "API has not been used in project ... before or it is disabled." ↓
cause The specific Google API you are trying to access has not been enabled for your Google Cloud Project, or there is a mismatch in the project ID being used.
fix
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.
error google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.', ...) ↓
cause The OAuth 2.0 refresh token used to obtain new access tokens has expired or been revoked. This can happen if the user explicitly revoked access, the token exceeded its lifetime (e.g., for testing apps), or the user changed their password.
fix
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. error HttpError 403 ... Quota exceeded for quota metric 'Requests' ... ↓
cause Your Google Cloud Project or user account has exceeded the allowed API request limits (quotas) for the specific Google API being called.
fix
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.
Warnings
deprecated The google-api-python-client library is in maintenance mode and will not add new features. For new development, consider using Cloud Client Libraries for Python. ↓
fix Use Cloud Client Libraries for Python for new development.
gotcha Ensure that the 'build' function is imported from 'googleapiclient.discovery' to avoid ImportError. ↓
fix Use 'from googleapiclient.discovery import build' for correct import.
gotcha F-strings containing nested quotes (e.g., for dictionary keys) must use different quote types for the f-string delimiter and the inner quotes to avoid a SyntaxError. ↓
fix 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\']})'.
breaking Encountered DefaultCredentialsError when accessing Google APIs. This typically means that Application Default Credentials (ADC) are not configured. The application failed to find credentials. ↓
fix 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`.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.82s 141.5M
3.10 slim (glibc) - - 0.60s 142M
3.11 alpine (musl) - - 1.51s 145.6M
3.11 slim (glibc) - - 0.97s 146M
3.12 alpine (musl) - - 1.30s 137.1M
3.12 slim (glibc) - - 1.31s 138M
3.13 alpine (musl) - - 1.32s 136.7M
3.13 slim (glibc) - - 1.33s 137M
3.9 alpine (musl) - - 0.71s 141.5M
3.9 slim (glibc) - - 0.66s 142M
Imports
- build
from googleapiclient.discovery import build
Quickstart stale last tested: 2026-04-23
import os
from googleapiclient.discovery import build
# Set up the API client
service = build('drive', 'v3', developerKey=os.environ.get('API_KEY'))
# Call the API
results = service.files().list(pageSize=10, fields='files(id, name)').execute()
items = results.get('files', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print(f'{item['name']} ({item['id']})')