Skip to content

prefect.variables

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")
or
    from prefect import variables

    @flow
    async def my_flow():
        var = await variables.get("my_var")

Source code in prefect/variables.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@sync_compatible
async def get(name: str, default: str = None) -> Optional[str]:
    """
    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")
    ```
    or
    ```
        from prefect import variables

        @flow
        async def my_flow():
            var = await variables.get("my_var")
    ```
    """
    variable = await _get_variable_by_name(name)
    return variable.value if variable else default