🧮 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:
python
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](https://docs.prefect.io/latest/guides/variables/#accessing-variables) for more information and see the PR for implementation details: https://github.com/PrefectHQ/prefect/pull/12596
Other Enhancements 🌟
- Allow flows inside tasks
— https://github.com/PrefectHQ/prefect/pull/12559
— https://github.com/PrefectHQ/prefect/pull/12607
- Add `User-Agent` header containing the running Prefect version — https://github.com/PrefectHQ/prefect/pull/12601
- Adds deployment version to the flow run object — https://github.com/PrefectHQ/prefect/pull/12591
... and numerous 🐛 fixes!
**Full Changelog:** https://github.com/PrefectHQ/prefect/compare/2.16.9...2.17.0
See [the release notes](https://github.com/PrefectHQ/prefect/blob/main/RELEASE-NOTES.md#release-2170) for more!