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
| Name | Type | Description |
|---|---|---|
| conn | str | ID or Grok Name of the connection to retrieve |
Returns
| Type | Description |
|---|---|
| User | DataConnection instance with detailed information |
save()
Save a data connection to the backend.
Parameters
| Name | Type | Description |
|---|---|---|
| conn | DataConnection | The data connection object to save. |
| save_credentials | bool, optional | Whether to save the credentials associated with the connection, by default False. |
Returns
| Type | Description |
|---|---|
| DataConnection | The saved data connection returned from the backend, potentially with updated fields. |
delete()
Delete a data connection by object or ID or Grok Name.
Parameters
| Name | Type | Description |
|---|---|---|
| conn | DataConnection or str | The 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
| Name | Type | Description |
|---|---|---|
| smart_filter | str, optional | Text filter to search connection names or descriptions, by default None. |
| data_source | DataSourceType, optional | Filter connections by data source type, by default None. |
| tags | list of str, optional | Filter connections by associated tags, by default None. |
Returns
| Type | Description |
|---|---|
| list of DataConnection | A list of data connections matching the provided filters. |
test()
Test if a data connection is available.
Parameters
| Name | Type | Description |
|---|---|---|
| conn | DataConnection | The data connection object to test. Raises Exception If the connection can't be tested or test fails or the backend returns an error. |