README
¶
Databricks SDK for Go
Beta: This SDK is supported for production use cases, but we do expect future releases to have some interface changes; see Interface stability. We are keen to hear feedback from you on these SDKs. Please file issues, and we will address them | See documentation at Go Packages | See also the Terraform Provider | See also the SDK for Python | See also the SDK for Java
The Databricks SDK for Go includes functionality to accelerate development with Go for the Databricks Lakehouse. It covers all public Databricks REST API operations. The SDK's internal HTTP client is robust and handles failures on different levels by performing intelligent retries.
Contents
- Databricks SDK for Go
- Testing
Getting started
-
On your local development machine with Go already installed and a Go code project active, create a
go.modfile to track your Go code's dependencies by running thego mod initcommand, for example:go mod init sample -
Take a dependency on the Databricks SDK for Go package by running the
go mod edit -requirecommand:go mod edit -require github.com/databricks/databricks-sdk-go@latestYour
go.modfile should now look like this:module sample go 1.25 require github.com/databricks/databricks-sdk-go v0.9.0 // Indirect dependencies will go here. -
Within your project, create a Go code file that imports the Databricks SDK for Go. The following example, in a file named
main.gowith the following contents, simply lists all the clusters in your Databricks workspace: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) } } -
Add any misssing module dependencies by running the
go mod tidycommand:go mod tidyNote: If you get the error
go: warning: "all" matched no packages, you forgot to add the preceding Go code file that imports the Databricks SDK for Go. -
Grab copies of all packages needed to support builds and tests of packages in your
mainmodule, by running thego mod vendorcommand:go mod vendor -
Set up Databricks authentication on your local development machine by running
databricks configurecommand, if you have not done so already. For details, see the next section, Authentication. -
Run your Go code file, assuming a file named
main.go, by running thego runcommand:go run main.goAssuming the preceding example code is run, the output is:
[TRACE] Loading config via environment [TRACE] Loading config via config-file ... [TRACE] Attempting to configure auth: pat [TRACE] Attempting to configure auth: basic [TRACE] Attempting to configure auth: azure-client-secret ...
Authentication
If you use Databricks configuration profiles or Databricks-specific environment variables for Databricks authentication, the only code required to start working with a Databricks workspace is the following code snippet, which instructs the Databricks SDK for Go to use its default authentication flow:
w := databricks.Must(databricks.NewWorkspaceClient())
w./*press TAB for autocompletion*/
The conventional name for the variable that holds the workspace-level client of the Databricks SDK for Go is w, which is shorthand for workspace.
In this section
- Default authentication flow
- Unified host support
- Databricks native authentication
- Azure native authentication
- Google Cloud Platform native authentication
- Overriding .databrickscfg
- Additional authentication configuration options
- Custom credentials provider
Default authentication flow
If you run the Databricks Terraform Provider, the Databricks CLI, or applications that target the Databricks SDKs for other langauges, most likely they will all interoperate nicely together. By default, the Databricks SDK for Go tries the following authentication methods, in the following order, until it succeeds:
- Databricks native authentication
- Azure native authentication
- Google Cloud Platform native authentication
- If the SDK is unsuccessful at this point, it returns an authentication error and stops running.
Each authentication method requires specific configuration attributes (e.g., Token for PAT auth, AzureClientID for Azure service principal auth). The SDK automatically detects the cloud provider and skips authentication methods whose required configuration attributes are not present. This means that Azure-specific methods like azure-cli are automatically skipped when connecting to an AWS or GCP workspace, and vice versa for GCP-specific methods.
To force a specific authentication method instead of relying on auto-detection, set the AuthType field in *databricks.Config:
// Force Azure CLI authentication — skip all other methods
w, err := databricks.NewWorkspaceClient(&databricks.Config{
Host: "https://mycompany.databricks.com",
AuthType: "azure-cli",
Cloud: "Azure",
})
This is useful when your environment has credentials for multiple authentication methods and you want to ensure a specific one is used or when auto detection is not accurate.
For each authentication method, the SDK searches for compatible authentication credentials in the following locations, in the following order. Once the SDK finds a compatible set of credentials that it can use, it stops searching:
-
Credentials that hard-coded into
*databricks.Config.Caution: Databricks does not recommend hard-coding credentials into
*databricks.Config, as they can be exposed in plain text in version control systems. Use environment variables or configuration profiles instead. -
Credentials in Databricks-specific environment variables.
-
For Databricks native authentication, credentials in the
.databrickscfgfile'sDEFAULTconfiguration profile from its default file location (~for Linux or macOS, and%USERPROFILE%for Windows). -
For Azure or Google Cloud Platform native authentication, the SDK searches for credentials through the Azure CLI or Google Cloud CLI as needed.
Depending on the Databricks authentication method, the SDK uses the following information. Presented are the *databricks.Config arguments, their descriptions, any corresponding environment variables, and any corresponding .databrickscfg file fields, respectively.
Unified host support
Certain Databricks host types support both account-level and workspace-level API operations from a single endpoint. When using such a unified host, a single configuration profile can be used to create both WorkspaceClient and AccountClient instances without changing the Host.
For this to work, the following conditions must be met:
- The host must support unified operations.
- Both
AccountIDandWorkspaceIDmust be available — either set explicitly in the configuration or auto-discovered.
When both values are present, the SDK uses WorkspaceID to route workspace-level requests and AccountID to route account-level requests, all through the same host.
# .databrickscfg
[unified]
host = https://mycompany.databricks.com
account_id = 00000000-0000-0000-0000-000000000000
workspace_id = 1234567890
// Both clients share the same host and profile
w, _ := databricks.NewWorkspaceClient(&databricks.Config{Profile: "unified"})
a, _ := databricks.NewAccountClient(&databricks.Config{Profile: "unified"})
// A WorkspaceClient for a different workspace under the same host and account
w, _ = databricks.NewWorkspaceClient(&databricks.Config{
Profile: "unified",
WorkspaceID: "2345678901",
})
If the host supports it, AccountID and WorkspaceID may be auto-discovered, reducing the required explicit configuration.
Databricks native authentication
By default, the Databricks SDK for Go initially tries Databricks token authentication (AuthType: "pat" in *databricks.Config). If the SDK is unsuccessful, it then tries Workload Identity Federation (WIF). See Supported WIF for the supported JWT token providers.
- For Databricks token authentication, you must provide
HostandToken; or their environment variable or.databrickscfgfile field equivalents. - For Databricks OIDC authentication, you must provide the
Host,ClientIdandTokenAudience(optional) either directly, through the corresponding environment variables, or in your.databrickscfgconfiguration file. More information can be found in Databricks Documentation - For Azure DevOps OIDC authentication, the
TokenAudienceis irrelevant as the audience is always set toapi://AzureADTokenExchange. Also, theSystem.AccessTokenpipeline variable required for OIDC request must be exposed as theSYSTEM_ACCESSTOKENenvironment variable, following Pipeline variables
During initialization, the SDK automatically resolves missing configuration fields (AccountID, WorkspaceID, Cloud, and DiscoveryURL). Any explicitly provided values take precedence and are never overwritten. If the auto discovery fails, the SDK falls back to the explicit configuration. It is recommended to always set explicit configuration.
*databricks.Config argument |
Description | Environment variable / .databrickscfg file field |
|---|---|---|
Host |
(String) The Databricks host URL for either the Databricks workspace endpoint or the Databricks accounts endpoint. | DATABRICKS_HOST / host |
AccountID |
(String) The Databricks account ID for the Databricks accounts endpoint. Auto-discovered if not provided. Has effect on hosts that serve account-level APIs. | DATABRICKS_ACCOUNT_ID / account_id |
WorkspaceID |
(String) The Databricks workspace ID for the Databricks workspace endpoint. Auto-discovered if not provided. | DATABRICKS_WORKSPACE_ID / workspace_id |
Cloud |
(String) The cloud provider for the Databricks workspace (AWS, Azure, or GCP). Auto-discovered if not provided. When set, IsAws, IsAzure, and IsGcp use this value directly instead of inferring from hostname. |
DATABRICKS_CLOUD / cloud |
DiscoveryURL |
(String) The OpenID Connect discovery URL. Auto-discovered if not provided. When set, OIDC endpoints are fetched directly from this URL instead of using the default host-based well-known endpoint logic. | DATABRICKS_DISCOVERY_URL / discovery_url |
Token |
(String) The Databricks personal access token (PAT) (AWS, Azure, and GCP) or Azure Active Directory (Azure AD) token (Azure). | DATABRICKS_TOKEN / token |
TokenAudience |
(String) When using Workload Identity Federation, the audience to specify when fetching an ID token from the ID token supplier. |