> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# counting

# `prefect.server.events.counting`

## Classes

### `InvalidEventCountParameters` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L26](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L26)</sup>

Raised when the given parameters are invalid for counting events.

### `TimeUnit` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L34](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L34)</sup>

**Methods:**

#### `as_timedelta` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L41](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L41)</sup>

```python theme={null}
as_timedelta(self, interval: float) -> Duration
```

#### `auto` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/collections.py#L70](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/collections.py#L70)</sup>

```python theme={null}
auto() -> str
```

Exposes `enum.auto()` to avoid requiring a second import to use `AutoEnum`

#### `database_label_expression` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L145](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L145)</sup>

```python theme={null}
database_label_expression(self, db: PrefectDBInterface, time_interval: float) -> sa.Function[str]
```

Returns the SQL expression to label a time bucket

#### `database_value_expression` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L110](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L110)</sup>

```python theme={null}
database_value_expression(self, time_interval: float) -> sa.Cast[str]
```

Returns the SQL expression to place an event in a time bucket

#### `get_interval_spans` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L78](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L78)</sup>

```python theme={null}
get_interval_spans(self, start_datetime: datetime.datetime, end_datetime: datetime.datetime, interval: float) -> Generator[int | tuple[datetime.datetime, datetime.datetime], None, None]
```

Divide the given range of dates into evenly-sized spans of interval units

#### `validate_buckets` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L55](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L55)</sup>

```python theme={null}
validate_buckets(self, start_datetime: datetime.datetime, end_datetime: datetime.datetime, interval: float) -> None
```

### `Countable` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L175](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L175)</sup>

**Methods:**

#### `auto` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/collections.py#L70](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/collections.py#L70)</sup>

```python theme={null}
auto() -> str
```

Exposes `enum.auto()` to avoid requiring a second import to use `AutoEnum`

#### `get_database_query` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L183](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/events/counting.py#L183)</sup>

```python theme={null}
get_database_query(self, filter: 'EventFilter', time_unit: TimeUnit, time_interval: float) -> Select[tuple[str, str, DateTime, DateTime, int]]
```
