Create a variable
To create a variable stored in the Prefect backend, useVariable.set()
.
Read a variable
To read a variable, useVariable.get()
.
Variable.get(default=...)
.
Update a variable
To update a variable, useVariable.set(value, overwrite=True)
.
Delete a variable
To delete a variable, useVariable.unset()
.
Contextual BehaviorIn a sync context (such as an
if __name__ == "__main__"
block or simple def
scope), these methods are used synchronously.
In an async context (such as an async def
scope), they are used asynchronously.Use variables in prefect.yaml
deployment steps
In prefect.yaml
files, variables are expressed as strings wrapped in quotes and double curly brackets:
prefect.yaml
file that creates the deployments.
For example, you can pass in a variable to specify a branch for a git repo in a deployment pull
step:
deployment_branch
variable is evaluated at runtime for the deployed flow, allowing changes to variables used in a pull action without updating a deployment directly.