Skip to main content

Workflow and automation

Delta Sharing operations can be fully automated using the Databricks REST API, Python SDK, or SQL commands. This enables self-service onboarding, scheduled maintenance, and integration with CI/CD pipelines.

Common workflows

WorkflowDescriptionAutomation approach
Recipient onboardingCreate recipients, assign to shares, distribute credentialsSDK/API triggered by request form or CRM
Share provisioningCreate shares, add tables/views, configure partitionsTerraform or SDK in CI/CD pipeline
Token rotationRotate bearer tokens on scheduleScheduled Workflow with SDK
Access revocationRemove recipients or revoke grantsAPI call triggered by contract termination
Schema updatesAdd new tables or columns to existing sharesSDK in data pipeline post-deployment

Automation tools

ToolBest forDocumentation
REST APIDirect HTTP calls, language-agnostic integrationsShares, Recipients, Providers
Python SDK - SharingShares, recipients, grantsSharing module
Python SDK - MarketplaceListings, consumer requests, exchangesMarketplace module
SQLAd-hoc operations, notebook-based workflowsDelta Sharing SQL
TerraformInfrastructure-as-code, declarative provisioningDatabricks Terraform Provider

Use the Sharing module for D2D or open sharing outside of Marketplace. Use the Marketplace module when you need to programmatically manage listings, fulfill consumer requests, or work with private exchanges.

Example scripts

note

These scripts are provided as starting points for your automation. Review, test, and adapt them for your environment before use in production.

Self-service onboarding

Automate recipient onboarding with a Databricks Workflow triggered by a request form:

from databricks.sdk import WorkspaceClient

def onboard_recipient(customer_name: str, sharing_id: str, license: str):
"""Automated recipient onboarding."""
w = WorkspaceClient()

# Create recipient with properties
recipient = w.recipients.create(
name=customer_name.lower().replace(" ", "_"),
sharing_code=sharing_id,
properties_kvpairs={"properties": {"customer_code": customer_name, "license": license}}
)

# Grant access to appropriate shares based on license
w.shares.update_permissions(
name=f"{license}_data_share",
changes=[{"principal": recipient.name, "add": ["SELECT"]}]
)
return recipient

Audit all shares and recipients

Generate a compliance report of all shares, their objects, and who has access:

def audit_shares():
"""Generate a complete audit of shares and recipients."""
w = WorkspaceClient()
audit = []

for share in w.shares.list():
share_detail = w.shares.get(share.name)
permissions = w.shares.share_permissions(share.name)

audit.append({
"share": share.name,
"objects": [obj.name for obj in (share_detail.objects or [])],
"recipients": [p.principal for p in (permissions.privilege_assignments or [])]
})

return audit

Scheduled token rotation

Rotate tokens for open sharing recipients on a regular schedule:

def rotate_tokens_for_recipients(recipient_names: list[str]):
"""Rotate tokens for specified recipients."""
w = WorkspaceClient()
for name in recipient_names:
w.recipients.rotate_token(name=name)
# In production: send new activation link via secure channel

Schedule this as a Databricks Workflow to run monthly or quarterly.

Bulk revoke access

Revoke access for all recipients matching a naming pattern (e.g., during offboarding):

import re

def revoke_recipients_matching(pattern: str, dry_run: bool = True):
"""Revoke all shares from recipients matching a regex pattern."""
w = WorkspaceClient()
regex = re.compile(pattern)

for recipient in w.recipients.list():
if regex.match(recipient.name):
if dry_run:
print(f"[DRY RUN] Would revoke: {recipient.name}")
else:
w.recipients.delete(recipient.name)
print(f"Revoked: {recipient.name}")

# Preview what would be revoked
revoke_recipients_matching(r"^test_.*", dry_run=True)

Export metadata for backup

Export all share configurations to JSON for disaster recovery:

import json
from datetime import datetime

def export_share_metadata(output_file: str = None):
"""Export all share metadata to JSON."""
w = WorkspaceClient()

export = {"exported_at": datetime.now().isoformat(), "shares": [], "recipients": []}

for share in w.shares.list():
detail = w.shares.get(share.name)
export["shares"].append({
"name": share.name,
"objects": [{"name": o.name, "type": o.data_object_type} for o in (detail.objects or [])]
})

for recipient in w.recipients.list():
export["recipients"].append({"name": recipient.name, "type": recipient.authentication_type})

if output_file:
with open(output_file, "w") as f:
json.dump(export, f, indent=2)
return export

SQL quick reference

Shares

-- Create
CREATE SHARE my_share COMMENT 'Description';

-- Add assets
ALTER SHARE my_share ADD TABLE catalog.schema.table_name;
ALTER SHARE my_share ADD TABLE catalog.schema.table_name WITH HISTORY;
ALTER SHARE my_share ADD TABLE catalog.schema.table_name
PARTITION (region = 'us-west');
ALTER SHARE my_share ADD VIEW catalog.schema.view_name;
ALTER SHARE my_share ADD VOLUME catalog.schema.volume_name;

-- Remove assets
ALTER SHARE my_share REMOVE TABLE catalog.schema.table_name;

-- List and describe
SHOW SHARES;
DESCRIBE SHARE my_share;
SHOW ALL IN SHARE my_share;

-- Delete
DROP SHARE my_share;

Recipients

-- Create D2D recipient
CREATE RECIPIENT acme_corp USING ID '<sharing-identifier>';

-- Create D2O recipient (token-based)
CREATE RECIPIENT external_partner COMMENT 'Partner XYZ';

-- Create with properties
CREATE RECIPIENT acme_corp
USING ID '<sharing-identifier>'
PROPERTIES ('customer_code' = 'ACME', 'license' = 'enterprise');

-- Update properties
ALTER RECIPIENT acme_corp SET PROPERTIES ('license' = 'professional');

-- Rotate token (D2O only)
ALTER RECIPIENT external_partner ROTATE TOKEN;

-- List and describe
SHOW RECIPIENTS;
DESCRIBE RECIPIENT acme_corp;

-- Delete
DROP RECIPIENT acme_corp;

Grants

-- Grant access
GRANT SELECT ON SHARE my_share TO RECIPIENT acme_corp;

-- Revoke access
REVOKE SELECT ON SHARE my_share FROM RECIPIENT acme_corp;

-- View grants
SHOW GRANTS ON SHARE my_share;
SHOW GRANTS TO RECIPIENT acme_corp;

Information schema queries

-- List all shares
SELECT * FROM system.information_schema.shares;

-- List share contents
SELECT * FROM system.information_schema.share_objects
WHERE share_name = 'my_share';

-- List recipients
SELECT * FROM system.information_schema.recipient_tokens;

-- List recipient permissions
SELECT * FROM system.information_schema.share_recipient_privileges;

For complete syntax, see the Delta Sharing SQL reference.

SDK quick reference

The Databricks Python SDK provides programmatic access to Delta Sharing and Marketplace operations.

Installation

pip install databricks-sdk

Delta Sharing operations

from databricks.sdk import WorkspaceClient
w = WorkspaceClient()

# Shares
w.shares.list() # List all shares
w.shares.get(name="my_share") # Get share details
w.shares.create(name="...", ...) # Create share
w.shares.update(name="...", ...) # Update share
w.shares.delete(name="...") # Delete share
w.shares.share_permissions(name) # Get share permissions
w.shares.update_permissions(...) # Update permissions

# Recipients
w.recipients.list() # List all recipients
w.recipients.get(name="...") # Get recipient details
w.recipients.create(name="...", ...) # Create recipient
w.recipients.rotate_token(name) # Rotate token
w.recipients.delete(name="...") # Delete recipient

Full reference: Sharing module documentation

Marketplace operations

# Provider operations
w.provider_listings.list() # List your listings
w.provider_listings.get(id="...") # Get listing details
w.provider_personalization_requests.list() # List access requests
w.provider_exchanges.list() # List private exchanges

# Consumer operations
w.consumer_listings.list() # Browse listings
w.consumer_listings.get(id="...") # Get listing details

Full reference: Marketplace module documentation

What's next