--- id: python-hcl2 version: "8.1.2" license: MIT license_treatment: permissive maintenance: active --- # python-hcl2 — A parser for HCL2 License: permissive · Maintenance: active · Downloads: 6.3M/mo ## What it is and what it does python-hcl2 is a parser that reads HCL2 configuration syntax—the language used by Terraform and other HashiCorp tools—and converts it into Python dictionaries, or vice versa. It uses the Lark parsing library and the regex module as its core dependencies. The package supports HCL2 only (not the older HCL v1) and works with any HCL2 config file, including Terraform configurations. Beyond basic parsing, the package provides a Builder API for constructing HCL2 documents programmatically from Python, and ships three CLI tools: hcl2tojson and jsontohcl2 for format conversion, and hq—a jq-like query tool for extracting and inspecting parts of HCL2 files. It is actively maintained, supports Python 3.8 through 3.13, and carries no known security vulnerabilities. Use it for: - Convert Terraform .tf files to JSON for programmatic inspection or transformation in a Python application. - Build HCL2 configuration files dynamically from Python code without hand-writing HCL syntax. - Query specific values from HCL2 files using the hq CLI tool for compliance checks or configuration audits. - Integrate HCL2 parsing into infrastructure-as-code tooling or configuration management scripts. - Round-trip HCL2 ↔ JSON for data pipeline or API integration workflows. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Parses HCL2 configuration files (used by Terraform and other HashiCorp tools) into Python data structures, and converts Python dicts back to HCL2 format. Includes CLI tools for format conversion and querying. Yes. The package is actively maintained, has no known vulnerabilities, installs with minimal friction (two lightweight dependencies), supports current Python versions, and solves a real problem for anyone working with Terraform or other HCL2-based tools. The permissive MIT license poses no barrier. Install it if you need to parse, query, or generate HCL2 files from Python. ## Install pip install python-hcl2 uv add python-hcl2 poetry add python-hcl2 ## Installing python-hcl2 Before you install: Low friction: pure Python wheel with only two runtime dependencies (lark and regex). Actively maintained with a recent release; last commit was 2026-07-18 and the project is not archived. License in practice: MIT license (permissive) means you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions. Quickstart: pip install python-hcl2 import hcl2 with open("main.tf") as f: data = hcl2.load(f) hcl_string = hcl2.dumps(data) Requires Python 3.8 or higher. Verify before relying: - Whether the package handles all HCL2 syntax edge cases or has known parsing limitations beyond those documented. - Performance characteristics when parsing very large HCL2 files or directories. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 6.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags HCL2 parser Python, Terraform config parser, HCL to JSON converter, parse HCL2 files, HCL2 query tool, infrastructure as code parser, terraform, configuration-parsing, infrastructure-as-code [View on SkillFed](https://skillfed.io/packages/python-hcl2) · [View on PyPI](https://pypi.org/project/python-hcl2/)