List time series
- async AsyncCogniteClient.time_series.list(
- name: str | None = None,
- unit: str | None = None,
- unit_external_id: str | None = None,
- unit_quantity: str | None = None,
- is_string: bool | None = None,
- is_step: bool | None = None,
- asset_ids: Sequence[int] | None = None,
- asset_external_ids: SequenceNotStr[str] | None = None,
- asset_subtree_ids: int | Sequence[int] | None = None,
- asset_subtree_external_ids: str | SequenceNotStr[str] | None = None,
- data_set_ids: int | Sequence[int] | None = None,
- data_set_external_ids: str | SequenceNotStr[str] | None = None,
- metadata: dict[str, Any] | None = None,
- external_id_prefix: str | None = None,
- created_time: dict[str, Any] | None = None,
- last_updated_time: dict[str, Any] | None = None,
- partitions: int | None = None,
- limit: int | None = 25,
- advanced_filter: Filter | dict[str, Any] | None = None,
- sort: TimeSeriesSort | str | SortableTimeSeriesProperty | tuple[str, Literal['asc', 'desc']] | tuple[str, Literal['asc', 'desc'], Literal['auto', 'first', 'last']] | list[TimeSeriesSort | str | SortableTimeSeriesProperty | tuple[str, Literal['asc', 'desc']] | tuple[str, Literal['asc', 'desc'], Literal['auto', 'first', 'last']]] | TimeSeriesProperty | None = None,
-
- Parameters:
name (str | None) – Name of the time series. Often referred to as tag.
unit (str | None) – Unit of the time series.
unit_external_id (str | None) – Filter on unit external ID.
unit_quantity (str | None) – Filter on unit quantity.
is_string (bool | None) – Whether the time series is a string time series.
is_step (bool | None) – Whether the time series is a step (piecewise constant) time series.
asset_ids (Sequence[int] | None) – List time series related to these assets.
asset_external_ids (SequenceNotStr[str] | None) – List time series related to these assets.
asset_subtree_ids (int | Sequence[int] | None) – Only include time series that are related to an asset in a subtree rooted at any of these assetIds. If the total size of the given subtrees exceeds 100,000 assets, an error will be returned.
asset_subtree_external_ids (str | SequenceNotStr[str] | None) – Only include time series that are related to an asset in a subtree rooted at any of these assetExternalIds. If the total size of the given subtrees exceeds 100,000 assets, an error will be returned.
data_set_ids (int | Sequence[int] | None) – Return only time series in the specified data set(s) with this id / these ids.
data_set_external_ids (str | SequenceNotStr[str] | None) – Return only time series in the specified data set(s) with this external id / these external ids.
metadata (dict[str, Any] | None) – Custom, application specific metadata. String key -> String value
external_id_prefix (str | None) – Filter by this (case-sensitive) prefix for the external ID.
created_time (dict[str, Any] | None) – Range between two timestamps. Possible keys are min and max, with values given as time stamps in ms.
last_updated_time (dict[str, Any] | None) – Range between two timestamps. Possible keys are min and max, with values given as time stamps in ms.
partitions (int | None) – Retrieve resources in parallel using this number of workers (values up to 10 allowed), limit must be set to None (or -1).
limit (int | None) – Maximum number of time series to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.
advanced_filter (Filter | dict[str, Any] | None) – Advanced filter query using the filter DSL (Domain Specific Language). It allows defining complex filtering expressions that combine simple operations, such as equals, prefix, exists, etc., using boolean operators and, or, and not. See examples below for usage.
sort (SortSpec | list[SortSpec] | TimeSeriesProperty | None) – The criteria to sort by. Defaults to desc for _score_ and asc for all other properties. Sort is not allowed if partitions is used.
- Returns:
The requested time series.
- Return type:
Note
- When using partitions, there are few considerations to keep in mind:
limit has to be set to None (or -1).
API may reject requests if you specify more than 10 partitions. When Cognite enforces this behavior, the requests result in a 400 Bad Request status.
Partitions are done independently of sorting: there’s no guarantee of the sort order between elements from different partitions. For this reason providing a sort parameter when using partitions is not allowed.
Examples
List time series:
>>> from cognite.client import CogniteClient, AsyncCogniteClient >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> res = client.time_series.list(limit=5)
Iterate over time series, one-by-one:
>>> for ts in client.time_series(): ... ts # do something with the time series
Iterate over chunks of time series to reduce memory load:
>>> for ts_list in client.time_series(chunk_size=2500): ... ts_list # do something with the time series
Using advanced filter, find all time series that have a metadata key ‘timezone’ starting with ‘Europe’, and sort by external id ascending:
>>> from cognite.client.data_classes import filters >>> in_timezone = filters.Prefix(["metadata", "timezone"], "Europe") >>> res = client.time_series.list( ... advanced_filter=in_timezone, sort=("external_id", "asc") ... )
Note that you can check the API documentation above to see which properties you can filter on with which filters.
To make it easier to avoid spelling mistakes and easier to look up available properties for filtering and sorting, you can also use the TimeSeriesProperty and SortableTimeSeriesProperty Enums.
>>> from cognite.client.data_classes import filters >>> from cognite.client.data_classes.time_series import ( ... TimeSeriesProperty, ... SortableTimeSeriesProperty, ... ) >>> in_timezone = filters.Prefix(TimeSeriesProperty.metadata_key("timezone"), "Europe") >>> res = client.time_series.list( ... advanced_filter=in_timezone, sort=(SortableTimeSeriesProperty.external_id, "asc") ... )
Combine filter and advanced filter:
>>> from cognite.client.data_classes import filters >>> not_instrument_lvl5 = filters.And( ... filters.ContainsAny("labels", ["Level5"]), ... filters.Not(filters.ContainsAny("labels", ["Instrument"])), ... ) >>> res = client.time_series.list( ... asset_subtree_ids=[123456], advanced_filter=not_instrument_lvl5 ... )