Miguel Moncada
01/24/2025, 10:06 AMVariable.get()
... changed at all between versions 2.19 and 3.x?? do you still access it via Variable.get("var_name").value
?Marvin
01/24/2025, 10:06 AMVariable.get()
has indeed changed from version 2.x. In Prefect 2.x, you accessed a variable's value directly with Variable.get("var_name")
. There was no need to append .value
to retrieve the value, as Variable.get()
would return the value directly.
In Prefect 3.x, you still use Variable.get()
to access variable values, and it remains a synchronous method in non-async contexts. Here's how you would typically access a variable:
python
from prefect.variables import Variable
# Synchronous context
value = Variable.get("var_name")
print(value)
For asynchronous contexts, Prefect 3.x introduces Variable.aget()
for async retrieval:
python
from prefect.variables import Variable
# Asynchronous context
async def my_flow():
value = await Variable.aget("var_name")
print(value)
You can find more details in the Prefect 3.x documentation on variables.
In short, the method to retrieve a variable's value remains straightforward, but Prefect 3.x introduces async capabilities for more flexible usage.