workbench.external.databricks

workbench.external.databricks

Databricks SDK integration.

Databricks SDK credentials implementations which support interacting with Posit Workbench-managed Databricks credentials.

Notes

These APIs are provided as a convenience and are subject to breaking changes: https://github.com/databricks/databricks-sdk-py#interface-stability

Attributes

Name Description
POSIT_WORKBENCH_AUTH_TYPE

Classes

Name Description
WorkbenchStrategy CredentialsStrategy implementation which uses a bearer token authentication provider for Workbench environments.

WorkbenchStrategy

workbench.external.databricks.WorkbenchStrategy(config=None)

CredentialsStrategy implementation which uses a bearer token authentication provider for Workbench environments.

This strategy can be used as a valid credentials_strategy when constructing a databricks.sdk.core.Config.

It should be used when content running on a Posit Workbench server needs to access a Databricks token that is manged by Posit Workbench-managed Databricks Credentials. If you need to author content that can run in multiple environments (local content, Posit Workbench, and Posit Connect), consider using the posit.connect.external.databricks.databricks_config() helper method.

See Also

  • https://docs.posit.co/ide/server-pro/user/posit-workbench/guide/databricks.html#databricks-with-python

Examples

This example shows how authenticate to Databricks using Posit Workbench-managed Databricks Credentials.

import os

from databricks.sdk.core import ApiClient, Config
from databricks.sdk.service.iam import CurrentUserAPI
from shiny import reactive
from shiny.express import render

from posit.workbench.external.databricks import WorkbenchStrategy


@reactive.calc
def cfg():
    return Config(
        credentials_strategy=WorkbenchStrategy(),
        host=os.getenv("DATABRICKS_HOST"),
    )


@render.text
def text():
    current_user_api = CurrentUserAPI(ApiClient(cfg()))
    databricks_user_info = current_user_api.me()
    return f"Hello, {databricks_user_info.display_name}!"

Methods

Name Description
auth_type
auth_type
workbench.external.databricks.WorkbenchStrategy.auth_type()