{"record":{"id":"302d155a65548a03","repo":"pola-rs/polars","slug":"could-not-get-databricks-token-databricks-sdk-is","errorCode":null,"errorMessage":"could not get Databricks token: databricks-sdk is not installed","messagePattern":"could not get Databricks token: databricks-sdk is not installed","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/catalog/unity/client.py","lineNumber":700,"sourceCode":"            ), storage_options\n\n        # This should generally not happen, but if using the temporary\n        # credentials API fails for whatever reason, we fallback to our built-in\n        # credential provider resolution.\n\n        from polars.io.cloud.credential_provider._builder import (\n            _init_credential_provider_builder,\n        )\n\n        return _init_credential_provider_builder(\n            \"auto\", table_info.storage_location, storage_options, caller_name\n        ), storage_options\n\n    @classmethod\n    def _get_databricks_token(cls) -> str:\n        if importlib.util.find_spec(\"databricks.sdk\") is None:\n            msg = \"could not get Databricks token: databricks-sdk is not installed\"\n            raise ImportError(msg)\n\n        # We code like this to bypass linting\n        m = importlib.import_module(\"databricks.sdk.core\").__dict__\n\n        return m[\"DefaultCredentials\"]()(m[\"Config\"]())()[\"Authorization\"][7:]\n\n\nclass CatalogCredentialProvider:\n    \"\"\"Retrieves credentials from the Unity catalog temporary credentials API.\"\"\"\n\n    catalog: Catalog\n    table_id: str\n    write: bool\n\n    def __init__(self, catalog: Catalog, table_id: str, *, write: bool) -> None:\n        self.catalog = catalog\n        self.table_id = table_id\n        self.write = write","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/catalog/unity/client.py#L682-L718","documentation":"`_get_databricks_token` raises ImportError when it needs to fetch a Databricks access token (bearer_token set to \"databricks-sdk\" or \"auto\" inside a Databricks environment) but the `databricks-sdk` package is not installed. Polars intentionally does not bundle the SDK and delegates authentication to its DefaultCredentials chain.","triggerScenarios":"Creating the Unity Catalog client with bearer_token=\"databricks-sdk\", or bearer_token=\"auto\" while running inside Databricks (notebook/compute), in an environment where `databricks.sdk` cannot be imported.","commonSituations":"Installing polars in a slim Docker image or serverless environment without databricks-sdk; forgetting to add the dependency to requirements; runtime Databricks cluster whose SDK isn't visible to the current Python env (wrong interpreter/venv).","solutions":["Install the SDK: `pip install databricks-sdk` (or add it to your dependencies)","Alternatively pass an explicit bearer_token string so the SDK lookup is skipped entirely","Verify the environment running Polars is the one where the SDK is installed (check `python -c \"import databricks.sdk\"`)"],"exampleFix":"// before (shell)\npip install polars  # missing databricks-sdk\nclient = CatalogClient(workspace_url=url, bearer_token=\"databricks-sdk\")\n// after\npip install \"databricks-sdk\"\nclient = CatalogClient(workspace_url=url, bearer_token=\"databricks-sdk\")","handlingStrategy":"fallback","validationCode":"import importlib.util\nif bearer_token in {'databricks-sdk','auto'} and importlib.util.find_spec('databricks.sdk') is None:\n    raise ImportError('pip install databricks-sdk')","typeGuard":"def databricks_sdk_installed() -> bool:\n    import importlib.util\n    return importlib.util.find_spec('databricks.sdk') is not None","tryCatchPattern":"try:\n    client = CatalogClient(workspace_url=url, bearer_token='databricks-sdk')\nexcept ImportError as e:\n    if 'databricks-sdk is not installed' in str(e):\n        client = CatalogClient(workspace_url=url, bearer_token=os.environ['DATABRICKS_TOKEN'])\n    else:\n        raise","preventionTips":["Add databricks-sdk to requirements whenever you use bearer_token='databricks-sdk' or 'auto'","Verify imports in the actual runtime interpreter/venv (CI vs notebook envs differ)","Prefer explicit PAT tokens in environments where you don't want the SDK dependency"],"tags":["python","databricks","dependency","authentication"],"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"}