Unity Catalog Client
The `unitycatalog-client` is the official Python SDK for interacting with Databricks Unity Catalog APIs. It provides programmatic access to manage catalogs, schemas, tables, volumes, and other Unity Catalog assets. Currently at version 0.4.1, it receives frequent updates, often with multiple releases per month, reflecting ongoing development and new feature integration.
Warnings
- breaking As the library is pre-1.0 (currently v0.4.1), its API surface, including method signatures, return types, and available models, may change in minor or even patch releases without strictly adhering to semantic versioning for breaking changes.
- gotcha Authentication requires `DATABRICKS_HOST` and `DATABRICKS_TOKEN` to be set as environment variables or passed directly to the `UnityCatalogClient` constructor. Incorrect or missing credentials will result in authentication failures.
- gotcha When operating within a Databricks environment (e.g., notebooks, jobs) or if you are already using `databricks-sdk`, you can leverage its authentication context to instantiate `UnityCatalogClient`. Not knowing this integration path can lead to redundant credential management.
Install
-
pip install unitycatalog-client
Imports
- UnityCatalogClient
from unitycatalog_client import UnityCatalogClient
Quickstart
import os
from unitycatalog_client import UnityCatalogClient
# To run this code, set the following environment variables:
# os.environ['DATABRICKS_HOST'] = 'https://<your-databricks-host>'
# os.environ['DATABRICKS_TOKEN'] = 'dapi...' # A Databricks personal access token
try:
# The client automatically picks up DATABRICKS_HOST and DATABRICKS_TOKEN
# from environment variables if not provided explicitly.
client = UnityCatalogClient()
print("Attempting to list catalogs in Unity Catalog...")
catalogs = client.list_catalogs()
if catalogs:
print(f"Successfully retrieved {len(catalogs)} catalogs:")
for catalog in catalogs:
print(f"- Name: {catalog.name}, Full Name: {catalog.full_name}")
else:
print("No catalogs found or accessible.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure DATABRICKS_HOST and DATABRICKS_TOKEN environment variables are set and valid,")
print("and that your token has permissions to list catalogs.")