prefect.variables
¶
Variable
¶
Bases: VariableCreate
Variables are named, mutable string values, much like environment variables. Variables are scoped to a Prefect server instance or a single workspace in Prefect Cloud. https://docs.prefect.io/latest/concepts/variables/
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
A string identifying the variable. |
required | |
value
|
A string that is the value of the variable. |
required | |
tags
|
An optional list of strings to associate with the variable. |
required |
Source code in prefect/variables.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
get
async
classmethod
¶
Get a variable by name. If doesn't exist return the default.
from prefect.variables import Variable
@flow
def my_flow():
var = Variable.get("my_var")
from prefect.variables import Variable
@flow
async def my_flow():
var = await Variable.get("my_var")
Source code in prefect/variables.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
set
async
classmethod
¶
Sets a new variable. If one exists with the same name, user must pass overwrite=True
from prefect.variables import Variable
@flow
def my_flow():
var = Variable.set(name="my_var",value="test_value", tags=["hi", "there"], overwrite=True)
from prefect.variables import Variable
@flow
async def my_flow():
var = await Variable.set(name="my_var",value="test_value", tags=["hi", "there"], overwrite=True)
Source code in prefect/variables.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
get
async
¶
Get a variable by name. If doesn't exist return the default.
from prefect import variables
@flow
def my_flow():
var = variables.get("my_var")
from prefect import variables
@flow
async def my_flow():
var = await variables.get("my_var")
Source code in prefect/variables.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|