Adding components to your project with Python
dg
and Dagster Components are under active development. You may encounter feature gaps, and the APIs may change. To report issues or give feedback, please join the #dg-components channel in the Dagster Community Slack.
In some cases, you may want to add a component to your project with Python rather than YAML.
Prerequisites
Before adding a component with Python, you will need to either create a components-compatible project with dg
or migrate an existing project to dg
.
Additionally, to run the example below, you will need to clone the sample dbt project and delete the embedded git repository:
git clone --depth=1 https://github.com/dagster-io/jaffle-platform.git dbt && rm -rf dbt/.git
Then install the dbt project component:
- uv
- pip
uv add dagster-dbt dbt-duckdb
pip install dagster-dbt dbt-duckdb
Steps
To add a component with Python, you can use the dg scaffold
command with the --format python
option. For example, to scaffold the dbt project component, you can run the following:
dg scaffold dagster_dbt.DbtProjectComponent jdbt --project-path dbt/jdbt --format python
Running this command will generate a component.py
file, rather than a component.yaml
file:
cd src/hello_world && tree
.
├── __init__.py
├── __pycache__
│ └── __init__.cpython-312.pyc
├── definitions.py
├── defs
│ ├── __init__.py
│ └── jdbt
│ └── component.py
└── lib
└── __init__.py