pola-rs/polars · error · ImportError

azure-identity must be installed to use `CredentialProviderA

Error message

azure-identity must be installed to use `CredentialProviderAzure`

What it means

CredentialProviderAzure._ensure_module_availability (py-polars/src/polars/io/cloud/credential_provider/_providers.py:452-457) checks importlib.util.find_spec('azure.identity') and raises ImportError when the Python Azure credential provider is needed but azure-identity is not installed. It is only reached when no user `credential` object was supplied and no account key could be retrieved from the Azure CLI.

Source

Thrown at py-polars/src/polars/io/cloud/credential_provider/_providers.py:457

                if verbose:
                    eprint(
                        "[CredentialProviderAzure]: Retrieved account key from Azure CLI"
                    )
            except Exception as e:
                if verbose:
                    eprint(
                        f"[CredentialProviderAzure]: Could not retrieve account key from Azure CLI: {e}"
                    )
            else:
                return creds, None

        return None

    @classmethod
    def _ensure_module_availability(cls) -> None:
        if importlib.util.find_spec("azure.identity") is None:
            msg = "azure-identity must be installed to use `CredentialProviderAzure`"
            raise ImportError(msg)

    @staticmethod
    def _extract_adls_uri_storage_account(uri: str) -> str | None:
        # "abfss://{CONTAINER}@{STORAGE_ACCOUNT}.dfs.core.windows.net/"
        #                      ^^^^^^^^^^^^^^^^^
        try:
            return (
                uri.split("://", 1)[1]
                .split("/", 1)[0]
                .split("@", 1)[1]
                .split(".dfs.core.windows.net", 1)[0]
            )

        except IndexError:
            return None

    @classmethod
    def _get_azure_storage_account_key_az_cli(cls, account_name: str) -> str:

View on GitHub (pinned to df599052da)

Solutions

  1. pip install azure-identity
  2. Authenticate the Azure CLI (az login) so the account-key fast path can be used without the package
  3. Pass an account key via storage_options to stay on the native Rust path

Example fix

# before
lf = pl.scan_parquet("az://container/f.parquet")  # ImportError
# after
# $ pip install azure-identity
lf = pl.scan_parquet("az://container/f.parquet")
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

def require_azure_identity() -> None:
    if importlib.util.find_spec("azure.identity") is None:
        raise ImportError("pip install azure-identity for az:///abfss:// access")

Try / catch

try:
    lf = pl.scan_parquet(url)
except ImportError as e:
    if "azure-identity" in str(e):
        raise SystemExit("pip install azure-identity (or pass an account_key via storage_options)") from e
    raise

Prevention

When it happens

Trigger: pl.scan_parquet('az://container/f.parquet') (or abfss://) with no storage_options key, no az login, and no azure-identity package; or explicitly via pl.CredentialProviderAzure().

Common situations: Fresh CI/deployment images without the Azure extra; code that previously only read public containers now pointed at private ones.

Related errors


AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16). Data as JSON: /api/errors/ff7a561cd0ee177c. Report an issue: GitHub.