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.