---
title: variables
sidebarTitle: variables
---

# `prefect.variables`

## Classes

### `Variable` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L17" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>


Variables are named, mutable JSON values that can be shared across tasks and flows.

**Args:**
- `name`: A string identifying the variable.
- `value`: A string that is the value of the variable.
- `tags`: An optional list of strings to associate with the variable.


**Methods:**

#### `aget` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L143" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
aget(cls, name: str) -> T | None
```

#### `aget` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L150" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
aget(cls, name: str, default: T) -> T
```

#### `aget` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L157" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
aget(cls, name: str, default: StrictVariableValue | None = None) -> StrictVariableValue | None
```

Asynchronously get a variable's value by name.

If the variable does not exist, return the default value.

**Args:**
- `- name`: The name of the variable value to get.
- `- default`: The default value to return if the variable does not exist.


#### `aset` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L41" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
aset(cls, name: str, value: StrictVariableValue, tags: Optional[list[str]] = None, overwrite: bool = False) -> 'Variable'
```

Asynchronously sets a new variable. If one exists with the same name, must pass `overwrite=True`

Returns the newly set variable object.

**Args:**
- `- name`: The name of the variable to set.
- `- value`: The value of the variable to set.
- `- tags`: An optional list of strings to associate with the variable.
- `- overwrite`: Whether to overwrite the variable if it already exists.


#### `aunset` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L255" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
aunset(cls, name: str) -> bool
```

Asynchronously unset a variable by name.

**Args:**
- `- name`: The name of the variable to unset.

Returns `True` if the variable was deleted, `False` if the variable did not exist.


#### `get` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L199" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
get(cls, name: str) -> T | None
```

#### `get` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L206" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
get(cls, name: str, default: T) -> T
```

#### `get` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L214" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
get(cls, name: str, default: StrictVariableValue | None = None) -> StrictVariableValue | None
```

Get a variable's value by name.

If the variable does not exist, return the default value.

**Args:**
- `- name`: The name of the variable value to get.
- `- default`: The default value to return if the variable does not exist.


#### `set` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L94" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
set(cls, name: str, value: StrictVariableValue, tags: Optional[list[str]] = None, overwrite: bool = False) -> 'Variable'
```

Sets a new variable. If one exists with the same name, must pass `overwrite=True`

Returns the newly set variable object.

**Args:**
- `- name`: The name of the variable to set.
- `- value`: The value of the variable to set.
- `- tags`: An optional list of strings to associate with the variable.
- `- overwrite`: Whether to overwrite the variable if it already exists.


#### `unset` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/variables.py#L284" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
unset(cls, name: str) -> bool
```

Unset a variable by name.

**Args:**
- `- name`: The name of the variable to unset.

Returns `True` if the variable was deleted, `False` if the variable did not exist.

