Aan de slag met de Databricks-SDK

Databricks met de Python SDK

Avi Steinberg

Software/Data Engineer

Waarom Databricks leren?

Profielfoto

  • Toonaangevend ML-, AI- en data-engineeringcloudplatform
  • Gebruikt door >60% van de Fortune 500

Databricks-embleem

1 https://www.databricks.com/company/newsroom/press-releases/databricks-raising-10b-series-j-investment-62b-valuation
Databricks met de Python SDK

Wat is een Databricks-werkruimte?

  • Databricks-implementatie van cloudresources
  • Omgeving om Databricks-assets te benaderen
  • Voorbeelden in de Databricks-werkruimte: jobs, clusters en notebooks
Databricks met de Python SDK

Databricks-SDK installeren

Installeer de SDK

pip install databricks-sdk

Maak WorkspaceClient aan

from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
1 https://docs.databricks.com/en/dev-tools/sdk-python.html#language-venv
Databricks met de Python SDK

Authenticatie-omgevingsvariabelen

  • Omgevingsvariabele = key/value-paar om applicatiegedrag te configureren

  • DATABRICKS_CLIENT_SECRET

  • DATABRICKS_CLIENT_ID
  • DATABRICKS_HOST=<workspace_id>.cloud.databricks.com

Schermafbeelding van Databricks Workspace-web-URL

Databricks met de Python SDK

Authenticeren met een Service Principal

  • Service Principal = beveiligingsidentiteit in een cloudplatform die een applicatie vertegenwoordigt

  • Maak een Service Principal

  • Ken rechten toe aan een Service Principal
  • Genereer een secret voor de Service Principal

Afbeelding van Secrets-pagina voor Databricks Workspace Service Principal

1 https://docs.databricks.com/en/dev-tools/auth/oauth-m2m.html#step-1-create-a-service-principal
Databricks met de Python SDK

Standaardauthenticatie

from databricks.sdk import WorkspaceClient
import os

os.environ['DATABRICKS_CLIENT_SECRET'] = "Your-Client-Secret"
os.environ['DATABRICKS_CLIENT_ID'] = "Your-Databricks-Client-Id"
os.environ['DATABRICKS_HOST'] = "Your-Databricks-Host"
w = WorkspaceClient()
  • Leest automatisch de waarden van de drie omgevingsvariabelen
Databricks met de Python SDK

Interactie met onze Databricks-werkruimte

# Authenticate WorkspaceClient
from databricks.sdk import WorkspaceClient
import os
os.environ['DATABRICKS_CLIENT_SECRET'] = "Your-Client-Secret"
os.environ['DATABRICKS_CLIENT_ID'] = "Your-Databricks-Client-Id"
os.environ['DATABRICKS_HOST'] = "Your-Databricks-Host"
w = WorkspaceClient()

# Create Cluster: cluster = w.clusters.create(cluster_name="Test-Cluster")
# List Clusters: for cluster in w.clusters.list(): print(f"Clusters Name: {cluster.cluster_name}")
Clusters Name: Test-Cluster
1 https://databricks-sdk-py.readthedocs.io/en/latest/clients/workspace.html
Databricks met de Python SDK

Laten we oefenen!

Databricks met de Python SDK

Preparing Video For Download...