Update assets
- async AsyncCogniteClient.assets.update(
- item: Asset | AssetWrite | AssetUpdate | Sequence[Asset | AssetWrite | AssetUpdate],
- mode: Literal['replace_ignore_null', 'patch', 'replace'] = 'replace_ignore_null',
-
Labels can be added, removed or replaced (set). Note that set operation deletes all the existing labels and adds the new specified labels.
- Parameters:
item (Asset | AssetWrite | AssetUpdate | Sequence[Asset | AssetWrite | AssetUpdate]) – Asset(s) to update
mode (Literal['replace_ignore_null', 'patch', 'replace']) – How to update data when a non-update object is given (Asset or -Write). If you use ‘replace_ignore_null’, only the fields you have set will be used to replace existing (default). Using ‘replace’ will additionally clear all the fields that are not specified by you. Last option, ‘patch’, will update only the fields you have set and for container-like fields such as metadata or labels, add the values to the existing. For more details, see Update and Upsert Mode Parameter.
- Returns:
Updated asset(s)
- Return type:
Examples
Perform a partial update on an asset, updating the description and adding a new field to metadata:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import AssetUpdate >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> my_update = ( ... AssetUpdate(id=1) ... .description.set("New description") ... .metadata.add({"key": "value"}) ... ) >>> res1 = client.assets.update(my_update) >>> # Remove an already set field like so >>> another_update = AssetUpdate(id=1).description.set(None) >>> res2 = client.assets.update(another_update)
Remove the metadata on an asset:
>>> from cognite.client.data_classes import AssetUpdate >>> my_update = AssetUpdate(id=1).metadata.add({"key": "value"}) >>> res1 = client.assets.update(my_update) >>> another_update = AssetUpdate(id=1).metadata.set(None) >>> # The same result can be achieved with: >>> another_update2 = AssetUpdate(id=1).metadata.set({}) >>> res2 = client.assets.update(another_update)
Attach labels to an asset:
>>> from cognite.client.data_classes import AssetUpdate >>> my_update = AssetUpdate(id=1).labels.add(["PUMP", "VERIFIED"]) >>> res = client.assets.update(my_update)
Detach a single label from an asset:
>>> from cognite.client.data_classes import AssetUpdate >>> my_update = AssetUpdate(id=1).labels.remove("PUMP") >>> res = client.assets.update(my_update)
Replace all labels for an asset:
>>> from cognite.client.data_classes import AssetUpdate >>> my_update = AssetUpdate(id=1).labels.set("PUMP") >>> res = client.assets.update(my_update)