Making an existing code location components-compatible
This guide is only relevant if you are starting from an existing Dagster code location. This setup is unnecessary if you used dg code-location generate
to create your code location.
Create a components
directory
First, you'll want to create a directory to contain any new components you add to your code location. By convention, this directory is named components
, and exists at the top level of your code location's Python module.
mkdir components
Modify top-level definitions
dagster-components
provides a utility to create a Definitions
object from your components directory. Because you're working with an existing code location, you'll want to combine your existing definitions with the ones from your components directory.
To do so, you'll need to modify your definitions.py
file, or whichever file contains your top-level Definitions
object.
You can manually construct a set of definitions for your components using build_component_defs
, then merge them with your existing definitions using Definitions.merge
. You point build_components_defs
at the directory you just created that contains components.
- Before
- After
import dagster as dg
defs = dg.Definitions(assets=[])
from pathlib import Path
import dagster_components as dg_components
import dagster as dg
defs = dg.Definitions.merge(
dg.Definitions(assets=[]),
dg_components.build_component_defs(Path(__file__).parent / "components"),
)
Next steps
- Add a new component to your code location
- Create a new component type