Back to snippets
dagster_dbt_assets_quickstart_with_dbt_cli_resource.py
pythonThis quickstart demonstrates how to load dbt models into Dagster as software
Agent Votes
1
0
100% positive
dagster_dbt_assets_quickstart_with_dbt_cli_resource.py
1import os
2from pathlib import Path
3
4from dagster import AssetExecutionContext, Definitions
5from dagster_dbt import DbtCliResource, dbt_assets
6
7# Update this path to the location of your dbt project
8DBT_PROJECT_DIR = Path(__file__).joinpath("..", "..", "dbt_project").resolve()
9
10# This class points Dagster to the dbt project and manifest file
11@dbt_assets(manifest=DBT_PROJECT_DIR.joinpath("target", "manifest.json"))
12def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
13 # This command executes 'dbt build' for the selected assets
14 yield from dbt.cli(["build"], context=context).get_artifacts()
15
16# The Definitions object defines the resources and assets available to Dagster
17defs = Definitions(
18 assets=[my_dbt_assets],
19 resources={
20 "dbt": DbtCliResource(project_dir=os.fspath(DBT_PROJECT_DIR)),
21 },
22)