Registry / gcp / google-api-python-client

google-api-python-client

JSON →
library2.199.0pypypi✓ verified 24d ago

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
INSTALL
IMPORT
SIG · GOOGLE-API-PYTHON-
G
google-api-python-client
gcppythonv2.199.0
Install
5.8s avg
Import
961ms
Disk
150MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.199.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.994s · 150.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.8s · import 0.928s · 152MB
150MB installed
● package 150MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

build
from googleapiclient.discovery import build
Ensure correct import path to access the 'build' function for creating service objects.

Quickstart example to list files from Google Drive using the API client.

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']})')
Debug
Known issues
deprecatedThe 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.
affects: all
gotchaEnsure that the 'build' function is imported from 'googleapiclient.discovery' to avoid ImportError.
fix
Use 'from googleapiclient.discovery import build' for correct import.
affects: all
gotchaF-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\']})'.
affects: python:3.6+
breakingEncountered 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`.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'googleapiclient'
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`
HttpError 403 when requesting ... returned "API has not been used in project ... before or it is disabled."
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.
google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.', ...)
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.
HttpError 403 ... Quota exceeded for quota metric 'Requests' ...
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.
Upgrade
Version history
2.199.0latest on PyPI · released Aug 20, 2026
Audit
Dependencies
httplib2requiredHTTP client for Python, required for making API requests.
uritemplaterequiredLibrary for parsing and expanding URI templates, used in API requests.
Agent activity
59 hits · last 30 days
node
50
Meta
2
OpenAI (training)
1
Resources
google-api-python-client — pip install google-api-python-client · libregistry