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

Shaun McAvinney

03/13/2024, 4:11 PM
How to use configurations with assets jobs?
s

Scout

03/13/2024, 4:11 PM
To use configurations with asset jobs in Dagster, you can define configuration schemas for your assets and provide runtime configuration when materializing them. Here's a step-by-step guide based on the documentation: 1. Define Configuration Schema for Assets: When defining an asset, you can specify a
config_schema
that outlines the expected configuration fields. This schema allows you to parameterize your assets with different runtime values.
Copy code
python    from dagster import asset     @asset(config_schema={"interest_rate": float})    def asset_with_config(context):        return some_financial_calculation(rate=context.op_config["interest_rate"])
2. Materialize Assets with Runtime Configuration: When you want to materialize your assets, you can provide the runtime configuration that matches the
config_schema
you defined. This is done by specifying the configuration for the underlying op that computes the asset.
Copy code
python    from dagster import materialize     materialize(        [asset_with_config],        run_config={"ops": {"asset_with_config": {"config": {"interest_rate": 0.05}}}}    )
3. Dagit UI Support: The Dagit UI has been updated to support asset configuration. For assets with a
config_schema
, the schema is rendered in both the sidebar of the Assets Explorer and in the Asset Details page, allowing you to easily provide configuration when materializing assets through the UI. Remember that the asset's compute function is essentially the corresponding op's compute function, and the asset config is implemented by forwarding the asset's
config_schema
to its underlying op. The runtime config for the asset is provided by directly specifying the config for the op, and it is accessed in the asset's compute function under
context.op_config
. This is how you can use configurations with asset jobs in Dagster, allowing for flexible and parameterized asset computations.
7 Views