1919 from sift_client .sift_types .channel import Channel
2020
2121
22+ def _channel_ids_from_list (items : list [str | Channel ]) -> list [str ]:
23+ """Resolve a list of channel IDs or Channel objects to a list of channel IDs.
24+
25+ Args:
26+ items: List of channel IDs (str) or Channel objects.
27+
28+ Returns:
29+ List of channel ID strings.
30+
31+ Raises:
32+ ValueError: If any Channel object has no id set.
33+ """
34+ ids : list [str ] = []
35+ for item in items :
36+ if isinstance (item , str ):
37+ ids .append (item )
38+ else :
39+ try :
40+ ids .append (item ._id_or_error )
41+ except ValueError :
42+ raise ValueError ("One or more Channel objects have no id set." ) from None
43+ return ids
44+
45+
2246class ChannelsAPIAsync (ResourceBase ):
2347 """High-level API for interacting with channels.
2448
@@ -75,7 +99,7 @@ async def list_(
7599 run : Run | str | None = None ,
76100 # common filters
77101 description_contains : str | None = None ,
78- include_archived : bool | None = None ,
102+ archived : bool | None = None ,
79103 filter_query : str | None = None ,
80104 order_by : str | None = None ,
81105 limit : int | None = None ,
@@ -96,7 +120,7 @@ async def list_(
96120 assets: Filter channels associated with these Assets or asset IDs.
97121 run: Filter channels associated with this Run or run ID.
98122 description_contains: Partial description of the channel.
99- include_archived : If True, include archived channels in results .
123+ archived : If True, searches for archived channels.
100124 filter_query: Explicit CEL query to filter channels.
101125 order_by: Field and direction to order results by.
102126 limit: Maximum number of channels to return. If None, returns all matches.
@@ -117,7 +141,6 @@ async def list_(
117141 * self ._build_common_cel_filters (
118142 description_contains = description_contains ,
119143 filter_query = filter_query ,
120- include_archived = include_archived ,
121144 ),
122145 ]
123146 if channel_ids :
@@ -133,9 +156,10 @@ async def list_(
133156 if run is not None :
134157 run_id = run .id_ if isinstance (run , Run ) else run
135158 filter_parts .append (cel .equals ("run_id" , run_id ))
159+
136160 # This is opposite of usual archived state
137- if include_archived is not None :
138- filter_parts .append (cel .equals ("active" , not include_archived ))
161+ if archived is not None :
162+ filter_parts .append (cel .equals ("active" , not archived ))
139163
140164 query_filter = cel .and_ (* filter_parts )
141165
@@ -163,6 +187,26 @@ async def find(self, **kwargs) -> Channel | None:
163187 return channels [0 ]
164188 return None
165189
190+ async def archive (self , channels : list [str | Channel ]) -> None :
191+ """Batch archive channels by setting active to false.
192+
193+ Args:
194+ channels: List of channel IDs or Channel objects to archive. If a Channel
195+ has no id set, raises ValueError.
196+ """
197+ channel_ids = _channel_ids_from_list (channels )
198+ await self ._low_level_client .batch_archive_channels (channel_ids )
199+
200+ async def unarchive (self , channels : list [str | Channel ]) -> None :
201+ """Batch unarchive channels by setting active to true.
202+
203+ Args:
204+ channels: List of channel IDs or Channel objects to unarchive. If a Channel
205+ has no id set, raises ValueError.
206+ """
207+ channel_ids = _channel_ids_from_list (channels )
208+ await self ._low_level_client .batch_unarchive_channels (channel_ids )
209+
166210 def _ensure_data_low_level_client (self ):
167211 """Ensure that the data low level client is initialized. Separated out like this to not require large dependencies (pandas/pyarrow) for the client if not fetching data."""
168212 if self ._data_low_level_client is None :
0 commit comments