Josh
02/22/2024, 3:21 PMScout
02/22/2024, 3:21 PMDagsterInstance
class to report asset events and access asset values. Here is an example of how you can use the DagsterInstance
to report an asset event: python from dagster import DagsterInstance, AssetCheckEvaluation, AssetCheckKey instance = DagsterInstance.get() instance.report_runless_asset_event( AssetCheckEvaluation( asset_key=AssetKey("example_asset"), check_name="example_check", passed=True ) )
Additionally, if you want to load an already-materialized asset's value, you can use the Definitions
class to load the asset value. Here is an example of how to do that: python from dagster import asset, materialize, Definitions, AssetKey @asset def upstream_asset(): return [1, 2, 3] @asset def downstream_asset(upstream_asset): return upstream_asset + [4] defs = Definitions(assets=[upstream_asset, downstream_asset]) if __name__ == "__main__": materialize([upstream_asset, downstream_asset]) upstream_content = defs.load_asset_value(AssetKey("upstream_asset")) downstream_content = defs.load_asset_value(AssetKey("downstream_asset")) print("Upstream asset: ", upstream_content) print("Downstream asset: ", downstream_content)
In this example, the materialize
function is used to materialize the assets, and then the load_asset_value
method of the Definitions
class is used to load the values of the materialized assets.Josh
02/22/2024, 3:23 PMScout
02/22/2024, 3:23 PM