Skip to main content

ConnectionsClient

Client for managing DataConnection objects in the Datagrok platform. The ConnectionsClient provides methods to create, retrieve, update, delete, list, and test data connections via the Datagrok REST API. A data connection represents configuration details needed to connect to an external data source, including authentication parameters. This client wraps calls to /public/v1/connections endpoints and handles serialization/deserialization of DataConnection objects.

Examples

Get connection by Grok Name

>>> from datagrok_api import DatagrokClient
>>> from datagrok_api.models import DataConnection, Credentials, DatabaseDataSourceType
>>> grok = DatagrokClient(base_url="https://public.datagrok.ai/api", api_key="Bearer <your-token>")
>>> conn = grok.connections.get("JohnDoe:MyConnection")
>>> print(conn.name)

MyConnection

Create, save and test DataConnection

>>> shop_connection = DataConnection(name="TestConn", data_source=DatabaseDataSourceType.Postgres, description="Test conn", server="localhost",
... port=5432, db="shopdb", credentials=Credentials(login="***", password="***"))
>>> shop_connection_saved = grok.connections.save(shop_connection, save_credentials=True)
>>> grok.connections.test(shop_connection_saved)

Get all CLickHouse connections

>>> click_house_conns = grok.connections.list(smart_filter="dataSource='ClickHouse'")

Methods

__init__()

get()

Get DataConnection object by id or Grok Name.

Parameters

NameTypeDescription
connstrID or Grok Name of the connection to retrieve

Returns

TypeDescription
UserDataConnection instance with detailed information

save()

Save a data connection to the backend.

Parameters

NameTypeDescription
connDataConnectionThe data connection object to save.
save_credentialsbool, optionalWhether to save the credentials associated with the connection, by default False.

Returns

TypeDescription
DataConnectionThe saved data connection returned from the backend, potentially with updated fields.

delete()

Delete a data connection by object or ID or Grok Name.

Parameters

NameTypeDescription
connDataConnection or strThe data connection object or connection ID or Grok Name to delete. Raises Exception Raises if the HTTP delete request fails.

list()

List data connections with optional filters.

Parameters

NameTypeDescription
smart_filterstr, optionalText filter to search connection names or descriptions, by default None.
data_sourceDataSourceType, optionalFilter connections by data source type, by default None.
tagslist of str, optionalFilter connections by associated tags, by default None.

Returns

TypeDescription
list of DataConnectionA list of data connections matching the provided filters.

test()

Test if a data connection is available.

Parameters

NameTypeDescription
connDataConnectionThe data connection object to test. Raises Exception If the connection can't be tested or test fails or the backend returns an error.