w.connections: Connections¶
- class databricks.sdk.service.catalog.ConnectionsAPI¶
A connection represents an external data source for use within Databricks.
Creating a connection object is the first step to managing external data sources within Unity Catalog. The second step is 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. You can create different types of connections, and each connection has 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], environment_settings: Optional[EnvironmentSettings], parent: Optional[str], properties: Optional[Dict[str, str]], read_only: Optional[bool], secrets: Optional[Dict[str, 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()}", }, ) # cleanup w.connections.delete(name=conn_create.name)
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_type –
ConnectionTypeThe type of external data source or service that the connection reaches. The connection type determines which keys are required in options and cannot be changed after creation.options – Dict[str,str] A map of key-value properties attached to the securable.
comment – str (optional) User-provided free-form text description.
environment_settings –
EnvironmentSettings(optional) Environment settings for the connection, such as the Java libraries that it needs and the environment version.parent – str (optional) Parent schema for schema-level connections, in format “schemas/{catalog}.{schema}”. Absent for metastore-level (L1) connections.
properties – Dict[str,str] (optional) A map of key-value properties attached to the securable.
read_only – bool (optional) Whether the connection is read only. All connections are currently read only, so a value set on create or update is ignored.
secrets – Dict[str,str] (optional) A map of option names to UC Secret references. Keys are connection option names (same as in OptionsKVPairs) and values are UC Secret fully qualified names.
- Returns:
- delete(name: str)¶
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)
Gets a connection from its name.
- Parameters:
name – str Name of the connection.
- Returns:
- list([, max_results: Optional[int], page_token: Optional[str], parent: 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 all connections.
NOTE: we recommend using max_results=0 to use the paginated version of this API. Unpaginated calls will be deprecated soon.
PAGINATION BEHAVIOR: When using pagination (max_results >= 0), a page may contain zero results while still providing a next_page_token. Clients must continue reading pages until next_page_token is absent, which is the only indication that the end of results has been reached.
- 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.
parent – str (optional) Optional. Parent schema filter for listing schema-level connections, in format “schemas/{catalog}.{schema}”.
- Returns:
Iterator over
ConnectionInfo
- update(name: str, options: Dict[str, str] [, environment_settings: Optional[EnvironmentSettings], new_name: Optional[str], owner: Optional[str], secrets: Optional[Dict[str, 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)
Updates the connection that matches the supplied name. When options are provided, they replace the existing options of the connection, so include every key that the connection type requires.
- Parameters:
name – str Name of the connection.
options – Dict[str,str] A map of key-value properties attached to the securable.
environment_settings –
EnvironmentSettings(optional) Environment settings for the connection, such as the Java libraries that it needs and the environment version.new_name – str (optional) New name for the connection.
owner – str (optional) Username of the current owner of the connection. The creator becomes the owner at creation, and ownership can be transferred on update.
secrets – Dict[str,str] (optional) A map of option names to UC Secret references. Keys are connection option names (same as in OptionsKVPairs) and values are UC Secret fully qualified names.
- Returns: