Stefan
08/01/2025, 6:38 AMMarvin
08/01/2025, 6:38 AMMarvin
08/01/2025, 6:40 AMpython
from prefect.variables import Variable
# Set a variable
Variable.create(name="my_variable", value="my_value")
# Get a variable
my_var = Variable.get("my_variable")
Key points:
1. Variables are meant for non-sensitive configuration data. For sensitive information, use Secret blocks instead.
2. Variable names are limited to 255 characters, and values are limited to 5000 characters.
3. Values must be JSON-serializable.
4. If a variable doesn't exist when you try to get it, a ValueError
will be raised.
You can also use the optional default
parameter when getting a variable to provide a fallback value if the variable doesn't exist:
python
# Get with default value
my_var = Variable.get("my_variable", default="fallback_value")
For more information, you can refer to:
- Variables Concept Documentation
- Variables API Reference