Type Stubs for Google Auth

0.3.0 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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).")

view raw JSON →