Assets (legacy)
|
|
Create an asset hierarchy with validation. |
|
|
|
|
|
|
|
Retrieve the subtree for this asset up to a specified depth. |
|
|
|
|
|
|
Upsert assets, i.e., update if it exists, and create if it does not exist. |
Asset Data classes
- class cognite.client.data_classes.assets.AggregateResultItem(
- child_count: int | None = None,
- depth: int | None = None,
- path: list[dict[str, Any]] | None = None,
- **_: Any,
Bases:
CogniteResourceAggregated metrics of the asset
- Parameters:
child_count (int | None) – Number of direct descendants for the asset
depth (int | None) – Asset path depth (number of levels below root node).
path (list[dict[str, Any]] | None) – IDs of assets on the path to the asset.
**_ (Any) – No description.
- class cognite.client.data_classes.assets.Asset(
- id: int,
- created_time: int,
- last_updated_time: int,
- root_id: int,
- name: str,
- external_id: str | None = None,
- parent_id: int | None = None,
- parent_external_id: str | None = None,
- description: str | None = None,
- data_set_id: int | None = None,
- metadata: dict[str, str] | None = None,
- source: str | None = None,
- labels: list[Label] | None = None,
- geo_location: GeoLocation | None = None,
- aggregates: AggregateResultItem | None = None,
Bases:
WriteableCogniteResourceWithClientRef[AssetWrite]A representation of a physical asset, for example, a factory or a piece of equipment. This is the read version of the Asset class, it is used when retrieving assets from the Cognite API.
- Parameters:
id (int) – A server-generated ID for the object.
created_time (int) – The number of milliseconds since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC), minus leap seconds.
last_updated_time (int) – The number of milliseconds since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC), minus leap seconds.
root_id (int) – ID of the root asset.
name (str) – The name of the asset.
external_id (str | None) – The external ID provided by the client. Must be unique for the resource type.
parent_id (int | None) – The parent of the node, null if it is the root node.
parent_external_id (str | None) – The external ID of the parent. The property is omitted if the asset doesn’t have a parent or if the parent doesn’t have externalId.
description (str | None) – The description of the asset.
data_set_id (int | None) – The id of the dataset this asset belongs to.
metadata (dict[str, str] | None) – Custom, application-specific metadata. String key -> String value. Limits: Maximum length of key is 128 bytes, value 10240 bytes, up to 256 key-value pairs, of total size at most 10240.
source (str | None) – The source of the asset.
labels (list[Label] | None) – A list of the labels associated with this resource item.
geo_location (GeoLocation | None) – The geographic metadata of the asset.
aggregates (AggregateResultItem | None) – Aggregated metrics of the asset
- as_write() AssetWrite
Returns this Asset in its write version.
- children() AssetList
Returns the children of this asset.
- Returns:
The requested assets
- Return type:
- async children_async() AssetList
Returns the children of this asset.
- Returns:
The requested assets
- Return type:
- 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]
- events(**kwargs: Any) EventList
Retrieve all events related to this asset.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to events/list.
- Returns:
All events related to this asset.
- Return type:
- async events_async(**kwargs: Any) EventList
Retrieve all events related to this asset.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to events/list.
- Returns:
All events related to this asset.
- Return type:
- files(**kwargs: Any) FileMetadataList
Retrieve all files metadata related to this asset.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to files/list.
- Returns:
Metadata about all files related to this asset.
- Return type:
- async files_async(**kwargs: Any) FileMetadataList
Retrieve all files metadata related to this asset.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to files/list.
- Returns:
Metadata about all files related to this asset.
- Return type:
- sequences(**kwargs: Any) SequenceList
Retrieve all sequences related to this asset.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to sequences/list.
- Returns:
All sequences related to this asset.
- Return type:
- async sequences_async(**kwargs: Any) SequenceList
Retrieve all sequences related to this asset.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to sequences/list.
- Returns:
All sequences related to this asset.
- Return type:
- subtree(
- depth: int | None = None,
Returns the subtree of this asset up to a specified depth.
- Parameters:
depth (int | None) – Retrieve assets up to this depth below the asset.
- Returns:
The requested assets sorted topologically.
- Return type:
- async subtree_async(
- depth: int | None = None,
Returns the subtree of this asset up to a specified depth.
- Parameters:
depth (int | None) – Retrieve assets up to this depth below the asset.
- Returns:
The requested assets sorted topologically.
- Return type:
- time_series(**kwargs: Any) TimeSeriesList
Retrieve all time series related to this asset.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to time_series/list.
- Returns:
All time series related to this asset.
- Return type:
- async time_series_async(**kwargs: Any) TimeSeriesList
Retrieve all time series related to this asset.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to time_series/list.
- Returns:
All time series related to this asset.
- Return type:
- to_pandas(
- expand_metadata: bool = False,
- metadata_prefix: str = 'metadata.',
- expand_aggregates: bool = False,
- aggregates_prefix: str = 'aggregates.',
- ignore: list[str] | None = None,
- camel_case: bool = False,
- convert_timestamps: bool = True,
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.
expand_aggregates (bool) – Expand the aggregates into separate rows (default: False).
aggregates_prefix (str) – Prefix to use for the aggregates 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
- class cognite.client.data_classes.assets.AssetFilter(
- name: str | None = None,
- parent_ids: Sequence[int] | None = None,
- parent_external_ids: SequenceNotStr[str] | None = None,
- asset_subtree_ids: Sequence[dict[str, Any]] | None = None,
- data_set_ids: Sequence[dict[str, Any]] | None = None,
- metadata: dict[str, str] | None = None,
- source: str | None = None,
- created_time: dict[str, Any] | TimestampRange | None = None,
- last_updated_time: dict[str, Any] | TimestampRange | None = None,
- root: bool | None = None,
- external_id_prefix: str | None = None,
- labels: LabelFilter | None = None,
- geo_location: GeoLocationFilter | None = None,
Bases:
CogniteFilterFilter on assets with strict matching.
- Parameters:
name (str | None) – The name of the asset.
parent_ids (Sequence[int] | None) – Return only the direct descendants of the specified assets.
parent_external_ids (SequenceNotStr[str] | None) – Return only the direct descendants of the specified assets.
asset_subtree_ids (Sequence[dict[str, Any]] | None) – Only include assets in subtrees rooted at the specified asset IDs and external IDs. If the total size of the given subtrees exceeds 100,000 assets, an error will be returned.
data_set_ids (Sequence[dict[str, Any]] | None) – No description.
metadata (dict[str, str] | None) – Custom, application specific metadata. String key -> String value. Limits: Maximum length of key is 128 bytes, value 10240 bytes, up to 256 key-value pairs, of total size at most 10240.
source (str | None) – The source of the asset.
created_time (dict[str, Any] | TimestampRange | None) – Range between two timestamps.
last_updated_time (dict[str, Any] | TimestampRange | None) – Range between two timestamps.
root (bool | None) – Whether the filtered assets are root assets, or not. Set to True to only list root assets.
external_id_prefix (str | None) – Filter by this (case-sensitive) prefix for the external ID.
labels (LabelFilter | None) – Return only the resource matching the specified label constraints.
geo_location (GeoLocationFilter | None) – Only include files matching the specified geographic relation.
- 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]
- class cognite.client.data_classes.assets.AssetHierarchy(
- assets: Sequence[AssetWrite],
- ignore_orphans: bool = False,
Bases:
objectClass that verifies if a collection of Assets is valid, by validating its internal consistency. This is done “offline”, meaning CDF is -not- queried for the already existing assets. As a result, any asset providing a parent link by ID instead of external ID, are assumed valid.
- Parameters:
assets (Sequence[AssetWrite]) – Sequence of assets to be inspected for validity.
ignore_orphans (bool) – If true, orphan assets are assumed valid and won’t raise.
Examples
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import AssetHierarchy >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> hierarchy = AssetHierarchy(assets) >>> # Get a report written to the terminal listing any issues: >>> hierarchy.validate_and_report() >>> if hierarchy.is_valid(): ... res = client.assets.create_hierarchy(hierarchy) ... # If there are issues, you may inspect them directly: ... else: ... hierarchy.orphans ... hierarchy.invalid ... hierarchy.unsure_parents ... hierarchy.duplicates ... hierarchy.cycles # Requires no other basic issues
There are other ways to generate the report than to write directly to screen. You may pass an
output_filewhich can be either aPathobject (writes are done in append-mode) or a file-like object supportingwrite(default isNonewhich is just regularprint):>>> # Get a report written to file: >>> from pathlib import Path >>> report = Path("path/to/my_report.txt") >>> hierarchy = AssetHierarchy(assets) >>> hierarchy.validate_and_report(output_file=report)
>>> # Get a report as text "in memory": >>> import io >>> with io.StringIO() as file_like: ... hierarchy.validate_and_report(output_file=file_like) ... report = file_like.getvalue()
- count_subtree(
- mapping: dict[str | None, list[AssetWrite]],
Returns a mapping from asset external ID to the size of its subtree (children and children of children etc.).
- Parameters:
mapping (dict[str | None, list[AssetWrite]]) – The mapping returned by groupby_parent_xid(). If None is passed, will be recreated (slightly expensive).
- Returns:
Lookup from external ID to descendant count.
- Return type:
dict[str, int]
- groupby_parent_xid() dict[str | None, list[AssetWrite]]
Returns a mapping from parent external ID to a list of its direct children.
Note
If the AssetHierarchy was initialized with ignore_orphans=True, all orphans assets, if any, are returned as part of the root assets in the mapping and can be accessed by mapping[None]. The same is true for all assets linking its parent by ID.
- Returns:
No description.
- Return type:
dict[str | None, list[AssetWrite]]
- class cognite.client.data_classes.assets.AssetList(
- resources: Sequence[T_CogniteResource],
Bases:
WriteableCogniteResourceListWithClientRef[AssetWrite,Asset],IdTransformerMixin- events(**kwargs: Any) EventList
Retrieve all events related to these assets.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to events/list. Note: ‘sort’, ‘partitions’ and ‘limit’ can not be used.
- Returns:
All events related to the assets in this AssetList.
- Return type:
- async events_async(**kwargs: Any) EventList
Retrieve all events related to these assets.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to events/list. Note: ‘sort’, ‘partitions’ and ‘limit’ can not be used.
- Returns:
All events related to the assets in this AssetList.
- Return type:
- files(**kwargs: Any) FileMetadataList
Retrieve all files metadata related to these assets.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to files/list. Note: ‘limit’ can not be used.
- Returns:
Metadata about all files related to the assets in this AssetList.
- Return type:
- async files_async(**kwargs: Any) FileMetadataList
Retrieve all files metadata related to these assets.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to files/list. Note: ‘limit’ can not be used.
- Returns:
Metadata about all files related to the assets in this AssetList.
- Return type:
- sequences(**kwargs: Any) SequenceList
Retrieve all sequences related to these assets.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to sequences/list. Note: ‘limit’ can not be used.
- Returns:
All sequences related to the assets in this AssetList.
- Return type:
- async sequences_async(**kwargs: Any) SequenceList
Retrieve all sequences related to these assets.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to sequences/list. Note: ‘limit’ can not be used.
- Returns:
All sequences related to the assets in this AssetList.
- Return type:
- time_series(**kwargs: Any) TimeSeriesList
Retrieve all time series related to these assets.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to time_series/list. Note: ‘partitions’ and ‘limit’ can not be used.
- Returns:
All time series related to the assets in this AssetList.
- Return type:
- async time_series_async(**kwargs: Any) TimeSeriesList
Retrieve all time series related to these assets.
- Parameters:
**kwargs (Any) – All extra keyword arguments are passed to time_series/list. Note: ‘partitions’ and ‘limit’ can not be used.
- Returns:
All time series related to the assets in this AssetList.
- Return type:
- class cognite.client.data_classes.assets.AssetProperty(value)
Bases:
EnumPropertyAn enumeration.
- class cognite.client.data_classes.assets.AssetUpdate(id: int | None = None, external_id: str | None = None)
Bases:
CogniteUpdateChanges applied to asset
- Parameters:
id (int) – A server-generated ID for the object.
external_id (str) – The external ID provided by the client. Must be unique for the resource type.
- class cognite.client.data_classes.assets.AssetWrite(
- name: str,
- external_id: str | None = None,
- parent_id: int | None = None,
- parent_external_id: str | None = None,
- description: str | None = None,
- data_set_id: int | None = None,
- metadata: dict[str, str] | None = None,
- source: str | None = None,
- labels: list[Label | str | LabelDefinitionWrite | dict] | None = None,
- geo_location: GeoLocation | None = None,
Bases:
WriteableCogniteResource[AssetWrite]A representation of a physical asset, for example, a factory or a piece of equipment. This is the write version of the Asset class, and is used when inserting new assets.
- Parameters:
name (str) – The name of the asset.
external_id (str | None) – The external ID provided by the client. Must be unique for the resource type.
parent_id (int | None) – The parent of the node, null if it is the root node.
parent_external_id (str | None) – The external ID of the parent. The property is omitted if the asset doesn’t have a parent or if the parent doesn’t have externalId.
description (str | None) – The description of the asset.
data_set_id (int | None) – The id of the dataset this asset belongs to.
metadata (dict[str, str] | None) – Custom, application-specific metadata. String key -> String value. Limits: Maximum length of key is 128 bytes, value 10240 bytes, up to 256 key-value pairs, of total size at most 10240.
source (str | None) – The source of the asset.
labels (list[Label | str | LabelDefinitionWrite | dict] | None) – A list of the labels associated with this resource item.
geo_location (GeoLocation | None) – The geographic metadata of the asset.
- 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]
- class cognite.client.data_classes.assets.AssetWriteList(
- resources: Sequence[T_CogniteResource],
Bases:
CogniteResourceList[AssetWrite],ExternalIDTransformerMixin
- class cognite.client.data_classes.assets.SortableAssetProperty(value)
Bases:
EnumPropertyAn enumeration.