Adding Dagster definitions to a dg project
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.
You can use the dg
CLI to scaffold Dagster definitions such as assets, schedules, and sensors.
All definitions added underneath the defs
directory of a project created with the create-dagster
CLI will be automatically loaded into the top-level Definitions
object.
Prerequisites
Before scaffolding definitions with dg
, you must create a project with the create-dagster CLI
and activate its virtual environment.
1. Scaffold an asset
You can use the dg scaffold defs
command to scaffold a new asset underneath the defs
folder. In this example, we scaffold an asset named my_asset.py
and write it to the defs/assets
directory:
dg scaffold defs dagster.asset assets/my_asset.py
Creating a component at /.../my-project/src/my_project/defs/assets/my_asset.py.
Once the asset has been scaffolded, we can see that a new file has been added to defs/assets
, and view its contents:
- uv
- pip
tree
.
├── pyproject.toml
├── src
│ └── my_project
│ ├── __init__.py
│ └── defs
│ ├── __init__.py
│ └── assets
│ └── my_asset.py
├── tests
│ └── __init__.py
└── uv.lock
6 directories, 6 files
tree
.
├── pyproject.toml
├── src
│ └── my_project
│ ├── __init__.py
│ └── defs
│ ├── __init__.py
│ └── assets