Skip to main content

Production-focused Databricks API toolkit by Rehla Digital Inc for workspace and account automation on AWS.

Project description

Unified Databricks API

Single Python package to call Databricks Workspace and Account APIs and convert JSON responses into Pandas or PySpark DataFrames.

About Rehla Digital Inc

Rehla Digital Inc builds cloud and data engineering solutions that help teams standardize platform operations, accelerate delivery, and reduce integration risk. This package is maintained as part of that effort to provide a practical, production-oriented Databricks API toolkit.

Install

pip install rehla-dbx-tools

Import in Python with underscores:

from rehla_dbx_tools import DatabricksApiClient

Install Spark extras if needed:

pip install "rehla-dbx-tools[spark]"

Quick Start

from rehla_dbx_tools import DatabricksApiClient

client = DatabricksApiClient.from_env()
if client.workspace is not None:
    jobs = client.workspace.list_jobs()
    df = jobs.to_pandas()
    print(df.head())

# Force both workspace/account config to a target cloud
client = DatabricksApiClient.from_env_for_cloud("azure")

Notebook Context Bootstrap

Inside Databricks notebooks:

from rehla_dbx_tools import DatabricksApiClient

client = DatabricksApiClient.from_notebook_context()
if client.workspace is not None:
    clusters = client.workspace.list_clusters()
    spark_df = clusters.to_spark()
    display(spark_df)

Account API

account client is enabled when DATABRICKS_ACCOUNT_HOST and DATABRICKS_ACCOUNT_ID are set.

if client.account is not None:
    workspaces = client.account.list_workspaces()
    print(workspaces.to_pandas().head())

Version-Aware Generic Request

response = client.workspace.request_versioned(
    "GET",
    service="unity-catalog",
    endpoint="metastores",
    api_version="2.1",
)

Expanded Convenience Wrappers

import getpass

if client.workspace is not None:
    run = client.workspace.run_job_now(job_id=123)
    runs = client.workspace.list_job_runs(job_id=123, active_only=True, limit=10)
    run_export = client.workspace.export_job_run(run_id=987, views_to_export="CODE")
    run_output = client.workspace.get_job_run_output(run_id=987)
    run_submit = client.workspace.submit_job_run({"run_name": "ad-hoc-check"})
    run_delete = client.workspace.delete_job_run(run_id=987)
    repair = client.workspace.repair_job_run(run_id=987, rerun_all_failed_tasks=True)
    cancel_all = client.workspace.cancel_all_job_runs(job_id=123, all_queued_runs=True)
    cluster = client.workspace.get_cluster(cluster_id="0123-abc")
    catalogs = client.workspace.list_catalogs(max_results=25)
    warehouses = client.workspace.list_sql_warehouses()
    dbfs_files = client.workspace.list_dbfs("dbfs:/tmp")
    token = client.workspace.create_token(lifetime_seconds=3600, comment="ci-short-lived")
    rotated_token = client.workspace.rotate_token(
        token_id_to_revoke="old-token-id",
        lifetime_seconds=3600,
        comment="ci-rotation",
    )
    repos = client.workspace.list_repos(path_prefix="/Repos/team")
    repo = client.workspace.get_repo(repo_id=12345)
    client.workspace.put_secret(
        scope="app-prod",
        key="api-token",
        string_value=getpass.getpass("Secret value: "),
    )

if client.account is not None:
    ws = client.account.get_workspace(workspace_id=101)
    creds = client.account.list_credentials()
    storage_cfgs = client.account.list_storage_configurations()
    networks = client.account.list_networks()
    private_access = client.account.list_private_access_settings()
    vpc_endpoints = client.account.list_vpc_endpoints()
    cmks = client.account.list_customer_managed_keys()
    users = client.account.list_users()
    user = client.account.get_user("user-101")
    groups = client.account.list_groups()
    group = client.account.get_group("group-101")
    budgets = client.account.list_budget_policies()
    log_delivery_configs = client.account.list_log_delivery_configurations()

For detailed setup and examples, see docs/USAGE.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rehla_dbx_tools-1.0.0.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rehla_dbx_tools-1.0.0-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file rehla_dbx_tools-1.0.0.tar.gz.

File metadata

  • Download URL: rehla_dbx_tools-1.0.0.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rehla_dbx_tools-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ea0280fd2294081d240d3ddcaf3f57022110c22bc7685d3d5be54661c0275dca
MD5 291f0c27ccd58313b38994cd82019647
BLAKE2b-256 6ade2f98f28a3d5f88e6dad5ec9cfe9a6b4aad18e06cdb6b0dcb9429ef8d1c05

See more details on using hashes here.

Provenance

The following attestation bundles were made for rehla_dbx_tools-1.0.0.tar.gz:

Publisher: workflow.yml on rehladigital/rehla_dbx_tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rehla_dbx_tools-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rehla_dbx_tools-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3cb2b230da79d8215323c826f06a9d59d89f9bafbcdbae2264dd5936c6cb82e
MD5 9c7340ae406efbfcb13650f867126a93
BLAKE2b-256 9b7203d48c3c75d021be5077b1d9a933cd1ab17e0e05ec7765e7fa67e102b8ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for rehla_dbx_tools-1.0.0-py3-none-any.whl:

Publisher: workflow.yml on rehladigital/rehla_dbx_tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page