Skip to main content

Python LookML Code Generator

A reusable library for boostrapping LookML code for BigQuery datasets with Python.

This library takes a GBQ table and turns it into Looker explores and views using some of the naming conventions, attributes and measures that are used in the Dimensions Data Solutions Team.

Please note that this is an all-purpose generator and most likely requires further manual editing afterwards.

How to Run

You can run it either as a command line application, or using Python e.g. via a script or within a Colab notebook.

The prerequisite in both cases is an authenticated connection to Google BigQuery. When running via Colab, that's created at runtime via the oauth authentication mechanism.

Input

These is all the input data we need to run the script:

  • GBQ project and table information

There are other options that normally take defaults values but can be customised when calling the script from Python. See gbqgen/main.py

Output

By default, data gets saved in the home folder (~).

See the extras folder for an example.

Installation (all users)

pip install lookml-helper

Installation (developers)

With Python 3.9 and virtualenvwrapper

$ git clone git@gitlab.com:digital-science/dimensions/data-solutions/looker-lookml-generator.git
$ mkvirtualenv lookml-helper
$ pip install -r requirements.txt
$ pip install -e .

Then you can run

$ lookmlhelper
Usage: lookmlhelper [OPTIONS]

  lookmlhelper CLI. Requires both a billproject and dataset to run.

Options:
  --examples              Show some examples
  -b, --billproject TEXT  BILLING PROJECT: the GCP billing project to access
                          resources.
  -d, --dataset TEXT      DATASET: a fully scopes GBQ dataset eg `dimensions-
                          ai.data_analytics.clinical_trials`.
  --help                  Show this message and exit.

Prerequisites: Accessing BigQuery

You need to be able to connect to Google BigQuery using Python. This means:

  • Installing the SDK. Installing & authorizing the the Google Cloud SDK, "gcloud," available directly from Google. If you can open a terminal and the gcloud command is recognized, it has been sufficiently configured.
  • Setting up a GCP project. Each time you interact with BigQuery, you need to specify which GCP project you are using. This is generally used for resources access management. More info here.

Note: when using Colab, all of the above is handled in the background for you by the standard Colab-GCP connectivity features.

Example run as CLI

$ lookml-helper -b ds-data-solutions-gbq -d dimensions-ai.data_analytics.clinical_trials
Querying dimensions-ai.data_analytics.clinical_trials information schema...
Found 258 fields...
Generating LookML...
Done.

Example run from Python

In [1]: import lookmlhelper

In [2]: lookmlhelper.from_gbq("ds-data-solutions-gbq", "dimensions-ai.data_analytics.clinical_trials")
Querying dimensions-ai.data_analytics.clinical_trials information schema...
Found 258 fields...
Generating LookML...
Done.

Metadata

Release files for lookml-helper 0.2

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

Source distribution (sdist)

Source distribution for lookml-helper 0.2
File Size Uploaded
lookml-helper-0.2.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lookml-helper 0.2
File Interpreter ABI Platform
lookml_helper-0.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 56.7 kB

Release files / lookml-helper-0.2.tar.gz

Download URL lookml-helper-0.2.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a2e69b057113dbd6539eec1aa3c46a5820ca05da67fc59c25bf3cc88f83a658a
BLAKE2b-256 checksum
How to use checksums
1a4f171242ccad6217ea10204c70682df7556c04e031e6d6c28aa6383e1be88c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.9

Release files / lookml_helper-0.2-py2.py3-none-any.whl

Download URL lookml_helper-0.2-py2.py3-none-any.whl
Size 38.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
65240e1d713f91451d53b3aa506a4176219d561cbbf9b07acd5b140663c3d995
BLAKE2b-256 checksum
How to use checksums
1ae9bc7f991a67b173d087bce9f4c416918ab203f1f028714c853779473b0e31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.9

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.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