Retrieve Edges by id(s)

async AsyncCogniteClient.data_modeling.instances.retrieve_edges(edges: ~cognite.client.data_classes.data_modeling.ids.EdgeId | ~collections.abc.Sequence[~cognite.client.data_classes.data_modeling.ids.EdgeId] | tuple[str, str] | ~collections.abc.Sequence[tuple[str, str]], edge_cls: type[~cognite.client.data_classes.data_modeling.instances.T_Edge] = <class 'cognite.client.data_classes.data_modeling.instances.Edge'>, sources: ~cognite.client.data_classes.data_modeling.query.SourceSelector | ~cognite.client.data_classes.data_modeling.views.View | ~cognite.client.data_classes.data_modeling.ids.ViewId | tuple[str, str] | tuple[str, str, str] | ~collections.abc.Sequence[~cognite.client.data_classes.data_modeling.query.SourceSelector | ~cognite.client.data_classes.data_modeling.views.View | ~cognite.client.data_classes.data_modeling.ids.ViewId | tuple[str, str] | tuple[str, str, str]] | None = None, include_typing: bool = False) EdgeList[T_Edge] | T_Edge | Edge | None

Retrieve one or more edges by id(s).

Note

This method should be used for retrieving edges with a custom edge class. You can use it without providing a custom edge class, but in that case, the retrieved edges will be of the built-in Edge class.

Parameters:
  • edges (EdgeId | Sequence[EdgeId] | tuple[str, str] | Sequence[tuple[str, str]]) – Edge id(s) to retrieve.

  • edge_cls (type[T_Edge]) – The custom edge class to use, the retrieved edges will automatically be serialized into this class.

  • sources (Source | Sequence[Source] | None) – Retrieve properties from the listed - by reference - views. This only applies if you do not provide a custom edge class.

  • include_typing (bool) – Whether to include typing information

Returns:

The requested edges.

Return type:

EdgeList[T_Edge] | T_Edge | Edge | None

Examples

Retrieve edges using a custom typed class “Flow”. Any property that you want to look up by a different attribute name, e.g. you want my_edge.flow_rate to return the data for property flowRate, must use the PropertyOptions as shown below. We strongly suggest you use snake_cased attribute names, as is done here:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes.data_modeling import (
...     EdgeId,
...     TypedEdge,
...     PropertyOptions,
...     DirectRelationReference,
...     ViewId,
... )
>>> class Flow(TypedEdge):
...     flow_rate = PropertyOptions(identifier="flowRate")
...
...     def __init__(
...         self,
...         space: str,
...         external_id: str,
...         version: int,
...         type: DirectRelationReference,
...         last_updated_time: int,
...         created_time: int,
...         flow_rate: float,
...         start_node: DirectRelationReference,
...         end_node: DirectRelationReference,
...         deleted_time: int | None = None,
...     ) -> None:
...         super().__init__(
...             space,
...             external_id,
...             version,
...             type,
...             last_updated_time,
...             created_time,
...             start_node,
...             end_node,
...             deleted_time,
...         )
...         self.flow_rate = flow_rate
...
...     @classmethod
...     def get_source(cls) -> ViewId:
...         return ViewId("sp_model_space", "flow", "1")
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient()  # another option
>>> res = client.data_modeling.instances.retrieve_edges(
...     EdgeId("mySpace", "theFlow"), edge_cls=Flow
... )
>>> isinstance(res, Flow)