<@U0667DNC02Y> Is there a way to access an asset v...
# ask-ai
j
@Scout Is there a way to access an asset value using an API that dagster exposes?
s
Yes, there is a way to access an asset value using an API that we expose. According to the documentation, you can use the
DagsterInstance
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:
Copy code
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:
Copy code
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.
j
@Scout I am asking if it is possible to do so without access to the pipeline code? does dagster expose any api for that?
s
We currently do not provide a direct public API for retrieving the value of a materialized asset without access to the pipeline code. The typical way to interact with assets in Dagster is through the pipeline code itself, using the Dagster framework's constructs such as assets, ops, and jobs. However, if you have a running Dagster instance, you can interact with it using the Dagit web interface to view the materializations and metadata of assets. Additionally, Dagster exposes a GraphQL API that can be used to query information about runs, assets, and other metadata, which is primarily used by Dagit. You could potentially use this GraphQL API to fetch information about assets, but it is not designed for directly retrieving the value of a materialized asset. If you need to access the value of a materialized asset programmatically, you would typically do this by accessing the underlying storage system (e.g., a database or file system) where the asset data is persisted. This would be outside the scope of Dagster's APIs and would require direct interaction with the storage system using appropriate tools or libraries for that system. For more advanced use cases, you might consider implementing custom tooling or using Dagster's hooks and events to capture asset values and expose them through your own service or API. However, this would require additional development and is not provided out-of-the-box by Dagster.