{"id":4552,"library":"google-auth-stubs","title":"Type Stubs for Google Auth","description":"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.","status":"active","version":"0.3.0","language":"en","source_language":"en","source_url":"https://github.com/henribru/google-auth-stubs","tags":["google","auth","type-stubs","typing","mypy"],"install":[{"cmd":"pip install google-auth-stubs","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Credentials","correct":"from google.auth.credentials import Credentials"},{"symbol":"default","correct":"import google.auth.default"},{"symbol":"Request","correct":"from google.auth.transport.requests import Request"},{"symbol":"service_account_credentials","correct":"from google.oauth2 import service_account"}],"quickstart":{"code":"import google.auth\nfrom google.auth.transport.requests import Request\n\n# This code demonstrates typical google-auth usage, which google-auth-stubs provides types for.\n# In a real application, credentials would be obtained from environment variables,\n# a service account file, or other configuration.\n# For example, to use default credentials:\n\ntry:\n    credentials, project = google.auth.default()\n\n    # If credentials are refreshable and expired, try to refresh them.\n    if credentials and credentials.expired and credentials.refresh_token:\n        credentials.refresh(Request())\n\n    print(f\"Successfully obtained credentials for project: {project}\")\n    print(f\"Credentials scope(s): {credentials.scopes}\")\nexcept Exception as e:\n    print(f\"Failed to obtain Google Cloud credentials: {e}\")\n    print(\"Ensure 'google-auth' is installed and credentials are configured (e.g., GOOGLE_APPLICATION_CREDENTIALS).\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `google-auth` is included in your project's runtime dependencies (`pip install google-auth`).","message":"This 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Type 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your development environment uses a compatible Python version (e.g., Python 3.8, 3.9, 3.10, 3.11).","message":"The 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}