Databricks API Client (Legacy)

0.9.0 · deprecated · verified Fri Apr 10

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

Install

Imports

Quickstart

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.")

view raw JSON →