{"record":{"id":"25fbe23314092eb4","repo":"pola-rs/polars","slug":"google-auth-must-be-installed-to-use-credentialpr","errorCode":null,"errorMessage":"google-auth must be installed to use `CredentialProviderGCP`","messagePattern":"google-auth must be installed to use `CredentialProviderGCP`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/cloud/credential_provider/_providers.py","lineNumber":588,"sourceCode":"        creds.refresh(google.auth.transport.requests.Request())  # type: ignore[no-untyped-call, unused-ignore]\n\n        return {\"bearer_token\": creds.token}, (  # type: ignore[dict-item]\n            int(\n                (\n                    expiry.replace(tzinfo=zoneinfo.ZoneInfo(\"UTC\"))\n                    if expiry.tzinfo is None\n                    else expiry\n                ).timestamp()\n            )\n            if (expiry := creds.expiry) is not None\n            else None\n        )\n\n    @classmethod\n    def _ensure_module_availability(cls) -> None:\n        if importlib.util.find_spec(\"google.auth\") is None:\n            msg = \"google-auth must be installed to use `CredentialProviderGCP`\"\n            raise ImportError(msg)\n\n\nclass UserProvidedGCPToken(CredentialProvider):\n    \"\"\"User-provided GCP token in storage_options.\"\"\"\n\n    def __init__(self, token: str) -> None:\n        self.token = token\n\n    def __call__(self) -> CredentialProviderFunctionReturn:\n        return {\"bearer_token\": self.token}, None\n\n\ndef _get_credentials_from_provider_expiry_aware(\n    credential_provider: CredentialProviderFunction,\n) -> dict[str, str] | None:\n    if (\n        isinstance(credential_provider, CredentialProviderAWS)\n        and not credential_provider._can_use_as_provider()","sourceCodeStart":570,"sourceCodeEnd":606,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/cloud/credential_provider/_providers.py#L570-L606","documentation":"Polars' `CredentialProviderGCP` requires the `google-auth` package to obtain GCP credentials. At construction time, `_ensure_module_availability` checks whether `google.auth` is importable and raises this ImportError immediately if it is not. This is a deliberate fail-fast so users learn the optional dependency is missing rather than getting an obscure failure later during I/O.","triggerScenarios":"Instantiating `pl.credential_providers.CredentialProviderGCP()` (or passing it to scan/read functions lazily when credentials are fetched) in an environment where the `google-auth` package is not installed.","commonSituations":"Running on machines/CI images without GCP libraries installed while reading GCS paths (gs://) with cloud auth enabled; using a slim polars install since polars does not bundle google-auth as a hard dependency; virtualenv not activated so the package installed elsewhere isn't visible.","solutions":["Install the missing dependency: `pip install google-auth` (or `pip install 'polars[gcp]'` if the extra is available).","If credentials are supplied another way (service-account key JSON in storage_options, GOOGLE_APPLICATION_CREDENTIALS with google-auth installed), install google-auth anyway or use a different credential mechanism such as explicit `storage_options` tokens.","Verify the active interpreter/venv has the package: `python -c \"import google.auth\"`.","If GCP is not actually being used, remove the `CredentialProviderGCP` usage from the scan/read call."],"exampleFix":"// before\nprovider = CredentialProviderGCP()\ndf = pl.read_csv(\"gs://bucket/file.csv\", credential_provider=provider)\n# after\n# pip install google-auth\nprovider = CredentialProviderGCP()\ndf = pl.read_csv(\"gs://bucket/file.csv\", credential_provider=provider)","handlingStrategy":"try-catch","validationCode":"import importlib.util\nif importlib.util.find_spec(\"google.auth\") is None:\n    raise SystemExit(\"Install google-auth: pip install google-auth\")","typeGuard":"def has_google_auth() -> bool:\n    return importlib.util.find_spec(\"google.auth\") is not None","tryCatchPattern":"try:\n    provider = CredentialProviderGCP()\nexcept ImportError as e:\n    if \"google-auth\" in str(e):\n        provider = None  # fall back to storage_options/env credentials\n    else:\n        raise","preventionTips":["Pin optional cloud extras in requirements (e.g. polars[gcp] or google-auth) for any environment reading gs:// paths.","Run `python -c \"import google.auth\"` as a CI smoke test before I/O jobs.","Keep one canonical venv per project so installs don't land in the wrong interpreter."],"tags":["python","dependency","gcp","import-error"],"backgroundTag":"missing-optional-dependency","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}