Connections#
A connection is an object that is used to store connection related data for a single datasource (Kafka, Azure, etc.) like credentials, secrets and urls. Each connection is defined for exactly one datasource.
Tip
To read more about datasources see Retrieving an DatasourceType.
The SDK provides functionality to interact with connections.
- This includes operations such as:
Creating a connection
Retrieving connection(s)
Updating a connection
Deleting a connection
Creating a Connection#
In the UI, you can create a new Connection by navigating to Assets -> New asset -> Connect to a datasource.


You will need to choose the desired datasource from the list

and provide a Name and other additional configuration (depending on the selected datasource).

In the SDK, you can create a new Connection
object within a
Project
,
by selecting the appropriate project from the Platform
and then using
the Project.create_connection()
method to instantiate the connection.
You must provide a name
and datasource
type to create connection.
DatasourceType
is an object defining the data source for which the connection will be created.
By default before creating any connection, server will validate it.
If the connection cannot be estabilished with provided parameters, you will get an error and connection will not be saved.
To skip validation and create connection anyway set test
parameter of
Project.create_connection()
to False
.
Note
To get available datasources see: Retrieving a DatasourceType.
>>> project = platform.projects.get(name="project")
Project(guid='d7831458-4771-4ad4-bb05-fb95fa94361c', name='project')
>>> datasource_type = platform.datasources[28]
DatasourceType(name='http')
>>> connection = project.create_connection(
... name="Connection Name",
... datasource_type=datasource_type,
... description="Description ...",
... properties={"url": "https://my/connection/url"},
... )
Connection(name='Connection Name')
Important
Each datasource_type defines its own set of required properties.
To get list of available properties see: Retrieving a DatasourceType connection properties.
Retrieving an Existing Connection#
In the UI, you can get all Connections by navigating to Assets -> Data access -> Connections.

In the SDK, Connection can be retrieved using Project.connections
property.
You can also further filter and refine the connections returned based on attributes including
name
, context
, properties
and datasource_type
.
This property returns a Connections
object.
>>> # Returns the first connection matching given `name`
>>> connection = project.connections.get(name="Connection Name")
Connection(name='Connection Name')
>>> # Return a list of all connections that match `properties`
>>> connections = project.connections.get_all(
... properties={"url": "https://my/connection/url"}
... )
[Connection(name='Connection Name')]
>>> # Return a list of all connections
>>> connections = project.connections
[Connection(name='Connection Name'), (...)]
Tip
For detailed information about parameters and values refer to https://cloud.ibm.com/apidocs/data-ai-common-core#listconnections.
Updating a Connection#
In the UI, you can update a Connection by navigating to Assets -> Data access -> Connections and clicking the edit button on the Connection you want to edit. This button is visible only when cursor is over the Connection object.

To update a connection in the SDK, we first modify properties of the connection and then
pass the instance to the Project.update_connection()
method.
This method returns an HTTP response indicating the status of the update operation.
Similar to Creating a Connection you can skip the validation by setting test
parameter of
Project.update_connection()
to False
.
>>> connection = project.connections.get(name="Connection Name")
Connection(name='Connection Name')
>>> connection.name = "New Connection Name"
>>> res = project.update_connection(connection)
<Response [200]>
Deleting a Connection#
In the UI, you can delete an existing Connection by navigating to the Assets -> Data access -> Connections.

In the SDK to delete a connection instance you can pass it to Project.delete_connection()
method.
This method returns an HTTP response indicating the status of the delete operation.
>>> connection = project.connections.get(name="New Connection Name")
Connection(name='New Connection Name')
>>> res = project.delete_connection(connection)
<Response [204]>