🧮 Manage Prefect variables via the Python SDK
Prefect variables are useful for storing and reusing data and configuration between and across workflows; and previously you could only create and update variables via the Prefect UI. With this release, you can now get and set Prefect variables directly in your Python code with the new Variable.set
and Variable.get
methods!
For an example of reading and writing variable values in Python see the following example:
from prefect.variables import Variable
# set a variable
variable = Variable.set(name="the_answer", value="42")
# get a variable
answer = Variable.get('the_answer')
print(answer.value)
# 42
# get a variable with a default value
answer = Variable.get('not_the_answer', default='42')
print(answer.value)
# 42
# update a variable
answer = Variable.set(name="the_answer", value="43", overwrite=True)
print(answer.value)
#43
Refer to the docs for more information and see the PR for implementation details: #12596
Other Enhancements 🌟
- Allow flows inside tasks
— #12559
— #12607 - Add
User-Agent
header containing the running Prefect version — #12601 - Adds deployment version to the flow run object — #12591
... and numerous 🐛 fixes!
Full Changelog: 2.16.9...2.17.0
See the release notes for more!