Base data classes

CogniteResource

class cognite.client.data_classes._base.CogniteResource

A CogniteResource represent a resource in the Cognite API, meaning that there should be a set of endpoints that can be used to interact with the resource.

to_pandas(expand_metadata: bool = False, metadata_prefix: str = 'metadata.', ignore: list[str] | None = None, camel_case: bool = False, convert_timestamps: bool = True) pandas.DataFrame

Convert the instance into a pandas DataFrame.

Parameters
  • expand_metadata (bool) – Expand the metadata into separate rows (default: False).

  • metadata_prefix (str) – Prefix to use for the metadata rows, if expanded.

  • ignore (list[str] | None) – List of row keys to skip when converting to a data frame. Is applied before expansions.

  • camel_case (bool) – Convert attribute names to camel case (e.g. externalId instead of external_id). Does not affect custom data like metadata if expanded.

  • convert_timestamps (bool) – Convert known attributes storing CDF timestamps (milliseconds since epoch) to datetime. Does not affect custom data like metadata.

Returns

The dataframe.

Return type

pandas.DataFrame

CogniteResourceList

class cognite.client.data_classes._base.CogniteResourceList(resources: Iterable[Any], cognite_client: CogniteClient | None = None)
dump(camel_case: bool = True) list[dict[str, Any]]

Dump the instance into a json serializable Python data type.

Parameters

camel_case (bool) – Use camelCase for attribute names. Defaults to True.

Returns

A list of dicts representing the instance.

Return type

list[dict[str, Any]]

dump_raw(camel_case: bool = True) dict[str, Any]

This method dumps the list with extra information in addition to the items.

Parameters

camel_case (bool) – Use camelCase for attribute names. Defaults to True.

Returns

A dictionary representation of the list.

Return type

dict[str, Any]

dump_yaml() str

Dump the instances into a YAML formatted string.

Returns

A YAML formatted string representing the instances.

Return type

str

extend(other: Iterable[Any]) None

S.extend(iterable) – extend sequence by appending elements from the iterable

get(id: Optional[int] = None, external_id: Optional[str] = None, instance_id: Optional[Union[InstanceId, tuple[str, str]]] = None) Optional[T_CogniteResource]

Get an item from this list by id, external_id or instance_id.

Parameters
  • id (int | None) – The id of the item to get.

  • external_id (str | None) – The external_id of the item to get.

  • instance_id (InstanceId | tuple[str, str] | None) – The instance_id of the item to get.

Returns

The requested item if present, otherwise None.

Return type

T_CogniteResource | None

final classmethod load(resource: Iterable[dict[str, Any]] | str, cognite_client: CogniteClient | None = None) Self

Load a resource from a YAML/JSON string or iterable of dict.

pop([index]) item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

to_pandas(camel_case: bool = False, expand_metadata: bool = False, metadata_prefix: str = 'metadata.', convert_timestamps: bool = True) pandas.DataFrame

Convert the instance into a pandas DataFrame. Note that if the metadata column is expanded and there are keys in the metadata that already exist in the DataFrame, then an error will be raised by pd.join.

Parameters
  • camel_case (bool) – Convert column names to camel case (e.g. externalId instead of external_id)

  • expand_metadata (bool) – Expand the metadata column into separate columns.

  • metadata_prefix (str) – Prefix to use for metadata columns.

  • convert_timestamps (bool) – Convert known columns storing CDF timestamps (milliseconds since epoch) to datetime. Does not affect custom data like metadata.

Returns

The Cognite resource as a dataframe.

Return type

pandas.DataFrame

CogniteResponse

class cognite.client.data_classes._base.CogniteResponse
dump(camel_case: bool = True) dict[str, Any]

Dump the instance into a json serializable Python data type.

Parameters

camel_case (bool) – Use camelCase for attribute names. Defaults to True.

Returns

A dictionary representation of the instance.

Return type

dict[str, Any]

CogniteFilter

class cognite.client.data_classes._base.CogniteFilter
dump(camel_case: bool = True) dict[str, Any]

Dump the instance into a json serializable Python data type.

Parameters

camel_case (bool) – Use camelCase for attribute names. Defaults to True.

Returns

A dictionary representation of the instance.

Return type

dict[str, Any]

CogniteUpdate

class cognite.client.data_classes._base.CogniteUpdate(id: Optional[int] = None, external_id: Optional[str] = None)
dump(camel_case: Literal[True] = True) dict[str, Any]

Dump the instance into a json serializable Python data type.

Parameters

camel_case (Literal[True]) – No description.

Returns

A dictionary representation of the instance.

Return type

dict[str, Any]