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
pip install looker-gen
- (Optional) Looker: Configure LookerSDK with
looker.ini
file - Verify:
looker-gen --help
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
explore
will generate anexplore
for the model.joins
will create a list ofjoin
s atteached to theexplore
.
Column
description
: Uses dbt's standarddescription
declaration; not referenced inlooker-gen
arguments.ignore-dim
: By default,looker-gen
will create adimension
ordimension_group
for every column within the table. This prevent the column from creating a dimension or dimension group.looker-only
: Defines a column in LookML, without an existing column in the database. Useful for derived dimensions, calculations, etc.column-type
: If defined aslooker-only
, will determine LookML column type. Currently only supportsdim
ordimension
values.measures
: Builds an array of measures.- Will generate
count
measure for all views. - Will generate a formatted
view_label
by default for all views.
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