Skip to main content

Asset selection examples

This page contains common example asset selection queries and their implementation in Python, CLI, and the Dagster UI. For a full explanation of the filters, layers, operands, and functions that you can use to construct your own queries, see "Asset selection syntax reference".

The examples in this section use the following asset graph to demonstrate how to use the selection syntax:

ExampleCo asset lineage

Select all assets on the path between two assets

key:"raw_data_b"+ and +key:"summary_stats_2"

Selects all assets on the path from the raw_data_b asset to the summary_stats_2 asset.

All assets on the path between two assets

Select all assets on the path between two sets of assets

(key:"raw_data_a" or key:"raw_data_b")+ and +(key:"a_b_c_for_sales" or key:"b_c_for_sales")

Selects all assets on the paths between the raw_data_a or raw_data_b assets and the a_b_c_for_sales and b_c_for_sales assets.

All assets between two sets of assets

Select all assets on the path between two sets of assets by tag

tag:"private"+ and +tag:"public"

Selects all assets on the paths between assets tagged with private and assets tagged with public.

All assets on the path between two sets of assets by tag

Select all assets on the path between two groups of assets

group:"sensitive_data"+ and +group:"public_data"

Selects all assets on the paths from the sensitive_data group to the public_data group.

All assets on the path between two groups of assets

Select assets between two assets that go through the "middle" asset

key:"raw_data_c"+ and +key:"combo_a_b_c_data"+ and +key:"summary_stats_1"

Selects all assets on the path between the raw_data_c asset and summary_stats_1 asset that go through the combo_a_b_c_data asset.

All assets between two assets that go through a middle asset

Select assets with multiple key components

To select an asset with a key containing multiple components, such as a prefix, insert slashes (/) between the components:

key:"my_prefix/raw_data_a"

This example selects the my_prefix/raw_data_a asset, which is defined below:

@dg.asset(
key_prefix="my_prefix",
...
)
def raw_data_a() -> None:
...

Select assets with multiple key components

Select multiple assets with or

To select multiple assets, use the or operand. The assets don't have to be dependent on each other. This example selects the summary_stats_1 and summary_stats_2 assets:

key:"summary_stats_1" or key:"summary_stats_2"

Select multiple assets with or

Select downstream assets with a filter

key:"combo_a_b_c_data"+ and kind:"csv"

Selects one layer downstream of combo_a_b_c_data, limited to assets of kind csv.

Select downstream assets with a filter

Select assets without a specific tag

owner:"nora.dagster@example.com" and not tag:"customer_data"

Selects all assets owned by nora.dagster@example.com excluding any assets tagged with customer_data.

Select assets with a specific owner and without a specific tag

Select assets with parentheses grouping and filters

Select a parentheses group or assets that belong in a named group

(owner:"team:sales" and kind:"csv") or group:"public_data"

Selects assets that are either owned by the sales team and of kind csv, or that belong to the public_data group.

Select a parentheses group or assets that belong in a named group

Exclude a parentheses group with not and select assets that match a key wildcard

not (kind:"s3" or kind:"csv") and key:"raw*"

Selects assets whose keys contain raw and are not of the kind s3 or csv.

Exclude parentheses group with not and select assets that match a key wildcard

Select roots or sinks

The examples in this section operate on a selection of assets in the public_data group:

Graph of assets in public_data group

Select all root assets within an asset selection

roots(group:"public_data")

Selects root assets within the public_data group.

Roots within public_data group

Select all sink assets within an asset selection

sinks(group:"public_data")

Selects sink assets within the public_data group.

Sinks within public_data group

Select all root assets that feed into an asset selection

roots(+group:"public_data")

Selects root assets that feed into the public_data group, but do not belong to that group.

Roots that feed to public_data group

Select all sink assets that depend on assets in a selection

sinks(group:"public_data"+)

Selects sink assets that depend on assets in the public_data group, but do not belong to that group.

Sinks that depend on public_data group