Customizing existing component types
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 customize the behavior of a component beyond what is available in the component.yaml
file by creating a subclass of the component type.
There are two ways you can customize a component:
- For one-off customizations, you can create a local component type, defined in a Python file in the same directory as your
component.yaml
file. Customarily, this local component type is defined in a file namedcomponent.py
in the component directory. - For customizations which may be reused across multiple components, you can create a global component type, defined in a Python file in the
lib
directory. This requires that your project is adg
plugin (projects scaffolded using thedg
CLI are automatically plugins).
Creating a customized component type
We'll use the SlingReplicationCollectionComponent
as an example. First, we'll scaffold a project with the dg
CLI:
dg scaffold project my-project \
&& cd my-project/src \
&& uv add dagster-sling \
&& dg scaffold dagster_sling.SlingReplicationCollectionComponent my_sling_sync
tree my_project/defs
my_project/defs
├── __init__.py
└── my_sling_sync
├── component.yaml
└── replication.yaml
2 directories, 3 files
- Local component type
- Global component type
To define a local component type, you can create a subclass of your desired component in a file named component.py
in the same directory as your component.yaml
file:
from dagster_sling import SlingReplicationCollectionComponent
class CustomSlingReplicationComponent(SlingReplicationCollectionComponent):
"""Customized Sling component."""
Then, we update the type
field in our component.yaml
file to reference this new component type. It should be the fully qualified name of the type:
type: my_project.defs.my_sling_sync.component.CustomSlingReplicationComponent
attributes:
replications:
- path: replication.yaml
tree my_project
my_project
├── __init__.py
├── definitions.py
├── defs