Jeff Hale
10/17/2024, 3:44 PMfrom prefect.variables import Variable
Variable.get("answer")
Shimita Rudra
10/17/2024, 3:56 PMJeff Hale
10/17/2024, 4:01 PMJeff Hale
10/17/2024, 4:04 PManswer
in the UI for the workspace I’m connected to.
from prefect.variables import Variable
var = Variable.get("answer") # answer is a variable set in the UI or code
print(var)
# prints 42
Shimita Rudra
10/17/2024, 4:06 PMJeff Hale
10/17/2024, 4:11 PMShimita Rudra
10/17/2024, 4:13 PMimport asyncio
from prefect import flow, pause_flow_run
from prefect.input import RunInput
from prefect.variables import Variable
class UserNameInput(RunInput):
name: str
@flow(log_prints=True)
async def greet_user():
user_input = await pause_flow_run(
wait_for_input=UserNameInput.with_initial_data(name="anonymous")
)
user_name_1 = Variable.get("user_name_1")
if user_input.name == "anonymous":
print("Hello,",{user_name_1}, "!")
else:
print(f"Hello, {user_input.name}!")
if __name__ == "__main__":
print("hi\n")
user_name_1 = Variable.get("user_name_1")
asyncio.run(greet_user())
Shimita Rudra
10/17/2024, 4:14 PMJeff Hale
10/17/2024, 4:25 PMuser_name_1
into greet_user
and adjust greet_user
to take that parameter.
Then the value should be available in your function.Shimita Rudra
10/17/2024, 4:38 PM