---
sidebar:
  hidden: true
title: roboto.domain.actions.stats
---
## Module Contents

### ActionStatsRecord

```python
class roboto.domain.actions.stats.ActionStatsRecord(/, **data: Any)
```

`from roboto.domain.actions import ActionStatsRecord`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/actions/stats.py#L17-L37)

Bases: `pydantic.BaseModel`

Data record of one action's invocation counts over a time range, as the Roboto API returns it.

`get_action_stats` returns one per action. Each count is the number of times an invocation of the action entered a status during the time range, so a failed invocation that Roboto retries counts once per attempt.

**Parameters**

- **data** (`Any`)

**Attributes**

- **ActionStatsRecord.action_name** (`str`): Name of the action, unique within the organization that owns it.
- **ActionStatsRecord.action_org_id** (`str`): ID of the organization that owns the action.
- **ActionStatsRecord.completed_count** (`int`): Number of times an invocation of the action completed during the time range.
- **ActionStatsRecord.fail_count** (`int`): Number of times an invocation of the action failed during the time range.
- **ActionStatsRecord.queued_count** (`int`): Number of times an invocation of the action was queued during the time range.

### get_action_stats()

```python
def roboto.domain.actions.stats.get_action_stats(
    start_time: datetime.datetime,
    end_time: datetime.datetime,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    org_id: Optional[str] = None,
) -> list[ActionStatsRecord]
```

`from roboto.domain.actions.stats import get_action_stats`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/actions/stats.py#L40-L83)

Fetch invocation counts by status for each action an organization invoked during a time range.

Counts the invocations that run in the organization, including those of actions another organization owns.

**Parameters**

- **start_time** (`datetime.datetime`): Exclusive start of the time range.
- **end_time** (`datetime.datetime`): Exclusive end of the time range.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).
- **org_id** (`Optional[str]`): Organization to count invocations in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.

**Returns**

- `list[ActionStatsRecord]`: One `ActionStatsRecord` per action with an invocation that was queued, completed or failed during the time range, highest `queued_count` first, up to 1,000 actions.

**Usage**

Print each action's counts for the last 24 hours:

```python
import datetime
from roboto.domain.actions.stats import get_action_stats
end_time = datetime.datetime.now(datetime.timezone.utc)
start_time = end_time - datetime.timedelta(days=1)
for stat in get_action_stats(start_time, end_time, org_id="og_12345"):
    print(f"{stat.action_name}: {stat.completed_count} completed, {stat.fail_count} failed")
```
