Home

Awesome

Looker Gen

Generate LookML from a dbt project. Reads from your dbt repo and outputs files; can output to your Looker repo.

Currently in experimentation mode, the API may break. Somewhat opinionated about output directory structure, refer to config.py for options.

Requires dbt 1.0.0 or later.

Installation

Installable from PyPi

Running

Build dbt project

In your dbt repo:

dbt compile # builds manifest based on dbt yml
dbt docs generate # builds catalog from database

Note: dbt run can replace compile. To ensure that LookML columns matches database schema, tables must be created with dbt run.

Generate LookML

$DBT_DIR = Directory of dbt repo

$LOOKER_DIR = Directory of LookML repo

looker-gen gen -d $DBT_DIR -o $LOOKER_DIR

This will output generated files with to output destination with the following structure:

LookMLRepo/
├─ explores/
│  ├─ looker-gen.explore.lkml
│  ├─ ....explore.lkml
├─ views/
   ├─ ....view.lkml

To use within Looker, simply add this to your *.models.lkml file:

include: "/explores/looker-gen.explore.lkml"

Optional: Valiate Looker Project

The looker-gen validate command can validate your LookML repo with Looker's linter ("LookML Validation") and content validation.

$LOOKER_DIR = Directory of LookML repo

$PROJECT = Name of project within Looker.

looker-gen validate -p $PROJECT -l $LOOKER_DIR

Note: use looker-gen validate --help for options

DBT Configuration Overview

Use the looker-gen key witn an element's meta tag. (Example below)

Mostly, the yml will be passed through to LookML. There are a few protected words that impact behavior:

Model

Column

DBT Configuration Example

version: 2

models:
  - name: fct_sales
    description: "All the sales"
    meta:
      looker-gen:
        explore:
          joins:
            - name: dim_customers
              sql_on: ${fct_sales.customer_id} = ${dim_customers.id}
              type: left_outer
              relationship: many_to_one
    columns:
        - name: revenue
          meta:
            looker-gen:
              ignore-dim: 'yes'
              measures:
                - name: total_revenue
                  type: sum
                  value_format: "$#.0;($#.00)"


    - name: dim_customers
      description: "All the customers"
      meta:
        looker-gen:
          group_label: "People"
      columns:
        - name: id
          description: "Primary Key"
          meta:
            looker-gen:
              primary_key: 'yes'
              measures:
                - name: unique_customers
                  type: count_distinct