Update sequences

async AsyncCogniteClient.sequences.update(
item: Sequence | SequenceWrite | SequenceUpdate | Sequence[Sequence | SequenceWrite | SequenceUpdate],
mode: Literal['replace_ignore_null', 'patch', 'replace'] = 'replace_ignore_null',
) → Sequence | SequenceList

Update one or more sequences.

Deprecated since version 8.23.0: The Sequences API is deprecated and is scheduled for removal on 2027-12-31. Use files in data modeling (for whole-table downloads) or records (for row-level queries). See https://docs.cognite.com/cdf/deprecated for details and migration guidance.

Parameters:
  • item (Sequence | SequenceWrite | SequenceUpdate | Sequence[Sequence | SequenceWrite | SequenceUpdate]) – Sequences to update

  • mode (Literal['replace_ignore_null', 'patch', 'replace']) – How to update data when a non-update object is given (Sequence 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 sequences.

Return type:

Sequence | SequenceList

Examples

Update a sequence that you have fetched. This will perform a full update of the sequences:

>>> from cognite.client import CogniteClient, AsyncCogniteClient
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient()  # another option
>>> res = client.sequences.retrieve(id=1)
>>> res.description = "New description"
>>> res = client.sequences.update(res)

Perform a partial update on a sequence, updating the description and adding a new field to metadata:

>>> from cognite.client.data_classes import SequenceUpdate
>>> my_update = (
...     SequenceUpdate(id=1)
...     .description.set("New description")
...     .metadata.add({"key": "value"})
... )
>>> res = client.sequences.update(my_update)

Updating column definitions

Currently, updating the column definitions of a sequence is only supported through partial update, using add, remove and modify methods on the columns property.

Add a single new column:

>>> from cognite.client.data_classes import SequenceUpdate, SequenceColumnWrite
>>>
>>> my_update = SequenceUpdate(id=1).columns.add(
...     SequenceColumnWrite(
...         value_type="STRING", external_id="user", description="some description"
...     )
... )
>>> res = client.sequences.update(my_update)

Add multiple new columns:

>>> from cognite.client.data_classes import SequenceUpdate, SequenceColumnWrite
>>>
>>> column_def = [
...     SequenceColumnWrite(
...         value_type="STRING", external_id="user", description="some description"
...     ),
...     SequenceColumnWrite(value_type="DOUBLE", external_id="amount"),
... ]
>>> my_update = SequenceUpdate(id=1).columns.add(column_def)
>>> res = client.sequences.update(my_update)

Remove a single column:

>>> from cognite.client.data_classes import SequenceUpdate
>>>
>>> my_update = SequenceUpdate(id=1).columns.remove("col_external_id1")
>>> res = client.sequences.update(my_update)

Remove multiple columns:

>>> from cognite.client.data_classes import SequenceUpdate
>>>
>>> my_update = SequenceUpdate(id=1).columns.remove(
...     ["col_external_id1", "col_external_id2"]
... )
>>> res = client.sequences.update(my_update)

Update existing columns:

>>> from cognite.client.data_classes import SequenceUpdate, SequenceColumnUpdate
>>>
>>> column_updates = [
...     SequenceColumnUpdate(external_id="col_external_id_1").external_id.set(
...         "new_col_external_id"
...     ),
...     SequenceColumnUpdate(external_id="col_external_id_2").description.set(
...         "my new description"
...     ),
... ]
>>> my_update = SequenceUpdate(id=1).columns.modify(column_updates)
>>> res = client.sequences.update(my_update)