Databricks API Client (Legacy)
The `databricks-api` package provides a simplified Python interface for the Databricks REST API. It is auto-generated from the underlying client library used in the official `databricks-cli` Python package. This library is now deprecated, and users are strongly advised to migrate to the official `databricks-sdk` for ongoing development and support. The package saw its last release (0.9.0) in June 2023.
Warnings
- breaking This 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.
- gotcha Authentication 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.
- gotcha The 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.
- gotcha The `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.
Install
-
pip install databricks-api
Imports
- DatabricksAPI
from databricks_api import DatabricksAPI
Quickstart
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.")