Create a relationship
- async AsyncCogniteClient.relationships.create(
- relationship: Relationship | RelationshipWrite | Sequence[Relationship | RelationshipWrite],
Create one or more relationships.
Deprecated since version 8.23.0: The Relationships API is deprecated and is scheduled for removal on 2027-12-31. Model connections as edges or direct relations in the data modeling service. See https://docs.cognite.com/cdf/deprecated for details and migration guidance.
- Parameters:
relationship (Relationship | RelationshipWrite | Sequence[Relationship | RelationshipWrite]) – Relationship or list of relationships to create.
- Returns:
Created relationship(s)
- Return type:
Note
The source_type and target_type field in the Relationship(s) can be any string among “Asset”, “TimeSeries”, “File”, “Event”, “Sequence”.
Do not provide the value for the source and target arguments of the Relationship class, only source_external_id / source_type and target_external_id / target_type. These (source and target) are used as part of fetching actual resources specified in other fields.
Examples
Create a new relationship specifying object type and external id for source and target:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import RelationshipWrite >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> flowrel1 = RelationshipWrite( ... external_id="flow_1", ... source_external_id="source_ext_id", ... source_type="asset", ... target_external_id="target_ext_id", ... target_type="event", ... confidence=0.1, ... data_set_id=1234, ... ) >>> flowrel2 = RelationshipWrite( ... external_id="flow_2", ... source_external_id="source_ext_id", ... source_type="asset", ... target_external_id="target_ext_id", ... target_type="event", ... confidence=0.1, ... data_set_id=1234, ... ) >>> res = client.relationships.create([flowrel1, flowrel2])