lkml is a speedy LookML parser and serializer implemented in pure Python. It parses LookML strings into Python dictionaries and serializes Python dictionaries back into LookML strings. The library is actively maintained with frequent minor releases to support new LookML syntax and improve parsing/serialization accuracy.
pip install lkmlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a LookML string into a Python dictionary using `lkml.load()`, modify the resulting dictionary, and then serialize it back into a LookML string using `lkml.dump()`. This mirrors the common pattern for programmatic LookML manipulation.
For simple parsing/serialization, accept the opinionated formatting. For precise control, utilize the lower-level `lkml.parse()` to get a `DocumentNode` and manipulate the parse tree directly, then use `lkml.tree.DocumentNode.to_lookml()`.
Thoroughly test and validate the structure of the Python dictionaries before serializing them with `lkml.dump()` to ensure they conform to LookML syntax rules.
Upgrade `lkml` to version `1.3.2` or later. If unable to upgrade, pass a copy of the dictionary to `lkml.dump()` (e.g., `lkml.dump(my_dict.copy())`) to prevent mutations of the original object.
When working with the parsed Python dictionary, always expect repeated LookML fields to be represented as lists under their pluralized key names. Consult `lkml.keys` for a definitive list of pluralized keys and special cases.
Review the LookML input at the indicated position for any syntax errors. Ensure all blocks are properly closed, attributes are correctly formatted, and all LookML keywords are spelled correctly. The `lkml` documentation on its grammar can be a helpful reference.
Ensure that the Python object passed to `lkml.dump()` is one of the supported types (string, list, tuple, or dictionary) and that its internal structure correctly represents valid LookML. Refer to the 'How LookML is represented by lkml' section in the documentation for guidance on structuring Python objects for serialization.
Install the `lkml` library using pip: `pip install lkml`. If you are using a virtual environment, ensure it is activated before installation. If already installed, verify your Python interpreter's path and ensure it's the one with the installed library.
No dependency data recorded yet.