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

# variables

# `prefect.server.models.variables`

## Functions

### `emit_variable_created_event` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L15](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L15)</sup>

```python theme={null}
emit_variable_created_event(variable: orm_models.Variable) -> None
```

Emit an event when a variable is created.

### `emit_variable_updated_event` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L21](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L21)</sup>

```python theme={null}
emit_variable_updated_event(variable: orm_models.Variable) -> None
```

Emit an event when a variable is updated.

### `emit_variable_deleted_event` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L27](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L27)</sup>

```python theme={null}
emit_variable_deleted_event(variable: orm_models.Variable) -> None
```

Emit an event when a variable is deleted.

### `create_variable` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L34](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L34)</sup>

```python theme={null}
create_variable(db: PrefectDBInterface, session: AsyncSession, variable: VariableCreate) -> orm_models.Variable
```

Create a variable

**Args:**

* `session`: async database session
* `variable`: variable to create

**Returns:**

* orm\_models.Variable

### `read_variable` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L57](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L57)</sup>

```python theme={null}
read_variable(db: PrefectDBInterface, session: AsyncSession, variable_id: UUID) -> Optional[orm_models.Variable]
```

Reads a variable by id.

### `read_variable_by_name` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L71](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L71)</sup>

```python theme={null}
read_variable_by_name(db: PrefectDBInterface, session: AsyncSession, name: str) -> Optional[orm_models.Variable]
```

Reads a variable by name.

### `read_variables` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L85](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L85)</sup>

```python theme={null}
read_variables(db: PrefectDBInterface, session: AsyncSession, variable_filter: Optional[filters.VariableFilter] = None, sort: sorting.VariableSort = sorting.VariableSort.NAME_ASC, offset: Optional[int] = None, limit: Optional[int] = None) -> Sequence[orm_models.Variable]
```

Read variables, applying filers.

### `count_variables` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L111](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L111)</sup>

```python theme={null}
count_variables(db: PrefectDBInterface, session: AsyncSession, variable_filter: Optional[filters.VariableFilter] = None) -> int
```

Count variables, applying filters.

### `update_variable` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L130](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L130)</sup>

```python theme={null}
update_variable(db: PrefectDBInterface, session: AsyncSession, variable_id: UUID, variable: VariableUpdate) -> bool
```

Updates a variable by id.

### `update_variable_by_name` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L156](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L156)</sup>

```python theme={null}
update_variable_by_name(db: PrefectDBInterface, session: AsyncSession, name: str, variable: VariableUpdate) -> bool
```

Updates a variable by name.

### `delete_variable` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L179](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L179)</sup>

```python theme={null}
delete_variable(db: PrefectDBInterface, session: AsyncSession, variable_id: UUID) -> bool
```

Delete a variable by id.

### `delete_variable_by_name` <sup>[https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L197](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/variables.py#L197)</sup>

```python theme={null}
delete_variable_by_name(db: PrefectDBInterface, session: AsyncSession, name: str) -> bool
```

Delete a variable by name.
