Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Databricks SDKs for JavaScript is in Beta. During Beta, Databricks recommends that you pin a dependency on the specific version of each Databricks SDKs for JavaScript package that your code depends on, for example in a project's package.json file.
Report issues in the Databricks SDKs for JavaScript repository in GitHub.
Automate Azure Databricks operations and accelerate development with the Databricks SDKs for JavaScript. These SDKs provide typed clients for the Databricks REST API. They have a modular architecture, with a separate npm package for each API (for example, @databricks/sdk-postgres). Install only the packages for the APIs that you use.
This page supplements the Databricks SDKs for JavaScript README and examples.
Requirements
To use the Databricks SDKs for JavaScript, your development machine must have:
- Node.js and npm installed.
- Azure Databricks authentication configured.
Get started
Install the package for each API that you need. Each Databricks API is published as a separate package named
@databricks/sdk-<api>. For example, to work with Postgres, run the following command from the root of your Node.js project:npm install @databricks/sdk-postgresIf it isn't already configured, set up your development machine for Azure Databricks authentication.
Import the client from the package's versioned subpath, and then call the API. The following TypeScript example lists your Postgres projects, using the default authentication described in Authenticate. List methods expose an
Itervariant that pages through results transparently as you iterate:import { PostgresClient } from '@databricks/sdk-postgres/v1'; const client = new PostgresClient({}); for await (const project of client.listProjectsIter({})) { console.log(project.name); }
For more runnable examples, including pagination, long-running operations, error handling, and authentication strategies, see the examples folder in the Databricks SDKs for JavaScript repository in GitHub.
Authenticate
By default, a client reads its configuration, including the host and credentials, from a Databricks configuration profile (~/.databrickscfg) and DATABRICKS_* environment variables. With those set, you do not need to pass any credentials in code, so for example:
import { PostgresClient } from '@databricks/sdk-postgres/v1';
// Resolves the host and credentials from the DEFAULT profile and DATABRICKS_* environment variables.
const client = new PostgresClient({});
To configure credentials explicitly, import a helper from @databricks/sdk-auth/credentials and pass it as credentials. The following example configures Databricks personal access token authentication.
import { PostgresClient } from '@databricks/sdk-postgres/v1';
import { newPatCredentials } from '@databricks/sdk-auth/credentials';
const client = new PostgresClient({
host: 'https://my-company.databricks.com',
credentials: newPatCredentials(MY_PAT_ENV_VAR),
});
The @databricks/sdk-auth package provides additional credential providers, including newU2mCredentials for user-to-machine (U2M) OAuth and newM2mCredentials for machine-to-machine (M2M) OAuth, as well as the default credential chain. For more information about Azure Databricks authentication, see Databricks unified authentication.
Packages
Each Databricks API is published as a separate package named @databricks/sdk-<api>. Import its client from the package's versioned subpath. For example, @databricks/sdk-postgres/v1 exports PostgresClient.
For the full list of available API packages, see Packages in the Databricks SDKs for JavaScript README.
Shared packages
Three packages are shared by every API client and provide pieces that you import directly:
| Package | Description |
|---|---|
@databricks/sdk-core |
The HTTP client, configuration-profile resolution, logging, and API error types (ApiError). |
@databricks/sdk-auth |
Credential providers (newPatCredentials, newU2mCredentials, newM2mCredentials) and the default credential chain. |
@databricks/sdk-options |
The option types passed to clients and calls (ClientOptions, CallOptions). |
Additional resources
- Databricks SDKs for JavaScript README
- Databricks SDKs for JavaScript examples
- Databricks unified authentication