<@U0667DNC02Y> can I access asset metadata program...
# ask-ai
s
@Scout can I access asset metadata programmatically from an instance of dagster._core.definitions.asset_graph.InternalAssetGraph
s
The documentation does not provide a direct example or method for accessing asset metadata programmatically from an instance of
dagster._core.definitions.asset_graph.InternalAssetGraph
. However, it does mention that the context object passed to functions decorated with
@asset
contains an instance attribute that can query the Dagster event log for metadata related to assets. For example, if you want to access metadata from a historical materialization of one asset from inside another asset, you can use the
context.instance
to get the latest materialization event and then access the metadata from that event. Here's a snippet from the documentation illustrating this approach:
Copy code
python @asset def asset1():     return Output(value=..., metadata={"num_rows": 5})  @asset  # or op def asset_1_num_rows(context):     instance = context.instance     materialization = instance.get_latest_materialization_event(AssetKey(["asset1"])).asset_materialization     return materialization.metadata["num_rows"]
This example shows how to retrieve the metadata for the number of rows from the latest materialization of
asset1
within another asset. If you are looking to interact with the
InternalAssetGraph
directly, you would typically be working with the internal APIs of Dagster, which are not covered in the user-facing documentation. The
InternalAssetGraph
is part of Dagster's core implementation and is not intended for direct manipulation by end-users. Instead, the recommended approach is to use the public APIs and the context objects provided by Dagster's decorators like
@asset
. If you need to perform operations that are not covered by the public APIs, you might need to explore the source code or reach out to the Dagster community for more specific guidance.