@@ -819,6 +819,30 @@ def list_workflows(
819
819
)
820
820
)
821
821
822
+ async def count_workflows (
823
+ self ,
824
+ query : Optional [str ] = None ,
825
+ rpc_metadata : Mapping [str , str ] = {},
826
+ rpc_timeout : Optional [timedelta ] = None ,
827
+ ) -> WorkflowExecutionCount :
828
+ """Count workflows.
829
+
830
+ Args:
831
+ query: A Temporal visibility filter. See Temporal documentation
832
+ concerning visibility list filters.
833
+ rpc_metadata: Headers used on each RPC call. Keys here override
834
+ client-level RPC metadata keys.
835
+ rpc_timeout: Optional RPC deadline to set for each RPC call.
836
+
837
+ Returns:
838
+ Count of workflows.
839
+ """
840
+ return await self ._impl .count_workflows (
841
+ CountWorkflowsInput (
842
+ query = query , rpc_metadata = rpc_metadata , rpc_timeout = rpc_timeout
843
+ )
844
+ )
845
+
822
846
@overload
823
847
def get_async_activity_handle (
824
848
self , * , workflow_id : str , run_id : Optional [str ], activity_id : str
@@ -2310,6 +2334,57 @@ class WorkflowExecutionStatus(IntEnum):
2310
2334
)
2311
2335
2312
2336
2337
+ @dataclass
2338
+ class WorkflowExecutionCount :
2339
+ """Representation of a count from a count workflows call."""
2340
+
2341
+ count : int
2342
+ """Approximate number of workflows matching the original query.
2343
+
2344
+ If the query had a group-by clause, this is simply the sum of all the counts
2345
+ in py:attr:`groups`.
2346
+ """
2347
+
2348
+ groups : Sequence [WorkflowExecutionCountAggregationGroup ]
2349
+ """Groups if the query had a group-by clause, or empty if not."""
2350
+
2351
+ @staticmethod
2352
+ def _from_raw (
2353
+ raw : temporalio .api .workflowservice .v1 .CountWorkflowExecutionsResponse ,
2354
+ ) -> WorkflowExecutionCount :
2355
+ return WorkflowExecutionCount (
2356
+ count = raw .count ,
2357
+ groups = [
2358
+ WorkflowExecutionCountAggregationGroup ._from_raw (g ) for g in raw .groups
2359
+ ],
2360
+ )
2361
+
2362
+
2363
+ @dataclass
2364
+ class WorkflowExecutionCountAggregationGroup :
2365
+ """Aggregation group if the workflow count query had a group-by clause."""
2366
+
2367
+ count : int
2368
+ """Approximate number of workflows matching the original query for this
2369
+ group.
2370
+ """
2371
+
2372
+ group_values : Sequence [temporalio .common .SearchAttributeValue ]
2373
+ """Search attribute values for this group."""
2374
+
2375
+ @staticmethod
2376
+ def _from_raw (
2377
+ raw : temporalio .api .workflowservice .v1 .CountWorkflowExecutionsResponse .AggregationGroup ,
2378
+ ) -> WorkflowExecutionCountAggregationGroup :
2379
+ return WorkflowExecutionCountAggregationGroup (
2380
+ count = raw .count ,
2381
+ group_values = [
2382
+ temporalio .converter ._decode_search_attribute_value (v )
2383
+ for v in raw .group_values
2384
+ ],
2385
+ )
2386
+
2387
+
2313
2388
class WorkflowExecutionAsyncIterator :
2314
2389
"""Asynchronous iterator for :py:class:`WorkflowExecution` values.
2315
2390
@@ -4373,6 +4448,15 @@ class ListWorkflowsInput:
4373
4448
rpc_timeout : Optional [timedelta ]
4374
4449
4375
4450
4451
+ @dataclass
4452
+ class CountWorkflowsInput :
4453
+ """Input for :py:meth:`OutboundInterceptor.count_workflows`."""
4454
+
4455
+ query : Optional [str ]
4456
+ rpc_metadata : Mapping [str , str ]
4457
+ rpc_timeout : Optional [timedelta ]
4458
+
4459
+
4376
4460
@dataclass
4377
4461
class QueryWorkflowInput :
4378
4462
"""Input for :py:meth:`OutboundInterceptor.query_workflow`."""
@@ -4669,6 +4753,12 @@ def list_workflows(
4669
4753
"""Called for every :py:meth:`Client.list_workflows` call."""
4670
4754
return self .next .list_workflows (input )
4671
4755
4756
+ async def count_workflows (
4757
+ self , input : CountWorkflowsInput
4758
+ ) -> WorkflowExecutionCount :
4759
+ """Called for every :py:meth:`Client.count_workflows` call."""
4760
+ return await self .next .count_workflows (input )
4761
+
4672
4762
async def query_workflow (self , input : QueryWorkflowInput ) -> Any :
4673
4763
"""Called for every :py:meth:`WorkflowHandle.query` call."""
4674
4764
return await self .next .query_workflow (input )
@@ -4928,6 +5018,21 @@ def list_workflows(
4928
5018
) -> WorkflowExecutionAsyncIterator :
4929
5019
return WorkflowExecutionAsyncIterator (self ._client , input )
4930
5020
5021
+ async def count_workflows (
5022
+ self , input : CountWorkflowsInput
5023
+ ) -> WorkflowExecutionCount :
5024
+ return WorkflowExecutionCount ._from_raw (
5025
+ await self ._client .workflow_service .count_workflow_executions (
5026
+ temporalio .api .workflowservice .v1 .CountWorkflowExecutionsRequest (
5027
+ namespace = self ._client .namespace ,
5028
+ query = input .query or "" ,
5029
+ ),
5030
+ retry = True ,
5031
+ metadata = input .rpc_metadata ,
5032
+ timeout = input .rpc_timeout ,
5033
+ )
5034
+ )
5035
+
4931
5036
async def query_workflow (self , input : QueryWorkflowInput ) -> Any :
4932
5037
req = temporalio .api .workflowservice .v1 .QueryWorkflowRequest (
4933
5038
namespace = self ._client .namespace ,
0 commit comments