A Python parser and toolkit for HCL2 configuration files, enabling conversion, querying, and programmatic manipulation.
Python HCL2 is a Python library and toolkit for parsing, generating, and querying HashiCorp Configuration Language version 2 (HCL2) files. It solves the problem of programmatically working with HCL2-based configuration—common in tools like Terraform—by providing a native Python interface for conversion, manipulation, and analysis.
Developers and DevOps engineers who work with Terraform or other HCL2-based infrastructure-as-code tools and need to automate or analyze configuration files using Python.
It offers a pure-Python implementation with a comprehensive API and CLI tools, enabling seamless integration into Python-based automation pipelines without relying on external binaries or complex workarounds.
Python HCL2 is a parser for HashiCorp Configuration Language version 2 (HCL2) written in Python using the Lark parsing toolkit. It allows developers to read, write, query, and manipulate HCL2 configuration files—such as those used by Terraform—directly from Python code or via command-line tools.
hcl2tojson and jsontohcl2 for format conversion, plus hq for jq-like querying of HCL files.Builder API to construct HCL2 documents from scratch within Python.DocumentView and BlockView for structured traversal and inspection of parsed HCL trees.The project focuses on providing a robust, Python-native interface to HCL2 that prioritizes correctness, usability, and extensibility for infrastructure-as-code workflows.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides hcl2.load and hcl2.dump for seamless conversion between HCL2 files and Python dictionaries, enabling easy programmatic access as shown in the usage examples.
Includes hcl2tojson, jsontohcl2, and hq for command-line format conversion and jq-like querying, documented with real-world examples in the CLI tools section.
Offers a Builder API to construct HCL2 documents from scratch, allowing dynamic generation of configuration files within Python scripts, as demonstrated in the Getting Started guide.
Features DocumentView and BlockView for structured traversal and inspection of parsed HCL trees, facilitating complex data extraction with detailed documentation.
Comment deserialization is listed as a planned feature in the roadmap, meaning comments may be lost during round-trip conversions, limiting fidelity in some workflows.
The migration guide for v8 indicates significant breaking changes, which could require updates to existing codebases and add maintenance overhead for adopters.
Explicitly supports HCL2 only, making it unsuitable for projects that need to handle older HCL v1 configuration files without additional tooling.