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.
dg
can be used to scaffold Dagster definitions such as assets, schedules, and sensors. When you use a project that has been scaffolded using dg
, any new definitions added underneath the defs
directory will be automatically loaded into the top-level Definitions
object. This allows you to easily add new definitions to your project without needing to explicitly import these definitions to your top-level definitions file.
This guide will walk through how to use dg
to scaffold a new asset.
Scaffold an asset
You can use the dg scaffold
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 this is done, we can see that a new file has been added to this location, and view its contents:
tree
.
├── pyproject.toml
├── src
│ └── my_project
│ ├── __init__.py
│ ├── components
│ │ └── __init__.py
│ ├── definitions.py
│ └── defs
│ ├── __init__.py
│ └── assets
│ └── my_asset.py
├── tests
│ └── __init__.py