Registry / type-stubs / google-api-python-client-stubs

google-api-python-client-stubs

JSON →
library1.40.0pypypi✓ verified 23d ago

This package provides type stubs for the `google-api-python-client` library, enabling type checking with tools like `mypy` and improving autocompletion in IDEs. The stubs are automatically generated based on Google's Discovery Documents. It is not officially affiliated with Google, and its releases can be infrequent.

pip install google-api-python-client-stubs
INSTALL
IMPORT
SIG · GOOGLE-API-PYTHON-
G
google-api-python-client-stubs
type-stubspythonv1.40.0
Install
5.7s avg
Import
1003ms
Disk
186MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.018s · 187.4MB
glibc
py 3.103.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()
Debug
Known issues
breakingType classes and `TypedDict`s provided by `google-api-python-client-stubs` are design-time artifacts and do not exist at runtime. Direct runtime imports or unquoted explicit annotations (in Python < 3.9 without `from __future__ import annotations`) will cause `NameError` or `ModuleNotFoundError`.
fix
To safely use explicit type annotations, import types within an `if typing.TYPE_CHECKING:` block or use `from __future__ import annotations` at the top of your file (for Python 3.7+ and 3.8, it makes annotations evaluated lazily).
affects: All versions
gotchaType inference for `googleapiclient.discovery.build` can be slow in `mypy` or IDEs due to the large number of overloads generated for various services and versions. This can impact autocompletion performance.
fix
Explicitly annotating the service object with the correct stub type (e.g., `sheets_service: SheetsResource = build(...)`) can significantly speed up type checking and autocompletion for that variable, but adhere to the runtime import caveats.
affects: All versions
gotchaStubs for non-API-specific parts of the `google-api-python-client` library (e.g., parts of `googleapiclient.http` or core utility functions) are less detailed compared to the API-specific service definitions, often defaulting to `Any`.
fix
Be aware that type checking coverage might be limited in these generic areas. Contributions to improve these stubs are generally welcome on the project's GitHub repository.
affects: All versions
gotchaThe `google-api-python-client-stubs` library is independently maintained and not officially affiliated with Google. Its release cycle can be infrequent.
fix
New features or API versions in the upstream `google-api-python-client` might not immediately have corresponding stubs. Users may need to open an issue on the stub library's GitHub repository to request an update.
affects: All versions
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.
fix
Install 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.
fix
Ensure `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.
fix
When 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.
fix
This 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.
Agent activity
30 hits · last 30 days
node
26
OpenAI (training)
2
Resources
google-api-python-client-stubs — pip install google-api-python-client-stubs · libregistry