Skip to main content

Databricks SDK for Go

In this article, you learn how to automate Databricks operations and accelerate development with the Databricks SDK for Go. This article supplements the Databricks SDK for Go README, API reference, and examples.

note

This feature is in Beta and is okay to use in production.

During the Beta period, Databricks recommends that you pin a dependency on the specific minor version of the Databricks SDK for Go that your code depends on, for example, in a project's go.mod file. For more information about pinning dependencies, see Managing dependencies.

Requirements

To use the Databricks SDK for Go, your development machine must have:

Get started with the Databricks SDK for Go

  1. On your development machine with Go already installed, an existing Go code project already created, and Databricks authentication configured, create a go.mod file to track your Go code's dependencies by running the go mod init command, for example:

    Bash
    go mod init sample
  2. Take a dependency on the Databricks SDK for Go package by running the go mod edit -require command, replacing 0.8.0 with the latest version of the Databricks SDK for Go package as listed in the CHANGELOG:

    Bash
    go mod edit -require github.com/databricks/databricks-sdk-go@v0.8.0

    Your go.mod file should now look like this:

    Go
    module sample

    go 1.18

    require github.com/databricks/databricks-sdk-go v0.8.0
  3. Within your project, create a Go code file that imports the Databricks SDK for Go. The following example, in a file named main.go with the following contents, lists all the clusters in your Databricks workspace:

    Go
    package main

    import (
    "context"

    "github.com/databricks/databricks-sdk-go"
    "github.com/databricks/databricks-sdk-go/service/compute"
    )

    func main() {
    w := databricks.Must(databricks.NewWorkspaceClient())
    all, err := w.Clusters.ListAll(context.Background(), compute.ListClustersRequest{})
    if err != nil {
    panic(err)
    }
    for _, c := range all {
    println(c.ClusterName)
    }
    }
  4. Add any missing module dependencies by running the go mod tidy command:

    Bash
    go mod tidy
    note

    If you get the error go: warning: "all" matched no packages, you forgot to add a Go code file that imports the Databricks SDK for Go.

  5. Grab copies of all packages needed to support builds and tests of packages in your main module, by running the go mod vendor command:

    Bash