Retrieve Nodes by id(s)
- async AsyncCogniteClient.data_modeling.instances.retrieve_nodes(nodes: ~cognite.client.data_classes.data_modeling.ids.NodeId | ~collections.abc.Sequence[~cognite.client.data_classes.data_modeling.ids.NodeId] | tuple[str, str] | ~collections.abc.Sequence[tuple[str, str]], node_cls: type[~cognite.client.data_classes.data_modeling.instances.T_Node] = <class 'cognite.client.data_classes.data_modeling.instances.Node'>, 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) NodeList[T_Node] | T_Node | Node | None
Retrieve one or more nodes by id(s).
Note
This method should be used for retrieving nodes with a custom node class. You can use it without providing a custom node class, but in that case, the retrieved nodes will be of the built-in Node class.
- Parameters:
nodes (NodeId | Sequence[NodeId] | tuple[str, str] | Sequence[tuple[str, str]]) – Node id(s) to retrieve.
node_cls (type[T_Node]) – The custom node class to use, the retrieved nodes will automatically be serialized to 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 node class.
include_typing (bool) – Whether to include typing information
- Returns:
The requested edges.
- Return type:
Examples
Retrieve nodes using a custom typed node class “Person”. Any property that you want to look up by a different attribute name, e.g. you want my_node.birth_year to return the data for property birthYear, 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 ( ... NodeId, ... TypedNode, ... PropertyOptions, ... DirectRelationReference, ... ViewId, ... ) >>> class Person(TypedNode): ... birth_year = PropertyOptions(identifier="birthYear") ... ... def __init__( ... self, ... space: str, ... external_id: str, ... version: int, ... last_updated_time: int, ... created_time: int, ... name: str, ... birth_year: int | None = None, ... type: DirectRelationReference | None = None, ... deleted_time: int | None = None, ... ): ... super().__init__( ... space=space, ... external_id=external_id, ... version=version, ... last_updated_time=last_updated_time, ... created_time=created_time, ... type=type, ... deleted_time=deleted_time, ... ) ... self.name = name ... self.birth_year = birth_year ... ... @classmethod ... def get_source(cls) -> ViewId: ... return ViewId("myModelSpace", "Person", "1") >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> res = client.data_modeling.instances.retrieve_nodes( ... NodeId("myDataSpace", "myPerson"), node_cls=Person ... ) >>> isinstance(res, Person)