Skip to content

Commit

Permalink
Adding subscription member endpoint (#1440)
Browse files Browse the repository at this point in the history
Co-authored-by: Anders Albert <[email protected]>
  • Loading branch information
matiascognite and doctrino authored Oct 27, 2023
1 parent e8b74a7 commit 4e23f9b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [6.36.0] - 2023-10-25
### Added
- Support for listing members of Data Point Subscription, `client.time_series.subscriptions.list_member_time_series()`. Note this is an experimental feature.

## [6.35.0] - 2023-10-25
### Added
- Support for `through` on node result set expressions.
Expand Down
33 changes: 33 additions & 0 deletions cognite/client/_api/datapoints_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
DatapointSubscriptionList,
DatapointSubscriptionPartition,
DataPointSubscriptionUpdate,
TimeSeriesID,
TimeSeriesIDList,
_DatapointSubscriptionBatchWithPartitions,
)
from cognite.client.utils._experimental import FeaturePreviewWarning
Expand Down Expand Up @@ -127,6 +129,37 @@ def retrieve(self, external_id: str, ignore_unknown_ids: bool = False) -> Datapo
else:
return None

def list_member_time_series(self, external_id: str, limit: int | None = DEFAULT_LIMIT_READ) -> TimeSeriesIDList:
"""`List time series in a subscription <https://api-docs.cognite.com/20230101-beta/tag/Data-point-subscriptions/operation/listSubscriptionMembers>`_
Retrieve a list of time series (IDs) that the subscription is currently retrieving updates from
Args:
external_id (str): External ID of the subscription to retrieve members of.
limit (int | None): Maximum number of time series to return. Defaults to 25. Set to -1, float("inf") or None to return all items.
Returns:
TimeSeriesIDList: List of time series in the subscription.
Examples:
List time series in a subscription:
>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import DataPointSubscriptionUpdate
>>> c = CogniteClient()
>>> members = c.time_series.subscriptions.list_member_time_series("my_subscription")
>>> timeseries_external_ids = members.as_external_ids()
"""
return self._list(
method="GET",
limit=limit,
list_cls=TimeSeriesIDList,
resource_cls=TimeSeriesID,
resource_path="/timeseries/subscriptions/members",
other_params={"externalId": external_id},
)

def update(self, update: DataPointSubscriptionUpdate) -> DatapointSubscription:
"""`Update a subscriptions <https://pr-2221.specs.preview.cogniteapp.com/20230101-beta.json.html#tag/Data-point-subscriptions/operation/updateSubscriptions>`_
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "6.35.0"
__version__ = "6.36.0"
__api_subversion__ = "V20220125"
5 changes: 5 additions & 0 deletions cognite/client/data_classes/datapoints_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CogniteResourceList,
CogniteUpdate,
EnumProperty,
IdTransformerMixin,
NoCaseConversionPropertyList,
PropertySpec,
T_CogniteResource,
Expand Down Expand Up @@ -361,6 +362,10 @@ class DatapointSubscriptionList(CogniteResourceList[DatapointSubscription]):
_RESOURCE = DatapointSubscription


class TimeSeriesIDList(CogniteResourceList[TimeSeriesID], IdTransformerMixin):
_RESOURCE = TimeSeriesID


def _metadata(key: str) -> list[str]:
return NoCaseConversionPropertyList(["metadata", key])

Expand Down
4 changes: 4 additions & 0 deletions docs/source/core_data_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ List data point subscriptions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.datapoints_subscriptions.DatapointsSubscriptionAPI.list

List member time series of subscription
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.datapoints_subscriptions.DatapointsSubscriptionAPI.list_member_time_series

Iterate over subscriptions data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: cognite.client._api.datapoints_subscriptions.DatapointsSubscriptionAPI.iterate_data
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "cognite-sdk"

version = "6.35.0"
version = "6.36.0"
description = "Cognite Python SDK"
readme = "README.md"
documentation = "https://cognite-sdk-python.readthedocs-hosted.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def test_create_retrieve_delete_subscription(
assert created.time_series_count == len(new_subscription.time_series_ids)
assert retrieved_subscription.external_id == new_subscription.external_id == created.external_id

time_series_in_subscription = cognite_client.time_series.subscriptions.list_member_time_series(
new_subscription.external_id, limit=10
)
retrieved_time_series_external_ids = [ts.external_id for ts in time_series_in_subscription]
assert sorted(new_subscription.time_series_ids) == sorted(retrieved_time_series_external_ids)

# Act
cognite_client.time_series.subscriptions.delete(new_subscription.external_id)
retrieved_deleted = cognite_client.time_series.subscriptions.retrieve(
Expand Down

0 comments on commit 4e23f9b

Please sign in to comment.