w.connections: Connections

class databricks.sdk.service.catalog.ConnectionsAPI

Connections allow for creating a connection to an external data source.

A connection is an abstraction of an external data source that can be connected from Databricks Compute. Creating a connection object is the first step to managing external data sources within Unity Catalog, with the second step being creating a data object (catalog, schema, or table) using the connection. Data objects derived from a connection can be written to or read from similar to other Unity Catalog data objects based on cloud storage. Users may create different types of connections with each connection having a unique set of configuration options to support credential management and other settings.

create(name: str, connection_type: ConnectionType, options: Dict[str, str] [, comment: Optional[str], properties: Optional[Dict[str, str]], read_only: Optional[bool]]) ConnectionInfo

Usage:

import time

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import catalog

w = WorkspaceClient()

conn_create = w.connections.create(
    comment="Go SDK Acceptance Test Connection",
    connection_type=catalog.ConnectionType.DATABRICKS,
    name=f"sdk-{time.time_ns()}",
    options={
        "host": "%s-fake-workspace.cloud.databricks.com" % (f"sdk-{time.time_ns()}"),
        "httpPath": "/sql/1.0/warehouses/%s" % (f"sdk-{time.time_ns()}"),
        "personalAccessToken": f"sdk-{time.time_ns()}",
    },
)

# cleanup
w.connections.delete(name=conn_create.name)

Create a connection.

Creates a new connection

Creates a new connection to an external data source. It allows users to specify connection details and configurations for interaction with the external server.

Parameters:
  • name – str Name of the connection.

  • connection_typeConnectionType The type of connection.

  • options – Dict[str,str] A map of key-value properties attached to the securable.

  • comment – str (optional) User-provided free-form text description.

  • properties – Dict[str,str] (optional) An object containing map of key-value properties attached to the connection.

  • read_only – bool (optional) If the connection is read only.

Returns:

ConnectionInfo

delete(name: str)

Delete a connection.

Deletes the connection that matches the supplied name.

Parameters:

name – str The name of the connection to be deleted.

get(name: str) ConnectionInfo

Usage:

import time

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import catalog

w = WorkspaceClient()

conn_create = w.connections.create(
    comment="Go SDK Acceptance Test Connection",
    connection_type=catalog.ConnectionType.DATABRICKS,
    name=f"sdk-{time.time_ns()}",
    options={
        "host": "%s-fake-workspace.cloud.databricks.com" % (f"sdk-{time.time_ns()}"),
        "httpPath": "/sql/1.0/warehouses/%s" % (f"sdk-{time.time_ns()}"),
        "personalAccessToken": f"sdk-{time.time_ns()}",
    },
)

conn_update = w.connections.update(
    name=conn_create.name,
    options={
        "host": "%s-fake-workspace.cloud.databricks.com" % (f"sdk-{time.time_ns()}"),
        "httpPath": "/sql/1.0/warehouses/%s" % (f"sdk-{time.time_ns()}"),
        "personalAccessToken": f"sdk-{time.time_ns()}",
    },
)

conn = w.connections.get(name=conn_update.name)

# cleanup
w.connections.delete(name=conn_create.name)

Get a connection.

Gets a connection from it’s name.

Parameters:

name – str Name of the connection.

Returns:

ConnectionInfo

list([, max_results: Optional[int], page_token: Optional[str]]) Iterator[ConnectionInfo]

Usage:

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import catalog

w = WorkspaceClient()

conn_list = w.connections.list(catalog.ListConnectionsRequest())

List connections.

List all connections.

Parameters:
  • max_results – int (optional) Maximum number of connections to return. - If not set, all connections are returned (not recommended). - when set to a value greater than 0, the page length is the minimum of this value and a server configured value; - when set to 0, the page length is set to a server configured value (recommended); - when set to a value less than 0, an invalid parameter error is returned;

  • page_token – str (optional) Opaque pagination token to go to next page based on previous query.

Returns:

Iterator over ConnectionInfo

update(name: str, options: Dict[str, str] [, new_name: Optional[str], owner: Optional[str]]) ConnectionInfo

Usage:

import time

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import catalog

w = WorkspaceClient()

conn_create = w.connections.create(
    comment="Go SDK Acceptance Test Connection",
    connection_type=catalog.ConnectionType.DATABRICKS,
    name=f"sdk-{time.time_ns()}",
    options={
        "host": "%s-fake-workspace.cloud.databricks.com" % (f"sdk-{time.time_ns()}"),
        "httpPath": "/sql/1.0/warehouses/%s" % (f"sdk-{time.time_ns()}"),
        "personalAccessToken": f"sdk-{time.time_ns()}",
    },
)

conn_update = w.connections.update(
    name=conn_create.name,
    options={
        "host": "%s-fake-workspace.cloud.databricks.com" % (f"sdk-{time.time_ns()}"),
        "httpPath": "/sql/1.0/warehouses/%s" % (f"sdk-{time.time_ns()}"),
        "personalAccessToken": f"sdk-{time.time_ns()}",
    },
)

# cleanup
w.connections.delete(name=conn_create.name)

Update a connection.

Updates the connection that matches the supplied name.

Parameters:
  • name – str Name of the connection.

  • options – Dict[str,str] A map of key-value properties attached to the securable.

  • new_name – str (optional) New name for the connection.

  • owner – str (optional) Username of current owner of the connection.

Returns:

ConnectionInfo