Registry / type-stubs / google-auth-stubs

google-auth-stubs

JSON →
library0.3.0pypypi✓ verified 21d ago

google-auth-stubs provides type stubs for the `google-auth` library, enabling static type checking (e.g., with MyPy) for Google authentication code. It helps catch type-related errors at development time without affecting runtime behavior. The current version is 0.3.0, with releases occurring as needed to support new `google-auth` versions or add type elaborations.

pip install google-auth-stubs
INSTALL
IMPORT
SIG · GOOGLE-AUTH-STUBS
G
google-auth-stubs
type-stubspythonv0.3.0
Install
4.2s avg
Import
240ms
Disk
59MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.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.258s · 61.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.2s · import 0.222s · 59MB
59MB installed
● package 59MB
Code
Verified usage

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

Credentials
from google.auth.credentials import Credentials
default
import google.auth.default
Request
from google.auth.transport.requests import Request
service_account_credentials
from google.oauth2 import service_account

This quickstart demonstrates a basic `google-auth` flow. The `google-auth-stubs` library provides type hints for all components used here, enhancing static analysis when this code is run through a type checker like MyPy.

import google.auth from google.auth.transport.requests import Request # This code demonstrates typical google-auth usage, which google-auth-stubs provides types for. # In a real application, credentials would be obtained from environment variables, # a service account file, or other configuration. # For example, to use default credentials: try: credentials, project = google.auth.default() # If credentials are refreshable and expired, try to refresh them. if credentials and credentials.expired and credentials.refresh_token: credentials.refresh(Request()) print(f"Successfully obtained credentials for project: {project}") print(f"Credentials scope(s): {credentials.scopes}") except Exception as e: print(f"Failed to obtain Google Cloud credentials: {e}") print("Ensure 'google-auth' is installed and credentials are configured (e.g., GOOGLE_APPLICATION_CREDENTIALS).")
Debug
Known issues
gotchaThis library provides type stubs only. You must also install the actual `google-auth` library for your application to run at runtime. `google-auth-stubs` is a development-time dependency for type checking.
fix
Ensure `google-auth` is included in your project's runtime dependencies (`pip install google-auth`).
affects: All versions
gotchaType stubs may not perfectly align with every minor version of the `google-auth` library. Mismatched versions can lead to incorrect type checking results or false positives from your type checker.
fix
Try to keep `google-auth-stubs` and `google-auth` versions as close as possible. Check the `google-auth-stubs` changelog for specific `google-auth` versions it targets.
affects: All versions
gotchaThe library explicitly requires Python versions >=3.6.2 and <4.0.0. Using it with unsupported Python versions may lead to installation failures or unexpected behavior.
fix
Ensure your development environment uses a compatible Python version (e.g., Python 3.8, 3.9, 3.10, 3.11).
affects: All versions
Errors
Common errors & fixes
Skipping analyzing "google.oauth2": module is installed, but missing library stubs or py.typed marker.
MyPy, or another static type checker, cannot find the type stubs for the `google.oauth2` subpackage (part of `google-auth`), indicating that `google-auth-stubs` might not be installed, not in a location MyPy checks, or is an incompatible version.
fix
Ensure `google-auth-stubs` is installed in the same environment as `google-auth` using `pip install google-auth-stubs`. Also, verify your MyPy configuration includes the environment where `google-auth-stubs` is installed.
error: Missing type stubs for package 'google.auth'
MyPy is reporting that it cannot find type information (stubs) for the `google.auth` package, which means `google-auth-stubs` is either not installed, or MyPy is not configured to look in the correct location for the installed stubs.
fix
Install the type stubs using `pip install google-auth-stubs`. If already installed, ensure your MyPy configuration (`mypy.ini` or command-line arguments) correctly points to your project's environment where stubs are installed, or run `mypy --install-types` to automatically install missing stubs from `typeshed`.
AttributeError: 'Credentials' object has no attribute 'request'
This runtime error usually occurs when an attempt is made to use an operation on a `Credentials` object (often obtained from `google.oauth2.credentials`) that the specific `Credentials` instance does not support or that requires an associated transport object. While `google-auth-stubs` provides type hints, this error typically indicates a mismatch between how the `Credentials` object is being used and its actual capabilities at runtime, potentially due to an outdated `google-auth` version or incorrect object initialization.
fix
Ensure `google-auth` and related libraries like `google-auth-oauthlib` or `google-auth-httplib2` are up to date (`pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2`). Verify that the `Credentials` object is properly initialized and, if needed, wrapped with a transport (`google.auth.transport.requests.AuthorizedSession`) before making requests. Consult the `google-auth` documentation for the correct way to use specific `Credentials` types and their associated transport methods. While stubs can highlight type issues, this specific error often points to a runtime logic problem.
Upgrade
Version history
0.3.0latest on PyPI · released Aug 26, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
40 hits · last 30 days
node
36
OpenAI (training)
1
Resources
google-auth-stubs — pip install google-auth-stubs · libregistry