Insert rows into a sequence

async AsyncCogniteClient.sequences.data.insert(
rows: SequenceRows | dict[int, Sequence[int | float | str]] | Sequence[tuple[int, Sequence[int | float | str]]] | Sequence[dict[str, Any]],
columns: SequenceNotStr[str] | None = None,
id: int | None = None,
external_id: str | None = None,
) None

Insert rows into a sequence.

Parameters:
  • rows (SequenceRows | dict[int, Sequence[int | float | str]] | Sequence[tuple[int, Sequence[int | float | str]]] | Sequence[dict[str, Any]]) – The rows you wish to insert. Can either be a list of tuples, a list of {“rowNumber”:… ,”values”: …} objects, a dictionary of rowNumber: data, or a SequenceData object. See examples below.

  • columns (SequenceNotStr[str] | None) – List of external id for the columns of the sequence.

  • id (int | None) – Id of sequence to insert rows into.

  • external_id (str | None) – External id of sequence to insert rows into.

Examples

Your rows of data can be a list of tuples where the first element is the rownumber and the second element is the data to be inserted:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import SequenceWrite, SequenceColumnWrite
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient()  # another option
>>> seq = client.sequences.create(
...     SequenceWrite(
...         columns=[
...             SequenceColumnWrite(value_type="STRING", external_id="col_a"),
...             SequenceColumnWrite(value_type="DOUBLE", external_id="col_b"),
...         ],
...     )
... )
>>> data = [(1, ["pi", 3.14]), (2, ["e", 2.72])]
>>> client.sequences.data.insert(columns=["col_a", "col_b"], rows=data, id=1)

They can also be provided as a list of API-style objects with a rowNumber and values field:

>>> data = [
...     {"rowNumber": 123, "values": ["str", 3]},
...     {"rowNumber": 456, "values": ["bar", 42]},
... ]
>>> client.sequences.data.insert(
...     data, id=1, columns=["col_a", "col_b"]
... )  # implicit columns are retrieved from metadata

Or they can be a given as a dictionary with row number as the key, and the value is the data to be inserted at that row:

>>> data = {123: ["str", 3], 456: ["bar", 42]}
>>> client.sequences.data.insert(columns=["stringColumn", "intColumn"], rows=data, id=1)

Finally, they can be a SequenceData object retrieved from another request. In this case columns from this object are used as well.

>>> data = client.sequences.data.retrieve(id=2, start=0, end=10)
>>> client.sequences.data.insert(rows=data, id=1, columns=None)