pola-rs/polars · error · ImportError

boto3 must be installed to use `CredentialProviderAWS`

Error message

boto3 must be installed to use `CredentialProviderAWS`

What it means

CredentialProviderAWS requires boto3 to fetch AWS credentials. At construction, _ensure_module_availability checks for the boto3 module and raises ImportError immediately if it is absent, so users get a clear message instead of a failure deep inside credential retrieval.

Solutions

  1. pip install boto3.
  2. Install the bundle: pip install 'polars[aws]' (or fsspec/s3fs equivalents).
  3. Use a different credential mechanism (explicit keys in storage_options, or CredentialProviderAWS replaced by env vars AWS_ACCESS_KEY_ID etc.).

Example fix

// before
 provider = pl.CredentialProviderAWS()
// after
 # pip install boto3
 provider = pl.CredentialProviderAWS()
Defensive patterns

Strategy: try-catch

Validate before calling

import importlib.util
if importlib.util.find_spec('boto3') is None:
    raise RuntimeError('install boto3 before using CredentialProviderAWS')

Type guard

def can_use_aws_provider() -> bool:
    return importlib.util.find_spec('boto3') is not None

Try / catch

try:
    provider = pl.CredentialProviderAWS()
except ImportError as e:
    if 'boto3 must be installed' in str(e):
        provider = None  # rely on AWS_ACCESS_KEY_ID env vars
    else:
        raise

Prevention

When it happens

Trigger: Instantiating CredentialProviderAWS directly or via credential_provider='aws' when boto3 is not installed in the environment.

Common situations: Fresh venv/CI image without boto3; polars installed bare (no cloud extras); code moved from a machine with AWS tooling to one without.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/f4a0c0402fe0c2d7. Report an issue: GitHub.

Appendix: source

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

            return False

        return True

    def _session(self) -> boto3.Session:
        # Note: boto3 automatically sources the AWS_PROFILE env var
        import boto3

        return boto3.Session(
            profile_name=self.profile_name,
            region_name=self.region_name,
        )

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

    class EmptyCredentialError(Exception):
        """
        Raised when boto3 returns empty credentials.

        This generally indicates that no credentials could be found in the
        environment.
        """


class CredentialProviderAzure(CachingCredentialProvider):
    """
    Azure Credential Provider.

    Using this requires the `azure-identity` Python package to be installed.

    .. warning::
        This functionality is considered **unstable**. It may be changed

View on GitHub (pinned to fe841f959e)