Project

lkml

0.0
The project is in a healthy, maintained state
Parse LookML strings into Ruby hashes and serialize Ruby hashes back to LookML. Implementation uses the same algorithm as the original Python lkml package.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
~> 5.25
~> 13.2
~> 1.69
 Project Readme

lkml

A fast LookML parser and serializer implemented in pure Ruby (stdlib only).

Lkml.load parses LookML text into Ruby hashes (with string keys, suitable for JSON). Lkml.dump / Lkml.generate serialize hashes back to LookML.

Why use lkml?

  • Exercised on a large corpus of real-world LookML (including bundled GitHub samples)
  • Parses typical view/model files in a few milliseconds (CPU time, excluding I/O)
  • No runtime gem dependencies
  • Full Minitest suite including lexer, parser, round-trip, and CLI checks

Install

gem install lkml

Or add to your Gemfile:

gem "lkml"

Requires Ruby 3.3+.

Usage

require "lkml"

hash = Lkml.load('view: orders { sql_table_name: public.orders ;; }')
# => {"views"=>[{"name"=>"orders", "sql_table_name"=>"public.orders"}]}

lookml = Lkml.dump(hash)
# or
lookml = Lkml.generate(hash)

Parse to the concrete syntax tree instead of a hash:

tree = Lkml.parse("view: x { dimension: id { type: number sql: ${TABLE}.id ;; } }")
tree.to_s # round-trip string

CLI

lkml path/to/file.view.lkml

Pretty-prints JSON.

Options:

  • -v / --verbose — debug logging on stderr

Development

bundle install
bundle exec rake test

Optional acceptance run over bundled GitHub samples (slow):

LKML_RUN_GITHUB_TESTS=1 bundle exec ruby -Itest test/test_github.rb

Benchmark (CPU time over test/resources/github/*.lkml):

ruby script/benchmark.rb

Contributing

See CONTRIBUTING.md.

License

MIT — see LICENSE.md.