saurabh18cs
Honored Contributor III

# Using Databricks CLI profile to access the workspace.
w = WorkspaceClient(profile="<<profilename>>")

OR

w = WorkspaceClient(
            host=databricks_host,
            client_id=app_id,
            client_secret=app_secret,
            auth_type="azure-cli",
        )
 
OR 
from azure.identity import ClientSecretCredential
credential = ClientSecretCredential(
    tenant_id="<tenant-id>",
    client_id="<client-id>",
    client_secret="<client-secret>"
)

# Get the access token for Databricks
token = credential.get_token("https://databricks.azure.net/.default").token

# Initialize the WorkspaceClient using the service principal token
client = WorkspaceClient(
    host="https://<databricks-instance>",
    token=token
)
 
OR 
 
# Initialize the WorkspaceClient using an OAuth token
w = WorkspaceClient(
    host="https://<databricks-instance>",
    token="<oauth-token>"
)
 
OR
w = WorkspaceClient(
        host=databricks_host,
        token=pat_token,
    )