dbt command operators#

Cosmos exposes individual operators that correspond to specific dbt commands, which can be used just like traditional Apache Airflow® operators. Cosmos names these operators using the format Dbt<dbt-command><execution-mode>Operator.

You can see the full example DAG in the dev/dags directory.

Run#

Requires Cosmos >= 0.6.0.

The DbtRunLocalOperator implements the dbt run command.

    run_operator = DbtRunLocalOperator(
        profile_config=profile_config,
        project_dir=DBT_PROJ_DIR,
        task_id="run",
        dbt_cmd_flags=["--select", "stg_customers"],
        install_deps=True,
        append_env=True,
    )

Test#

Requires Cosmos >= 0.6.0.

The DbtTestLocalOperator implements the dbt test command.

    test_operator = DbtTestLocalOperator(
        profile_config=profile_config,
        project_dir=DBT_PROJ_DIR,
        task_id="test",
        dbt_cmd_flags=["--select", "stg_customers"],
        install_deps=True,
        append_env=True,
    )

Snapshot#

Requires Cosmos >= 0.6.0.

The DbtSnapshotLocalOperator implements the dbt snapshot command.

    snapshot_operator = DbtSnapshotLocalOperator(
        profile_config=profile_config,
        project_dir=DBT_PROJ_DIR,
        task_id="snapshot",
        install_deps=True,
        append_env=True,
    )

Build#

Requires Cosmos >= 1.4.0.

The DbtBuildLocalOperator implements the dbt build command.

    build_operator = DbtBuildLocalOperator(
        profile_config=profile_config,
        project_dir=DBT_PROJ_DIR,
        task_id="build",
        install_deps=True,
        append_env=True,
    )

Seed#

Requires Cosmos >= 0.6.0.

The DbtSeedLocalOperator implements the dbt seed command.

    seed_raw_orders = DbtSeedLocalOperator(
        profile_config=profile_config,
        project_dir=DBT_PROJ_DIR,
        task_id="seed_raw_orders",
        dbt_cmd_flags=["--select", "raw_orders"],
        install_deps=True,
    )

Clone#

Requires Cosmos >= 1.8.0.

The DbtCloneLocalOperator implements the dbt clone command.

    clone_operator = DbtCloneLocalOperator(
        profile_config=profile_config,
        project_dir=DBT_PROJ_DIR,
        task_id="clone",
        dbt_cmd_flags=["--select", "stg_customers", "--state", DBT_ARTIFACT],
        install_deps=True,
        append_env=True,
    )