Skip to content

CLI

laktory.cli.version() ¤

Return installed laktory version and installed dependencies.

Examples:

laktory version
References
Source code in laktory/cli/_version.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@app.command()
def version():
    """
    Return installed laktory version and installed dependencies.

    Examples
    --------
    ```cmd
    laktory version
    ```

    References
    ----------
    * [CLI](https://www.laktory.ai/concepts/cli/)
    """
    print(show_version_info())

laktory.cli.build(environment=None, filepath='./stack.yaml', var=[], var_file=None) ¤

Build temporary files and python packages into settings.build_root if specified or default cache dir if not. These files may also be used when deployment is delegated to third parties like Databricks Declarative Bundles.

PARAMETER DESCRIPTION
environment

Name of the environment.

TYPE: Annotated[str, Option(--env, -e, help='Name of the environment')] DEFAULT: None

filepath

Stack (yaml) filepath.

TYPE: Annotated[str, Option(help='Stack (yaml) filepath.')] DEFAULT: './stack.yaml'

var

Variable override as key=value. Can be repeated. Overrides variables defined in the stack YAML and in --var-file.

TYPE: Annotated[list[str], Option(--var, help='Variable override as key=value. Can be repeated.')] DEFAULT: []

var_file

Path to a YAML file of variable overrides. If not provided, a variables[.{env}].yaml file next to the stack file is used automatically when present.

TYPE: Annotated[str, Option(--var - file, help='YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.')] DEFAULT: None

Examples:

laktory build --env dev
laktory build --env dev --var profile=MY_PROFILE
Source code in laktory/cli/_build.py
 9
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
@app.command()
def build(
    environment: Annotated[
        str, typer.Option("--env", "-e", help="Name of the environment")
    ] = None,
    filepath: Annotated[
        str, typer.Option(help="Stack (yaml) filepath.")
    ] = "./stack.yaml",
    var: Annotated[
        list[str],
        typer.Option("--var", help="Variable override as key=value. Can be repeated."),
    ] = [],
    var_file: Annotated[
        str,
        typer.Option(
            "--var-file",
            help="YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.",
        ),
    ] = None,
):
    """
    Build temporary files and python packages into `settings.build_root` if
    specified or default cache dir if not. These files may also be used when
    deployment is delegated to third parties like Databricks Declarative Bundles.

    Parameters
    ----------
    environment:
        Name of the environment.
    filepath:
        Stack (yaml) filepath.
    var:
        Variable override as `key=value`. Can be repeated. Overrides variables
        defined in the stack YAML and in `--var-file`.
    var_file:
        Path to a YAML file of variable overrides. If not provided, a
        `variables[.{env}].yaml` file next to the stack file is used automatically
        when present.

    Examples
    --------
    ```cmd
    laktory build --env dev
    laktory build --env dev --var profile=MY_PROFILE
    ```
    """
    controller = CLIController(
        env=environment,
        stack_filepath=filepath,
        var_list=var,
        var_file_path=var_file,
    )

    # Call
    controller.build()

laktory.cli.validate(environment=None, filepath='./stack.yaml', var=[], var_file=None) ¤

Validate configuration and resources.

PARAMETER DESCRIPTION
environment

Name of the environment.

TYPE: Annotated[str, Option(--env, -e, help='Name of the environment')] DEFAULT: None

filepath

Stack (yaml) filepath.

TYPE: Annotated[str, Option(help='Stack (yaml) filepath.')] DEFAULT: './stack.yaml'

var

Variable override as key=value. Can be repeated. Overrides variables defined in the stack YAML and in --var-file.

TYPE: Annotated[list[str], Option(--var, help='Variable override as key=value. Can be repeated.')] DEFAULT: []

var_file

Path to a YAML file of variable overrides. If not provided, a variables[.{env}].yaml file next to the stack file is used automatically when present.

TYPE: Annotated[str, Option(--var - file, help='YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.')] DEFAULT: None

Examples:

laktory validate --env dev
laktory validate --env dev --var profile=MY_PROFILE
References
Source code in laktory/cli/_validate.py
 9
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
@app.command()
def validate(
    environment: Annotated[
        str, typer.Option("--env", "-e", help="Name of the environment")
    ] = None,
    filepath: Annotated[
        str, typer.Option(help="Stack (yaml) filepath.")
    ] = "./stack.yaml",
    var: Annotated[
        list[str],
        typer.Option("--var", help="Variable override as key=value. Can be repeated."),
    ] = [],
    var_file: Annotated[
        str,
        typer.Option(
            "--var-file",
            help="YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.",
        ),
    ] = None,
):
    """
    Validate configuration and resources.

    Parameters
    ----------
    environment:
        Name of the environment.
    filepath:
        Stack (yaml) filepath.
    var:
        Variable override as `key=value`. Can be repeated. Overrides variables
        defined in the stack YAML and in `--var-file`.
    var_file:
        Path to a YAML file of variable overrides. If not provided, a
        `variables[.{env}].yaml` file next to the stack file is used automatically
        when present.

    Examples
    --------
    ```cmd
    laktory validate --env dev
    laktory validate --env dev --var profile=MY_PROFILE
    ```

    References
    ----------
    * [CLI](https://www.laktory.ai/concepts/cli/)
    """
    controller = CLIController(
        env=environment,
        stack_filepath=filepath,
        var_list=var,
        var_file_path=var_file,
    )

    # Shortcut to call resources cross-reference validation (_check_depends_on)
    controller.stack.to_terraform(
        env_name=controller.env, vars=controller.cli_vars or None
    )

laktory.cli.preview(environment=None, filepath='./stack.yaml', options=None, var=[], var_file=None) ¤

Validate configuration and resources and preview deployment.

PARAMETER DESCRIPTION
environment

Name of the environment.

TYPE: Annotated[str, Option(--env, -e, help='Name of the environment')] DEFAULT: None

filepath

Stack (yaml) filepath.

TYPE: Annotated[str, Option(help='Stack (yaml) filepath.')] DEFAULT: './stack.yaml'

options

Comma separated IaC backend options (flags).

TYPE: Annotated[str, Option(--options, help='Comma separated IaC backend options (flags).')] DEFAULT: None

var

Variable override as key=value. Can be repeated. Overrides variables defined in the stack YAML and in --var-file.

TYPE: Annotated[list[str], Option(--var, help='Variable override as key=value. Can be repeated.')] DEFAULT: []

var_file

Path to a YAML file of variable overrides. If not provided, a variables[.{env}].yaml file next to the stack file is used automatically when present.

TYPE: Annotated[str, Option(--var - file, help='YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.')] DEFAULT: None

Examples:

laktory preview --env dev
laktory preview --env dev --var profile=MY_PROFILE
References
Source code in laktory/cli/_preview.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
@app.command()
def preview(
    environment: Annotated[
        str, typer.Option("--env", "-e", help="Name of the environment")
    ] = None,
    filepath: Annotated[
        str, typer.Option(help="Stack (yaml) filepath.")
    ] = "./stack.yaml",
    options: Annotated[
        str,
        typer.Option("--options", help="Comma separated IaC backend options (flags)."),
    ] = None,
    var: Annotated[
        list[str],
        typer.Option("--var", help="Variable override as key=value. Can be repeated."),
    ] = [],
    var_file: Annotated[
        str,
        typer.Option(
            "--var-file",
            help="YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.",
        ),
    ] = None,
):
    """
    Validate configuration and resources and preview deployment.

    Parameters
    ----------
    environment:
        Name of the environment.
    filepath:
        Stack (yaml) filepath.
    options:
        Comma separated IaC backend options (flags).
    var:
        Variable override as `key=value`. Can be repeated. Overrides variables
        defined in the stack YAML and in `--var-file`.
    var_file:
        Path to a YAML file of variable overrides. If not provided, a
        `variables[.{env}].yaml` file next to the stack file is used automatically
        when present.

    Examples
    --------
    ```cmd
    laktory preview --env dev
    laktory preview --env dev --var profile=MY_PROFILE
    ```

    References
    ----------
    * [CLI](https://www.laktory.ai/concepts/cli/)
    * terraform [plan](https://developer.hashicorp.com/terraform/cli/commands/plan)
    """
    controller = CLIController(
        env=environment,
        stack_filepath=filepath,
        options_str=options,
        var_list=var,
        var_file_path=var_file,
    )

    # Call
    if controller.iac_backend == "terraform":
        controller.terraform_call("plan")
    else:
        raise ValueError(f"backend should be {SUPPORTED_BACKENDS}")

laktory.cli.deploy(environment=None, filepath='./stack.yaml', auto_approve=False, options=None, var=[], var_file=None) ¤

Execute deployment.

PARAMETER DESCRIPTION
environment

Name of the environment.

TYPE: Annotated[str, Option(--env, -e, help='Name of the environment')] DEFAULT: None

filepath

Stack (yaml) filepath.

TYPE: Annotated[str, Option(help='Stack (yaml) filepath.')] DEFAULT: './stack.yaml'

auto_approve

Automatically approve and perform the update after previewing it

TYPE: Annotated[bool, Option(--yes, -y, help='Automatically approve and perform the update after previewing it')] DEFAULT: False

options

Comma separated IaC backend options (flags).

TYPE: Annotated[str, Option(--options, help='Comma separated IaC backend options (flags).')] DEFAULT: None

var

Variable override as key=value. Can be repeated. Overrides variables defined in the stack YAML and in --var-file.

TYPE: Annotated[list[str], Option(--var, help='Variable override as key=value. Can be repeated.')] DEFAULT: []

var_file

Path to a YAML file of variable overrides. If not provided, a variables[.{env}].yaml file next to the stack file is used automatically when present.

TYPE: Annotated[str, Option(--var - file, help='YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.')] DEFAULT: None

Examples:

laktory deploy --env dev --filepath my-stack.yaml
laktory deploy --env dev --var profile=MY_PROFILE --var node_type=Standard_DS3_v2
laktory deploy --env dev --var-file variables.yaml
References
Source code in laktory/cli/_deploy.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
@app.command()
def deploy(
    environment: Annotated[
        str, typer.Option("--env", "-e", help="Name of the environment")
    ] = None,
    filepath: Annotated[
        str, typer.Option(help="Stack (yaml) filepath.")
    ] = "./stack.yaml",
    auto_approve: Annotated[
        bool,
        typer.Option(
            "--yes",
            "-y",
            help="Automatically approve and perform the update after previewing it",
        ),
    ] = False,
    options: Annotated[
        str,
        typer.Option("--options", help="Comma separated IaC backend options (flags)."),
    ] = None,
    var: Annotated[
        list[str],
        typer.Option("--var", help="Variable override as key=value. Can be repeated."),
    ] = [],
    var_file: Annotated[
        str,
        typer.Option(
            "--var-file",
            help="YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.",
        ),
    ] = None,
):
    """
    Execute deployment.

    Parameters
    ----------
    environment:
        Name of the environment.
    filepath:
        Stack (yaml) filepath.
    auto_approve:
        Automatically approve and perform the update after previewing it
    options:
        Comma separated IaC backend options (flags).
    var:
        Variable override as `key=value`. Can be repeated. Overrides variables
        defined in the stack YAML and in `--var-file`.
    var_file:
        Path to a YAML file of variable overrides. If not provided, a
        `variables[.{env}].yaml` file next to the stack file is used automatically
        when present.

    Examples
    --------
    ```cmd
    laktory deploy --env dev --filepath my-stack.yaml
    laktory deploy --env dev --var profile=MY_PROFILE --var node_type=Standard_DS3_v2
    laktory deploy --env dev --var-file variables.yaml
    ```

    References
    ----------
    * [CLI](https://www.laktory.ai/concepts/cli/)
    * terraform [apply](https://developer.hashicorp.com/terraform/cli/commands/apply)
    """
    controller = CLIController(
        env=environment,
        auto_approve=auto_approve,
        stack_filepath=filepath,
        options_str=options,
        var_list=var,
        var_file_path=var_file,
    )

    # Call
    if controller.iac_backend == "terraform":
        controller.terraform_call("apply")
    else:
        raise ValueError(f"backend should be {SUPPORTED_BACKENDS}")

laktory.cli.run(databricks_job=None, databricks_pipeline=None, timeout=1200, raise_exception=True, full_refresh=False, current_run_action='WAIT', environment=None, filepath='./stack.yaml', var=[], var_file=None) ¤

Execute remote job or DLT pipeline and monitor failures until completion.

PARAMETER DESCRIPTION
databricks_job

Name of the job to run (mutually exclusive with dlt)

TYPE: Annotated[str, Option(--databricks - job, help='Databricks job name')] DEFAULT: None

databricks_pipeline

Name of the DLT pipeline to run (mutually exclusive with job)

TYPE: Annotated[str, Option(--databricks - pipeline, help='Databricks pipeline name')] DEFAULT: None

timeout

Maximum allowed time (in seconds) for run.

TYPE: Annotated[float, Option(--timeout, -t, help='Maximum allowed time (in seconds) for run')] DEFAULT: 1200

raise_exception

Raise exception on failure

TYPE: Annotated[bool, Option('--raise', -r, help='Raise exception on failure')] DEFAULT: True

current_run_action

Action to take for currently running job or pipline.

TYPE: Annotated[str, Option(--action, -a, help="Action to take if job currently running ['WAIT', 'CANCEL', 'FAIL']")] DEFAULT: 'WAIT'

full_refresh

Full tables refresh (pipline only)

TYPE: Annotated[bool, Option(--full - refresh, help='Full tables refresh (pipeline only)')] DEFAULT: False

environment

Name of the environment.

TYPE: Annotated[str, Option(--env, -e, help='Name of the environment')] DEFAULT: None

filepath

Stack (yaml) filepath.

TYPE: Annotated[str, Option(help='Stack (yaml) filepath.')] DEFAULT: './stack.yaml'

var

Variable override as key=value. Can be repeated. Overrides variables defined in the stack YAML and in --var-file.

TYPE: Annotated[list[str], Option(--var, help='Variable override as key=value. Can be repeated.')] DEFAULT: []

var_file

Path to a YAML file of variable overrides. If not provided, a variables[.{env}].yaml file next to the stack file is used automatically when present.

TYPE: Annotated[str, Option(--var - file, help='YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.')] DEFAULT: None

Examples:

laktory run --env dev --databricks-pipeline pl-stock-prices --full-refresh --action CANCEL
laktory run --env dev --databricks-job my-job --var profile=MY_PROFILE
References
Source code in laktory/cli/_run.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
 96
 97
 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
123
124
125
126
127
128
129
@app.command()
def run(
    databricks_job: Annotated[
        str, typer.Option("--databricks-job", help="Databricks job name")
    ] = None,
    databricks_pipeline: Annotated[
        str, typer.Option("--databricks-pipeline", help="Databricks pipeline name")
    ] = None,
    timeout: Annotated[
        float,
        typer.Option(
            "--timeout", "-t", help="Maximum allowed time (in seconds) for run"
        ),
    ] = 1200,
    raise_exception: Annotated[
        bool, typer.Option("--raise", "-r", help="Raise exception on failure")
    ] = True,
    full_refresh: Annotated[
        bool,
        typer.Option("--full-refresh", help="Full tables refresh (pipeline only)"),
    ] = False,
    current_run_action: Annotated[
        str,
        typer.Option(
            "--action",
            "-a",
            help="Action to take if job currently running ['WAIT', 'CANCEL', 'FAIL']",
        ),
    ] = "WAIT",
    environment: Annotated[
        str, typer.Option("--env", "-e", help="Name of the environment")
    ] = None,
    filepath: Annotated[
        str, typer.Option(help="Stack (yaml) filepath.")
    ] = "./stack.yaml",
    var: Annotated[
        list[str],
        typer.Option("--var", help="Variable override as key=value. Can be repeated."),
    ] = [],
    var_file: Annotated[
        str,
        typer.Option(
            "--var-file",
            help="YAML file of variable overrides. Auto-discovers variables[.{env}].yaml if not set.",
        ),
    ] = None,
):
    """
    Execute remote job or DLT pipeline and monitor failures until completion.

    Parameters
    ----------
    databricks_job:
        Name of the job to run (mutually exclusive with dlt)
    databricks_pipeline:
        Name of the DLT pipeline to run (mutually exclusive with job)
    timeout:
        Maximum allowed time (in seconds) for run.
    raise_exception:
        Raise exception on failure
    current_run_action:
        Action to take for currently running job or pipline.
    full_refresh:
        Full tables refresh (pipline only)
    environment:
        Name of the environment.
    filepath:
        Stack (yaml) filepath.
    var:
        Variable override as `key=value`. Can be repeated. Overrides variables
        defined in the stack YAML and in `--var-file`.
    var_file:
        Path to a YAML file of variable overrides. If not provided, a
        `variables[.{env}].yaml` file next to the stack file is used automatically
        when present.

    Examples
    --------
    ```cmd
    laktory run --env dev --databricks-pipeline pl-stock-prices --full-refresh --action CANCEL
    laktory run --env dev --databricks-job my-job --var profile=MY_PROFILE
    ```

    References
    ----------
    * [CLI](https://www.laktory.ai/concepts/cli/)

    """
    # Set Resource Name
    if databricks_job and databricks_pipeline:
        raise ValueError("Only one of `job` or `dlt` should be set.")
    if not (databricks_job or databricks_pipeline):
        raise ValueError("One of `job` or `dlt` should be set.")

    # Set Dispatcher
    controller = CLIController(
        env=environment,
        stack_filepath=filepath,
        var_list=var,
        var_file_path=var_file,
    )
    dispatcher = Dispatcher(stack=controller.stack, env=controller.env)
    dispatcher.get_resource_ids()

    if databricks_job:
        dispatcher.run_databricks_job(
            job_name=databricks_job,
            timeout=timeout,
            raise_exception=raise_exception,
            current_run_action=current_run_action,
        )

    if databricks_pipeline:
        dispatcher.run_databricks_pipeline(
            pipeline_name=databricks_pipeline,
            timeout=timeout,
            raise_exception=raise_exception,
            current_run_action=current_run_action,
            full_refresh=full_refresh,
        )

laktory.cli.setup_agent(agent=None, no_mcp=False) ¤

Set up AI coding-agent support in the current directory.

Writes agent instruction files and (by default) .mcp.json for the Laktory MCP server. Safe to run on existing projects — all writes are idempotent.

Use --agent to skip the interactive prompt:

  • claude → .claude/docs/laktory.md + @import in CLAUDE.md
  • copilot → .github/instructions/laktory.instructions.md + reference in AGENTS.md
  • other → AGENTS_LAKTORY.md + reference in AGENTS.md

Use --no-mcp to write only the instruction files without the MCP server configuration (useful in restricted environments).

Examples:

laktory setup-agent
laktory setup-agent --agent claude
laktory setup-agent --agent claude --no-mcp
References
Source code in laktory/cli/_setup_agent.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
@app.command()
def setup_agent(
    agent: Annotated[
        Optional[str],
        typer.Option(
            "--agent",
            "-a",
            help=f"Agent framework {AGENT_CHOICES}",
        ),
    ] = None,
    no_mcp: Annotated[
        bool,
        typer.Option(
            "--no-mcp",
            help="Skip writing .mcp.json (instruction files are still written)",
        ),
    ] = False,
):
    """
    Set up AI coding-agent support in the current directory.

    Writes agent instruction files and (by default) .mcp.json for the Laktory
    MCP server. Safe to run on existing projects — all writes are idempotent.

    Use --agent to skip the interactive prompt:

    - claude   → .claude/docs/laktory.md + @import in CLAUDE.md
    - copilot  → .github/instructions/laktory.instructions.md + reference in AGENTS.md
    - other    → AGENTS_LAKTORY.md + reference in AGENTS.md

    Use --no-mcp to write only the instruction files without the MCP server
    configuration (useful in restricted environments).

    Examples
    --------
    ```cmd
    laktory setup-agent
    laktory setup-agent --agent claude
    laktory setup-agent --agent claude --no-mcp
    ```

    References
    ----------
    * [MCP](https://modelcontextprotocol.io/)
    """
    if agent is None:
        agent = prompt(
            f"Select agent {AGENT_CHOICES}: ",
            completer=WordCompleter(AGENT_CHOICES, ignore_case=True),
            validator=AgentValidator(),
        )

    agent = agent.lower()

    if agent == "claude":
        write_claude_instructions()
        write_claude_md()
    elif agent == "copilot":
        write_github_instructions()
        write_agents_md_copilot()
    else:
        write_other_instructions()

    if not no_mcp:
        write_mcp_json()