Upsert time series
- async AsyncCogniteClient.time_series.upsert(
- item: TimeSeries | TimeSeriesWrite | Sequence[TimeSeries | TimeSeriesWrite],
- mode: Literal['patch', 'replace'] = 'patch',
Upsert time series, i.e., update if it exists, and create if it does not exist.
Note this is a convenience method that handles the upserting for you by first calling update on all items, and if any of them fail because they do not exist, it will create them instead.
For more details, see Upsert.
- Parameters:
item (TimeSeries | TimeSeriesWrite | Sequence[TimeSeries | TimeSeriesWrite]) – TimeSeries or list of TimeSeries to upsert.
mode (Literal['patch', 'replace']) – Whether to patch or replace in the case the time series are existing. If you set ‘patch’, the call will only update fields with non-null values (default). Setting ‘replace’ will unset any fields that are not specified.
- Returns:
The upserted time series(s).
- Return type:
Examples
Upsert for TimeSeries:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import TimeSeriesWrite >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> existing_time_series = client.time_series.retrieve(id=1) >>> existing_time_series.description = "New description" >>> new_time_series = TimeSeriesWrite( ... external_id="new_timeSeries", description="New timeSeries" ... ) >>> res = client.time_series.upsert( ... [existing_time_series, new_time_series], mode="replace" ... )