Upsert

async AsyncCogniteClient.data_modeling.records.upsert(
items: RecordWrite | Sequence[RecordWrite],
*,
stream_id: str,
upsert_mode: Literal['replace'] = 'replace',
) None

Upsert records into a stream.

Creates or fully updates records. Only valid for mutable streams (returns 422 on immutable). When a record with the same space + externalId already exists it is fully replaced (this endpoint does not do partial property updates); otherwise it is created.

Parameters:
  • items (RecordWrite | Sequence[RecordWrite]) – One or more records to upsert.

  • stream_id (str) – External ID of the stream to upsert into.

  • upsert_mode (Literal['replace']) – How existing records are updated. Currently only "replace" is supported, which fully replaces the existing record. Defaults to "replace".

Examples

Upsert a single record:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes.data_modeling.records import (
...     RecordWrite,
...     RecordContainerId,
...     RecordSource,
... )
>>> client = CogniteClient()
>>> client.data_modeling.records.upsert(
...     RecordWrite(
...         space="my-space",
...         external_id="rec-1",
...         sources=[
...             RecordSource(
...                 source=RecordContainerId(
...                     space="my-space", external_id="my-container"
...                 ),
...                 properties={"temperature": 23.0},
...             )
...         ],
...     ),
...     stream_id="my-stream",
... )