Registry /
type-stubs / google-api-python-client-stubs
Install & Compatibility
Where this runs
tested against v1.40.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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 1.018s · 187.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 5.7s · import 0.988s · 188MB
186MB installed
● package 186MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
build
✓ from googleapiclient.discovery import build
SheetsResource
✓ from googleapiclient._apis.sheets.v4.resources import SheetsResource
✗ from googleapiclient.sheets.v4.resources import SheetsResource
Runtime type stubs are located under `googleapiclient._apis` and should only be imported within `if typing.TYPE_CHECKING:` blocks or referenced as string literals with `from __future__ import annotations`.
This quickstart demonstrates how to set up and use the `google-api-python-client-stubs` to provide type hints for a Google Sheets service client. It shows both the runtime `build` call and how to apply an explicit type annotation for improved development experience. Note the use of `if typing.TYPE_CHECKING:` to prevent runtime errors from stub-only imports.
import os
import typing
from googleapiclient.discovery import build
# Ensure annotations are processed correctly for type checkers
from __future__ import annotations
# Import the type stub for a specific service (e.g., Google Sheets v4)
# This import is solely for type checking and will not be evaluated at runtime.
if typing.TYPE_CHECKING:
from googleapiclient._apis.sheets.v4.resources import SheetsResource
# Use a placeholder for the API key for demonstration purposes
# In a real application, you would use proper authentication (e.g., OAuth2.0)
# or retrieve from environment variables.
API_KEY = os.environ.get("GOOGLE_API_KEY", "YOUR_API_KEY")
def main():
# Build the service client (runtime code for the actual API interaction)
service = build("sheets", "v4", developerKey=API_KEY)
# Example of type-hinting the service object using the imported stub type.
# This provides better IDE autocompletion and static type checking.
sheets_service: SheetsResource = build("sheets", "v4", developerKey=API_KEY)
print(f"Service built successfully. Runtime type: {type(service)}")
print("IDE and type checkers will now recognize 'sheets_service' as SheetsResource.")
# Example API call (commented out as it requires a valid API key/credentials)
# try:
# spreadsheet_id = 'YOUR_SPREADSHEET_ID'
# range_name = 'Sheet1!A1:B2'
# result = sheets_service.spreadsheets().values().get(
# spreadsheetId=spreadsheet_id,
# range=range_name
# ).execute()
# print(f"Retrieved data: {result}")
# except Exception as e:
# print(f"Error accessing Sheets API: {e}")
if __name__ == "__main__":
main()
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'googleapiclient'
The `google-api-python-client-stubs` package provides type hints for the `google-api-python-client` library, but it does not install the core library itself. This error occurs when the main `google-api-python-client` package is not installed in your environment.
fixInstall the `google-api-python-client` library: `pip install google-api-python-client`
mypy: Cannot find implementation or library stub for module
This error occurs when `mypy` cannot locate the type stubs for the `google-api-python-client` library, even if `google-api-python-client-stubs` is installed. This can be due to `mypy`'s import resolution path not including the location of the installed stubs, or an incorrect `MYPYPATH` configuration.
fixEnsure `google-api-python-client-stubs` is installed (`pip install google-api-python-client-stubs`). If the error persists, check your `mypy` configuration (e.g., `MYPYPATH` environment variable) to ensure it can find the installed packages. For projects, `mypy` typically works best when run from the project root.
NameError: name 'SheetsResource' is not defined
The types provided by `google-api-python-client-stubs` (like `SheetsResource`, `DriveResource`, `TypedDict`s for requests/responses) are *only* for static type checking and do not exist at runtime in the actual `google-api-python-client` library. Directly importing and using these types in your Python code without proper guards will lead to a `NameError` or similar runtime errors.
fixWhen using types from the stubs for explicit annotations, you must ensure they are only evaluated during type checking. Use `from __future__ import annotations` (for Python 3.7+) or import types within an `if typing.TYPE_CHECKING:` block, and surround annotations with quotes. For example:
```python
from __future__ import annotations # Or use quotes around type hints
import typing
if typing.TYPE_CHECKING:
from googleapiclient._apis.sheets.v4.resources import SheetsResource
def get_sheets_service() -> SheetsResource:
# ... build and return service
pass
``` reportMissingModuleSource error (Pyright/Pylance)
Pyright/Pylance may report `reportMissingModuleSource` when importing stub-only types (e.g., from `googleapiclient._apis`). This happens because the stub files (`.pyi`) exist, but there's no corresponding runtime `.py` file for those specific type-checking-only modules.
fixThis is generally safe to ignore as long as the imports are exclusively for type-checking. You can suppress this diagnostic in your `pyrightconfig.json` or `settings.json` (for Pylance) if it causes too much noise. For example, in `pyrightconfig.json`:
```json
{
"reportMissingModuleSource": "none"
}
``` Upgrade
Version history
1.40.0latest on PyPI · released Aug 22, 2026
Audit
Dependencies
google-api-python-clientrequiredProvides the runtime library for which these are stubs.
mypyoptionalA static type checker commonly used with these stubs.