Skip to main content

Programmatically generate LookML

Project description

LookML Generator

https://img.shields.io/pypi/v/lookml-gen.svg https://travis-ci.org/symphonyrm/lookml-gen.svg?branch=master Documentation Status Updates

Programmatically generate LookML

Features

  • Generate LookML views programmatically

  • Include dimensions, dimension groups, filters, and measures in your views

  • Support Persistent Derived Tables (PDTs)

  • Write output to files or StringIO buffers

Quick Start

Install it:

pip install lookml-gen

Use it:

from lookmlgen.view import View
from lookmlgen.field import Dimension, DimensionGroup, Measure
from lookmlgen.base_generator import GeneratorFormatOptions

view_name = 'my_view'
v = View(view_name, sql_table_name='my_table')
v.add_field(Dimension('id', type='number', primary_key=True))
v.add_field(DimensionGroup('created'))
v.add_field(Dimension('name'))
v.add_field(Dimension('quantity', type='number'))
v.add_field(Measure('total_quantity', sql='${TABLE}.quantity', type='sum'))

with open('%s.view.lkml' % view_name, 'w') as f:
    v.generate_lookml(f, GeneratorFormatOptions(view_fields_alphabetical=False))

See it:

# STOP! This file was generated by an automated process.
# Any edits you make will be lost the next time it is
# re-generated.
view: my_view {
  sql_table_name: my_table ;;

  dimension: id {
    type: number
    primary_key: yes
    sql: ${TABLE}.id ;;
  }

  dimension_group: created {
    type: time
    timeframes: ["time", "date", "week", "month"]
    datatype: datetime
    sql: ${TABLE}.created ;;
  }

  dimension: name {
    sql: ${TABLE}.name ;;
  }

  dimension: quantity {
    type: number
    sql: ${TABLE}.quantity ;;
  }

  measure: total_quantity {
    type: sum
    sql: ${TABLE}.quantity ;;
  }
}

TODOs

Full LookML support is far from complete right now. At the moment only very basic aspects of Views and Fields are supported and there is no support for Explores yet. However, it does cover the most common functionality, including Persistent Derived Tables. The code can easily be extended and we’d love to get pull requests to fill out additional functionality.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2017-04-17)

  • First release on PyPI.

0.1.1 (2017-04-17)

  • Switch to lookmlgen for module name

0.1.2 (2017-04-18)

  • Move primary_key from Field to Dimension

  • Remove stub for command line use

  • Add docstrings

0.1.3 (2017-04-20)

  • Default sql parameter of fields to ${TABLE}.field_name

0.1.4 (2017-04-20)

  • Support sql_table_name

  • Add formatting option for alphabetical view fields or not

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

lookml-gen-0.1.4.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lookml_gen-0.1.4-py2.py3-none-any.whl (10.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file lookml-gen-0.1.4.tar.gz.

File metadata

  • Download URL: lookml-gen-0.1.4.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lookml-gen-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ddc02bbb0d5fa49be41ee952afd34bbc12a2d8b4c7ca6fbfd9b90d1d8f876ed2
MD5 9b2314cedd2c9bc22beabb863dc5cf8d
BLAKE2b-256 c311ea1c15d0b5e20cdd6bbd30af07c7069b42e6c9df34e4fca20f647c2524a0

See more details on using hashes here.

File details

Details for the file lookml_gen-0.1.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for lookml_gen-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 92bde4ab993b89665c6e3b781e365f1af98209831d0aea9e6c5d120e6d2f89c5
MD5 a26989eafe5aa2be26f70033c18714d8
BLAKE2b-256 3262a8eddd728a07c76307aea56d80102c29b3ec799cca71c13e6189dd13afd4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page