Introducing Prefect Variables

Prefect Variables are a lightweight way to get configuration into your code at runtime.

You can use variables to represent any string you like, in the video linked here we show how they can be given different values in different workspaces.

Read more about variables in the docs.

Here’s the demo code I used in the video:

from prefect import flow, variables

@flow(log_prints=True)
def hello():
    env = variables.get("env", default="UNKNOWN")
    print(f"This flow run is in the {env} environment")


if __name__ == "__main__":
    hello()