https://dagster.io/ logo
#ask-community
Title
# ask-community
s

Stefan Otte

06/23/2022, 3:43 PM
Hello there, I really like the new software-defined asset abstraction. But I'm having issues wrapping my head around how to use them in this context: Let's say I want to create an asset
xyz_plot
and I want to reuse this function in multiple projects, i.e.
xyz_plot
should use
project-a/data.csv
and
project-b/data.csv
(or the resulting DataFrame of the csv) as input. How do I have to define the
xyz_plot
?
Copy code
@asset
def xyz_plot(in_key: DataFrame):
    # how should in_key be really named? in_key is not fixed
🤖 1
s

sandy

06/23/2022, 8:04 PM
Hi Stefan - asset definitions contain their dependencies. If you want to have an unbound dependency, I'd recommend using an op. As of today's release, it will be possible to define an op and then build assets from it. Something like:
Copy code
project_a_data = SourceAsset(key=["project_a", "data"])

project_b_data = SourceAsset(key=["project_b", "data"])

@op
def xyz_plot(in_key: DataFrame):
    ...

plot_a = AssetsDefinition.from_op(xyz_plot, keys_by_input_name={"in_key": AssetKey(["project_a", "data"])})

plot_b = AssetsDefinition.from_op(xyz_plot, keys_by_input_name={"in_key": AssetKey(["project_b", "data"])})
❤️ 1
s

Stefan Otte

06/25/2022, 2:51 PM
@sandy perfect, this clears things up! For the ML use cases I have in mind I would use the
op
and
AssetsDefinition.from_op
approach for pretty much everything as all assets depend on an unbound dependency...I think. I have to play around with this.
(Just for completeness sake: this is the changelog for the release that adds
AssetsDefinition.from_op
https://github.com/dagster-io/dagster/releases/tag/0.15.1)
2 Views