Adding Dagster Component definitions to your project
You can scaffold Dagster Component definitions in your project from the command line with the dg scaffold defs
command, which will create a new directory inside your defs/
folder that contains a defs.yaml
file.
Before scaffolding a component definition, you must either create a components-ready Dagster project or migrate an existing project to dg
.
Viewing available components
You can view the available components in your environment by running the following command:
dg list components
If the component you want to use is not available in your environment, you will need to install it with uv add
or pip install
. For example, to install the dbt project component, you would run:
- uv
- pip
uv add dagster-dbt
pip install dagster-dbt
For more information on integrations available as Dagster components, see the integrations documentation.
Viewing component documentation
To see automatically generated documentation for all components in your environment, you can run dg dev
to start the webserver and navigate to the Docs
tab for your project's code location:
dg dev
Scaffolding a component definition
Once you've decided on the component that you'd like to use, you can scaffold a definition for it by running dg scaffold defs <component> <component-path>
. This will create a new directory inside your defs/
folder that contains a defs.yaml
file.
For example, to scaffold a dbt project component definition, you would run:
dg scaffold defs dagster_dbt.DbtProjectComponent jdbt --project-path dbt/jdbt
Some components may require different arguments to be passed on the command line, or generate additional files when scaffolded.
You can run dg scaffold defs
from within any directory in your project and the resulting files will always be created in the <project-name>/src/<project_name>/defs/
folder.
Python-formatted component definitions
To scaffold a component definition formatted in Python instead of YAML, you can use the dg scaffold defs
command with the --format python
option. For example, the following command will generate a component.py
file for the dbt project component rather than a defs.yaml
file:
dg scaffold defs dagster_dbt.DbtProjectComponent jdbt --project-path dbt/jdbt --format python
cd src/hello_world && tree
.
├── __init__.py
├── definitions.py
├── defs
│ ├── __init__.py