Skip to main content

dbt2looker-bigquery

Use dbt2looker-bigquery to generate Looker view files automatically from dbt models in Bigquery.

Features

  • Warehouses: BigQuery

  • Column descriptions synced to looker

  • Define Dimensions define common lookml settings in dbt like label, group label, hidden

  • Define Measures simple measures can be defined from dbt

  • Create Explores for structs automatically generate explores for complex tables with structs and arrays in them.

  • Dimension groups for datetime/timestamp/date columns

Quickstart

Run dbt2looker in the root of your dbt project after compiling looker docs. (dbt2looker-bigquery uses docs to infer types and such)

Generate Looker view files for all models

dbt2looker

Install

Install from PyPi repository

uv add dbt2looker-bigquery

# Run
dbt2looker

cli args

options:
  -h, --help            show this help message and exit
  --version, -v         show program's version number and exit
  --target-dir TARGET_DIR
                        Path to dbt target directory containing manifest.json and catalog.json. Default is "./target"
  --tag TAG             Filter to dbt models using this tag, can be combined with --exposures-only to only generate lookml files for exposures with this tag
  --log-level {DEBUG,INFO,WARN,ERROR}, -log {DEBUG,INFO,WARN,ERROR}
                        Set level of logs. Default is INFO
  --output-dir OUTPUT_DIR
                        Path to a directory that will contain the generated lookml files
  --exposures-only      add this flag to only generate lookml files for exposures
  --exposures-tag EXPOSURES_TAG
                        filter to exposures with a specific tag
  --skip-explore        add this flag to skip generating an sample "explore" in views for nested structures
  --use-table-name      add this flag to use table names on views and explore instead of dbt file names. useful for versioned models
  --select SELECT [SELECT ...], -s SELECT [SELECT ...]
                        select one or more specific models to generate lookml for, ignores tag and explore, Will remove / and .sql if present
  --all-hidden          add this flag to force all dimensions and measures to be hidden
  --folder-structure FOLDER_STRUCTURE
                        Define the source of the folder structure. Default is 'fBIGQUERY_DATASET', options ['BIGQUERY_DATASET', 'DBT_FOLDER']
  --remove-prefix-from-dataset REMOVE_PREFIX_FROM_DATASET
                        Remove a prefix from dataset name, only works with 'BIGQUERY_DATASET' folder structure
  --show-arrays-and-structs
                        Experimental: stop arrays and structs from being hidden by default
  --implicit-primary-key
                        Add this flag to set primary keys on views based on the first field
  --dry-run             Add this flag to run the script without writing any files
  --strict              Add this flag to enable strict mode. This will raise an error for any lookml parsing errors and deprecations. It will
                        expect all --select models to generate files.
  --prefilter           Experimental: add this flag to prefilter the manifest.json file before parsing for --select
  --typing-source TYPING_SOURCE, -ts TYPING_SOURCE
                        Experimental: Define the catalog parser to use. Default is 'CATALOG', options ['DATABASE', 'CATALOG']
  --prefix              Experimental: add a string to prefix all generated views with this string

primary keys

Setting primary keys in Looker is important for many measures. Defining a dimension in dbt as primary key for looker can be done by setting a constraint on the dbt column:

    columns:
      - name: id
        data_tests:
          - unique
        constraints:
          - type: primary_key

Please note that setting a constraint like this does not get enforced in Bigquery.

Lookml in model yml

models:
  - name: dim_pages_v0
    meta:
      looker:
        view:
          label: This is set as the label on the view
          description: This is set as the explore description if an explore is generated
        explore:
          group_label: Sets the group label of the explore
    columns:
      - name: url
        description: "Page url"
        meta:
          looker:
            dimension:
              label: "Page url from website"
              group_label: "Urls"
              description: "A url for a webpage that you can inspect"
              value_format_name: id
              hidden: True

            measures:
              - type: count
                label: Number of urls
                hidden: True

              - type: count_distinct
                label: Distinct number of urls
                sql_distinct_key: url

pre-commit hook

You can use dbt2looker-bigquery in your dbt repository as a pre-commit hook, to validate your lookml configuration while working.

verify: checks that lookml is properly defined, and no errors occur during parsing generate: generate a lookml view file for the modified models.

The hooks verify schemas by checking the tables exists in Bigquery, so you do not need to generate the catalog.

  - repo: https://github.com/rognerud/dbt2looker-bigquery
    rev: v0.23.1
    hooks:
      - id: verify
        files: ^models/
      - id: generate
        files: ^models/

Acknowledgments

Higly inspired by dbt2lookml, all credit to @magnus-ffcg for the structure, he has refactored most of the code.

This is a fork of dbt2looker that is specific to bigquery.

The intention is to allow one to define most of the simple and tedious lookml settings in dbt. That way the lookml code gets less bloated, and can be more focused on advanced metrics and explores.

Want a deeper integration between dbt and your BI tool? You should also checkout Lightdash - the open source alternative to Looker

Metadata

Release files for dbt2looker-bigquery 0.23.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbt2looker-bigquery 0.23.10
File Size Uploaded
dbt2looker_bigquery-0.23.10.tar.gz 144.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbt2looker-bigquery 0.23.10
File Interpreter ABI Platform
dbt2looker_bigquery-0.23.10-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 180.5 kB

Release files / dbt2looker_bigquery-0.23.10.tar.gz

Download URL dbt2looker_bigquery-0.23.10.tar.gz
Size 144.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e4eeff940eae61084e73c1f915d28b2fecbf27c19626150d08cf54099b4f6a53
BLAKE2b-256 checksum
How to use checksums
72c67071a40763937af485ffb3b2ddb7f19af7c3d9f07da44e7de40ac92b68e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release files / dbt2looker_bigquery-0.23.10-py2.py3-none-any.whl

Download URL dbt2looker_bigquery-0.23.10-py2.py3-none-any.whl
Size 35.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
624bf1842074ccb61d384fcaebfd4aaa5c974804ce2f7d5198b110b2ad78f171
BLAKE2b-256 checksum
How to use checksums
ee2cd6b2efa9da669322ee77a722fa81e08be79d81df16aac3f4e0dfbed1e556
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release history Release notifications | RSS feed

This release

0.23.10 This release

2 release files

0.23.8

2 release files

0.23.7

2 release files

0.23.5

2 release files

0.23.4

2 release files

0.23.2

2 release files

0.23.1

2 release files

0.20.1

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.2

2 release files

0.13.3

2 release files

0.13.2

2 release files

0.13.0

2 release files

0.12.9

2 release files

0.12.8

2 release files

0.12.7

2 release files

0.12.5

2 release files

0.12.3

2 release files

0.12.2

2 release files

0.12.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page