Package to generate LookML from GBQ databases.
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lookml-helper-0.2.tar.gz
.
File metadata
- Download URL: lookml-helper-0.2.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2e69b057113dbd6539eec1aa3c46a5820ca05da67fc59c25bf3cc88f83a658a |
|
MD5 | e440ba0874ee9650b79911b19716e073 |
|
BLAKE2b-256 | 1a4f171242ccad6217ea10204c70682df7556c04e031e6d6c28aa6383e1be88c |
File details
Details for the file lookml_helper-0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: lookml_helper-0.2-py2.py3-none-any.whl
- Upload date:
- Size: 38.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65240e1d713f91451d53b3aa506a4176219d561cbbf9b07acd5b140663c3d995 |
|
MD5 | a9e48a8fb400f2f9a3632f6e53d075be |
|
BLAKE2b-256 | 1ae9bc7f991a67b173d087bce9f4c416918ab203f1f028714c853779473b0e31 |