Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.428s · 25.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.7s · import 0.410s · 26MB
24MB installed
● package 24MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
DatabricksAPI
✓ from databricks_api import DatabricksAPI
✗ from databricks_api.sdk import DatabricksAPI
The primary client class is directly available under the top-level package.
Initializes the `DatabricksAPI` client using a Databricks host URL and a Personal Access Token (PAT). It then demonstrates how to interact with a Databricks service (e.g., `cluster`) to list all available clusters in the workspace. Authentication credentials should be managed securely, preferably via environment variables.
import os
from databricks_api import DatabricksAPI
# Databricks host and token should ideally be loaded from environment variables
# For local testing, replace with your actual values if not set.
DATABRICKS_HOST = os.environ.get("DATABRICKS_HOST", "https://<your-workspace-url>.cloud.databricks.com")
DATABRICKS_TOKEN = os.environ.get("DATABRICKS_TOKEN", "dapi<your-personal-access-token>")
try:
# Initialize the Databricks API client
db = DatabricksAPI(host=DATABRICKS_HOST, token=DATABRICKS_TOKEN)
# Example: List all clusters in the workspace
print("Listing Databricks clusters...")
clusters_response = db.cluster.list_clusters()
if clusters_response and 'clusters' in clusters_response:
for cluster in clusters_response['clusters']:
print(f"- {cluster['cluster_name']} (ID: {cluster['cluster_id']})")
else:
print("No clusters found or error retrieving clusters.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure DATABRICKS_HOST and DATABRICKS_TOKEN environment variables are set correctly,")
print("or provided directly to the DatabricksAPI constructor, and that your token has sufficient permissions.")
Debug
Known issues
breakingThis library is deprecated. The project explicitly recommends switching to the official `databricks-sdk` for Python, which is actively maintained and provides comprehensive coverage of Databricks APIs. Continuing to use `databricks-api` may lead to unaddressed issues, lack of new features, or compatibility problems with newer Databricks API versions.fixMigrate your code to use the `databricks-sdk` by installing it (`pip install databricks-sdk`) and updating your imports and API calls as per its documentation.
affects: All versions
gotchaAuthentication relies on providing `host` and `token` (Databricks Personal Access Token) either directly to the `DatabricksAPI` constructor or via environment variables (`DATABRICKS_HOST`, `DATABRICKS_TOKEN`). Incorrect values or insufficient permissions for the PAT will result in authentication or API access errors.fixVerify that your Databricks host URL is correct and your Personal Access Token is valid and has the necessary permissions (e.g., 'Can Manage' for clusters, 'Can Read' for workspace objects). Set `DATABRICKS_HOST` and `DATABRICKS_TOKEN` environment variables or pass them explicitly.
affects: All versions
gotchaThe Databricks Community Edition (free tier) has network restrictions that block outbound API calls to external services, including often the Databricks APIs themselves when accessed programmatically from outside the Databricks environment.fixTo use this or any Databricks API client, you typically need a full Databricks workspace on AWS, Azure, or GCP. For Community Edition, consider running ETL/API interaction code locally and uploading results.
affects: All versions
gotchaThe `databricks-api` package is auto-generated based on `databricks-cli` version 0.17.0 for API version 2.0. Future changes in the underlying `databricks-cli` or updates to the Databricks API (beyond 2.0) may introduce undocumented breaking changes or inconsistencies in the `databricks-api` interface if it is not updated to reflect them.fixMonitor changes in the Databricks REST API documentation and consider migrating to the official `databricks-sdk` which is actively maintained to stay compatible with the latest API versions.
affects: All versions, especially with newer Databricks API features
Errors
Common errors & fixes
AttributeError: type object 'DatabricksAPI' has no attribute 'workspace'
Users attempt to access API clients like `workspace` directly on the `DatabricksAPI` class before instantiating it.
fixFirst, create an instance of the `DatabricksAPI` class with your host and token, then access its attributes: `db = DatabricksAPI(host='your_host', token='your_token'); db.workspace.list()`
Error 403 User not authorized
This error occurs when the Databricks personal access token or service principal credentials used for authentication lack the necessary permissions to perform the requested operation, or are invalid/expired.
fixEnsure the Databricks token is valid, has not expired, and possesses the required API permissions for the operations being attempted. Verify that the user or service principal associated with the token has the correct roles and access control settings in Databricks.
ModuleNotFoundError: No module named 'databricks_api'
The `databricks-api` package is either not installed, installed in a different Python environment, or there's a typo in the import statement.
fixInstall the package using pip: `pip install databricks-api`. Ensure your Python environment is correctly configured and that the import statement is `from databricks_api import DatabricksAPI` (or similar).
AttributeError: 'str' object has no attribute 'absolute_path'
This error typically arises when a string representing a DBFS path is passed to a method that expects a `DbfsPath` object, commonly when interacting with the `databricks_cli.dbfs.api` or related modules.
fixWrap the string path with `DbfsPath()` before passing it to the method: `from databricks_cli.dbfs.dbfs_path import DbfsPath; dbfs_path_obj = DbfsPath('dbfs:/path/to/file'); dbfs_api.get_file(dbfs_path_obj, ...)` Upgrade
Version history
0.9.0latest on PyPI · released Jun 8, 2023
Audit
Dependencies
databricks-clirequiredThis library is auto-generated from and relies on the databricks-cli package for its underlying client functionality.