Sync

async AsyncCogniteClient.data_modeling.records.sync(
stream_id: str,
*,
initialize_cursor: str,
filter: Filter | None = None,
sources: Sequence[RecordSourceSelector] | None = None,
target_units: RecordTargetUnits | Sequence[RecordTargetUnit] | None = None,
limit: int = 10,
include_typing: bool = False,
) SyncRecordList

Sync records from a stream.

Returns the first page of the change feed (new, updated and deleted records). Provide initialize_cursor to start from a relative time such as "7d-ago". Persist the returned SyncRecordList.cursor and pass it to sync_resume() on the next call to continue; SyncRecordList.has_next indicates whether more changes are immediately available.

Parameters:
  • stream_id (str) – External ID of the stream to sync.

  • initialize_cursor (str) – Where to start, as a relative duration like "7d-ago".

  • filter (Filter | None) – Filter expression (see cognite.client.data_classes.filters).

  • sources (Sequence[RecordSourceSelector] | None) – Which container properties to return.

  • target_units (RecordTargetUnits | Sequence[RecordTargetUnit] | None) – Properties to convert to another unit.

  • limit (int) – Maximum number of records to return in this page (1-1000). Defaults to 10.

  • include_typing (bool) – If True, include property type information on the returned list’s typing attribute.

Returns:

One page of change records, with cursor and has_next set.

Return type:

SyncRecordList

Examples

Initialize a sync, process the page, then resume from the cursor later:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> page = client.data_modeling.records.sync(
...     stream_id="my-stream", initialize_cursor="7d-ago"
... )
>>> for record in page:
...     pass  # process record; record.status is created/updated/deleted
>>> next_page = client.data_modeling.records.sync_resume(
...     stream_id="my-stream", cursor=page.cursor
... )