Sub topic 1
Why automate Databricks, and which tool to use
Clicking through the workspace UI works for one-off tasks. It breaks down when you need the same action repeated, reviewed, or run on a schedule. This chapter explains what automation gives you and which of the four tools in this tutorial fits which job.
Prerequisites
This chapter assumes you have:
- Basic command-line use: a shell, environment variables, and pipes.
- Familiarity with the Databricks workspace, jobs, and clusters.
- A basic understanding of HTTP requests and JSON.
- Basic Python, for the SDK examples later in the tutorial.
Why automate
Scripting a workspace instead of using the UI gives you four things:
- Repeatability. A script does the same thing each time. A person following a checklist does not.
- Review. Configuration stored in version control can be read, diffed, and approved before it changes anything.
- Scheduling and triggers. Pipelines can start a job after a build, or deploy after a merge, with no one present.
- Scale. Updating 40 jobs, or three workspaces, takes the same effort as updating one.
The four tools
Each tool sits at a different level of abstraction. All of them end up calling the Databricks REST API.
| Tool | What it is | Best for |
|---|---|---|
| Databricks CLI | A command-line program with one command group per feature area | Shell scripts, quick checks, ad hoc admin work |
| REST API | HTTP endpoints you call with `curl` or any HTTP client | Languages or systems where the CLI and SDK are not available |
| Databricks SDK for Python | A Python library that wraps the API | Application logic, loops, and error handling in Python |
| Declarative Automation Bundles (Asset Bundles) | A `databricks.yml` file describing resources, deployed with the CLI | Deploying jobs and pipelines as code from version control |
Choosing a tool
Start from the task, not the tool:
- Run a command once, or glue a few together in a shell script. Use the CLI. Its
--output jsonoption pairs well withjq. - Call from a language or environment with no CLI. Use the REST API directly. You handle authentication, pagination, and errors yourself.
- Write Python that reacts to results. Use the SDK. It handles authentication and pagination for you.
- Keep jobs and other resources in Git and deploy them the same way every time. Use bundles.
These choices are not exclusive. A common setup uses bundles to deploy a job, the CLI in a CI pipeline to run it, and the SDK in a Python service that monitors it.
What every tool needs
All four tools need the same two things before they can do anything:
- The workspace host, a URL such as
https://<workspace-host>. - A credential, which is either an OAuth login or a personal access token.
The next chapters cover installing the CLI and setting up authentication. Everything after that builds on those two pieces.
Exercise
Your team wants a job's definition stored in Git, reviewed in pull requests, and deployed to a dev and a prod workspace the same way each time. Which tool fits best, and why?
Show answer
Asset Bundles. A databricks.yml file declares the job as code and can define separate targets for dev and prod. It is deployed with databricks bundle deploy, so the definition goes through version control and review. The CLI alone would only run commands, and it would not track the job's desired state.
Exercise
You are writing a Python service that must start a job, wait for it, and retry on failure. Why might the SDK be a better choice than raw requests calls?
Show answer
The SDK handles authentication and pagination for you, so your code contains only the logic you care about. With raw HTTP you must write that code yourself and keep it correct as the API changes.