Caelan Schneider
03/08/2024, 2:16 PMScout
03/08/2024, 2:16 PM@multi_asset
, you can inspect the outs
parameter of the @multi_asset
decorator. The outs
parameter is a dictionary that maps output names to AssetOut
objects, which represent the produced assets. Each AssetOut
object can have an AssetKey
associated with it, which uniquely identifies the asset. Here's an example from the documentation that illustrates how you might define a @multi_asset
with multiple outputs: python @multi_asset( outs={ "output1": AssetOut(key=AssetKey(["group_name", "output1"])), "output2": AssetOut(key=AssetKey(["group_name", "output2"])), } ) def my_multi_asset(context): # Your computation logic here ...
In this example, the @multi_asset
produces two assets with keys AssetKey(["group_name", "output1"])
and AssetKey(["group_name", "output2"])
. To get a list of these asset keys, you would iterate over the values of the outs
dictionary and collect the keys: python asset_keys = [asset_out.key for asset_out in my_multi_asset.outs.values()]
This would give you a list of AssetKey
objects representing the assets produced by the @multi_asset
. Keep in mind that this is a conceptual explanation; the exact way to access the outs
attribute will depend on the context in which you're working with the @multi_asset
.Caelan Schneider
03/08/2024, 2:17 PMScout
03/08/2024, 2:17 PMmulti_asset
decorator is used to define a computation that produces multiple assets. However, the multi_asset
object itself, as defined by the decorator, does not directly expose a method or property to retrieve the list of asset keys it produces. The asset keys are defined in the outs
parameter of the multi_asset
decorator, which maps output names to AssetOut
objects. If you want to programmatically access the asset keys produced by a multi_asset
, you would typically do so by inspecting the outs
parameter of the decorator in the code where the multi_asset
is defined. This is a static analysis approach and would require you to look at the source code or the metadata of the multi_asset
definition. As of my knowledge cutoff date in April 2023, there is no built-in function or method provided by Dagster that allows you to dynamically retrieve the list of asset keys from the multi_asset
object itself after it has been defined. If such functionality is required, it would likely involve introspection or reflection techniques specific to the Python programming language, or it would require a feature update from Dagster that provides this capability. For dynamic scenarios or when working with the Dagster system at runtime, you would typically interact with the asset catalog or asset graph within the Dagster instance to query and retrieve information about assets, including their keys. However, this would not be done through the multi_asset
object directly but rather through Dagster's APIs for asset introspection. If you need to retrieve asset keys at runtime or from an instance of Dagster, you may want to explore Dagster's asset catalog or asset graph APIs, which can provide information about the assets that are part of your Dagster repository. These APIs allow you to query the system for assets and their metadata, which includes asset keys.