Skip to content

prefect.cli.variable

delete async

Delete a variable.

Parameters:

Name Type Description Default
name str

the name of the variable to delete

required
Source code in prefect/cli/variable.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@variable_app.command("delete")
async def delete(
    name: str,
):
    """
    Delete a variable.

    Arguments:
        name: the name of the variable to delete
    """

    async with get_client() as client:
        try:
            await client.delete_variable_by_name(
                name=name,
            )
        except ObjectNotFound:
            exit_with_error(f"Variable {name!r} not found.")

        exit_with_success(f"Deleted variable {name!r}.")

inspect async

View details about a variable.

Parameters:

Name Type Description Default
name str

the name of the variable to inspect

required
Source code in prefect/cli/variable.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@variable_app.command("inspect")
async def inspect(
    name: str,
):
    """
    View details about a variable.

    Arguments:
        name: the name of the variable to inspect
    """

    async with get_client() as client:
        variable = await client.read_variable_by_name(
            name=name,
        )
        if not variable:
            exit_with_error(f"Variable {name!r} not found.")

        app.console.print(Pretty(variable))

list_variables async

List variables.

Source code in prefect/cli/variable.py
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
@variable_app.command("ls")
async def list_variables(
    limit: int = typer.Option(
        100,
        "--limit",
        help="The maximum number of variables to return.",
    ),
):
    """
    List variables.
    """
    async with get_client() as client:
        variables = await client.read_variables(
            limit=limit,
        )

        table = Table(
            title="Variables",
            caption="List Variables using `prefect variable ls`",
            show_header=True,
        )

        table.add_column("Name", style="blue", no_wrap=True)
        # values can be up 5000 characters so truncate early
        table.add_column("Value", style="blue", no_wrap=True, max_width=50)
        table.add_column("Created", style="blue", no_wrap=True)
        table.add_column("Updated", style="blue", no_wrap=True)

        for variable in sorted(variables, key=lambda x: f"{x.name}"):
            table.add_row(
                variable.name,
                variable.value,
                pendulum.instance(variable.created).diff_for_humans(),
                pendulum.instance(variable.updated).diff_for_humans(),
            )

        app.console.print(table)