List sequences

async AsyncCogniteClient.sequences.list(
name: str | None = None,
external_id_prefix: str | None = None,
metadata: dict[str, str] | None = None,
asset_ids: Sequence[int] | 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,
created_time: dict[str, Any] | TimestampRange | None = None,
last_updated_time: dict[str, Any] | TimestampRange | None = None,
limit: int | None = 25,
partitions: int | None = None,
advanced_filter: Filter | dict[str, Any] | None = None,
sort: SequenceSort | str | SortableSequenceProperty | tuple[str, Literal['asc', 'desc']] | tuple[str, Literal['asc', 'desc'], Literal['auto', 'first', 'last']] | list[SequenceSort | str | SortableSequenceProperty | tuple[str, Literal['asc', 'desc']] | tuple[str, Literal['asc', 'desc'], Literal['auto', 'first', 'last']]] | None = None,
) SequenceList

List sequences.

Parameters:
  • name (str | None) – Filter out sequences that do not have this exact name.

  • external_id_prefix (str | None) – Filter out sequences that do not have this string as the start of the externalId

  • metadata (dict[str, str] | None) – Filter out sequences that do not match these metadata fields and values (case-sensitive). Format is {“key1”:”value1”,”key2”:”value2”}.

  • asset_ids (Sequence[int] | None) – Filter out sequences that are not linked to any of these assets.

  • asset_subtree_ids (int | Sequence[int] | None) – Only include sequences that have a related 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 sequences that have a related 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 sequences in the specified data set(s) with this id / these ids.

  • data_set_external_ids (str | SequenceNotStr[str] | None) – Return only sequences in the specified data set(s) with this external id / these external ids.

  • created_time (dict[str, Any] | TimestampRange | 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] | TimestampRange | None) – Range between two timestamps. Possible keys are min and max, with values given as time stamps in ms.

  • limit (int | None) – Max number of sequences to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.

  • 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).

  • 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] | 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 sequences.

Return type:

SequenceList

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 sequences:

>>> from cognite.client import CogniteClient, AsyncCogniteClient
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient()  # another option
>>> res = client.sequences.list(limit=5)

Iterate over sequences, one-by-one:

>>> for seq in client.sequences():
...     seq  # do something with the sequence

Iterate over chunks of sequences to reduce memory load:

>>> for seq_list in client.sequences(chunk_size=2500):
...     seq_list  # do something with the sequences

Using advanced filter, find all sequences 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.sequences.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 SequenceProperty and SortableSequenceProperty Enums.

>>> from cognite.client.data_classes import filters
>>> from cognite.client.data_classes.sequences import (
...     SequenceProperty,
...     SortableSequenceProperty,
... )
>>> in_timezone = filters.Prefix(SequenceProperty.metadata_key("timezone"), "Europe")
>>> res = client.sequences.list(
...     advanced_filter=in_timezone, sort=(SortableSequenceProperty.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.sequences.list(
...     asset_subtree_ids=[123456], advanced_filter=not_instrument_lvl5
... )