This guide provides instructions for using Dagster with Looker using the dagster-looker library. Your Looker assets, such as views, explores, and dashboards, can be represented in the Dagster asset graph, allowing you to track lineage and dependencies between Looker assets. You can also use Dagster to orchestrate Looker PDTs, allowing you to trigger refreshes of these materialized tables on a cadence or based on upstream data changes.
To load Looker assets into the Dagster asset graph, you must first construct a LookerResource, which allows Dagster to communicate with your Looker instance. You'll need to supply your Looker instance URL and API credentials, which can be passed directly or accessed from the environment using EnvVar.
Dagster can automatically load all views, explores, and dashboards from your Looker instance as asset specs. Call the undefined.load_looker_asset_specs function, which returns a list of AssetSpecs representing your Looker assets. You can then include these asset specs in your Definitions object:
Load Looker assets from filtered dashboards and explores#
It is possible to load a subset of your Looker assets by providing a undefined.LookerFilter to the undefined.load_looker_asset_specs function. All dashboards contained in the folders provided to your undefined.LookerFilter will be fetched. Additionally, only the explores used in these dashboards will be fetched by passing only_fetch_explores_used_in_dashboards=True to your undefined.LookerFilter.
Note that the content and size of Looker instance may affect the performance of your Dagster deployments. Filtering the dashboards and explores selection from which your Looker assets will be loaded is particularly useful for improving loading times.
Customize asset definition metadata for Looker assets#
By default, Dagster will generate asset keys for each Looker asset based on its type and name and populate default metadata. You can further customize asset properties by passing a custom DagsterLookerApiTranslator subclass to the undefined.load_looker_asset_specs function. This subclass can implement methods to customize the asset keys or specs for each Looker asset type.
from dagster_looker import(
DagsterLookerApiTranslator,
LookerResource,
LookerStructureData,
LookerStructureType,
load_looker_asset_specs,)import dagster as dg
looker_resource = LookerResource(
client_id=dg.EnvVar("LOOKERSDK_CLIENT_ID"),
client_secret=dg.EnvVar("LOOKERSDK_CLIENT_SECRET"),
base_url=dg.EnvVar("LOOKERSDK_HOST_URL"),)classCustomDagsterLookerApiTranslator(DagsterLookerApiTranslator):defget_asset_spec(self, looker_structure: LookerStructureData)-> dg.AssetSpec:
asset_spec =super().get_asset_spec(looker_structure)# Add a team owner tag for all Looker assets
asset_spec = asset_spec._replace(owners=["team:my_team"])# For only Looker dashboard, prefix the asset key with "looker" for organizational purposesif looker_structure.structure_type == LookerStructureType.DASHBOARD:
asset_spec = asset_spec._replace(key=asset_spec.key.with_prefix("looker"))return asset_spec
looker_specs = load_looker_asset_specs(
looker_resource, dagster_looker_translator=CustomDagsterLookerApiTranslator
)
defs = dg.Definitions(assets=[*looker_specs], resources={"looker": looker_resource})