<@ULVA73B9P> has `Variable.get()`... changed at al...
# ask-community
m
@Marvin has
Variable.get()
... changed at all between versions 2.19 and 3.x?? do you still access it via
Variable.get("var_name").value
?
m
In Prefect 3.x, the usage of
Variable.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:
Copy code
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:
Copy code
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.