77# Python HCL2
88
99A parser for [ HCL2] ( https://github.com/hashicorp/hcl/blob/hcl2/hclsyntax/spec.md ) written in Python using
10- [ Lark] ( https://github.com/lark-parser/lark ) . This parser only supports HCL2 and isn't backwards compatible
11- with HCL v1. It can be used to parse any HCL2 config file such as Terraform.
10+ [ Lark] ( https://github.com/lark-parser/lark ) . It can be used as a Python library or through its CLI tools:
11+ ` hcl2tojson ` , ` jsontohcl2 ` , and ` hq ` — a jq-like query tool for HCL files.
12+ Supports HCL2 only (not backwards compatible with HCL v1) and works with any HCL2 config file such as Terraform.
1213
1314## About Amplify
1415
@@ -33,6 +34,12 @@ This package can be installed using `pip`
3334pip3 install python-hcl2
3435```
3536
37+ To install the CLI tools (` hcl2tojson ` , ` jsontohcl2 ` , ` hq ` ) globally without affecting your project environments, use [ pipx] ( https://pipx.pypa.io/ ) :
38+
39+ ``` sh
40+ pipx install python-hcl2
41+ ```
42+
3643### Usage
3744
3845** HCL2 to Python dict:**
@@ -75,6 +82,7 @@ hcl_string = hcl2.dumps(doc.build())
7582| [ Querying HCL (Python)] ( docs/02_querying.md ) | DocumentView, BlockView, tree walking, view hierarchy |
7683| [ Advanced API] ( docs/03_advanced_api.md ) | Pipeline stages, Builder |
7784| [ hq Reference] ( docs/04_hq.md ) | ` hq ` CLI — structural queries, hybrid/eval, introspection |
85+ | [ hq Examples] ( docs/05_hq_examples.md ) | Real-world queries for discovery, compliance, extraction |
7886
7987### CLI Tools
8088
@@ -123,13 +131,10 @@ Github actions will take care of publishing it to PyPi.
123131
124132Planned features, roughly in priority order:
125133
126- - ** Agent-friendly CLIs** — structured errors, NDJSON streaming, and filtering for ` hcl2tojson ` /` jsontohcl2 `
127- - ** Comment deserialization** — preserve comments through JSON round-trip (issue #134 )
128- - ** jq syntax compatibility** — ` .[] ` as alias for ` [*] ` ; canonical ` hq --json | jq ` patterns for data transforms
129134- ** MCP server** — expose parsing, querying, and formatting as MCP tools for AI agents
130- - ** Canonical formatting** — predictable whitespace output, closer to ` terraform fmt `
135+ - ** Predictable formatting** — source-derived formatting heuristics and stable whitespace defaults
131136- ** In-place tree edits** — ` hq set ` , ` hq delete ` for programmatic HCL modification
132- - ** Comment reserialization ** — comments survive tree edits, not just JSON round-trips
137+ - ** Comment deserialization ** — comments survive JSON round-trips and tree edits
133138- ** Expression intelligence** — variable reference tracking, unused variable detection, cross-file analysis
134139- ** Refactoring operations** — ` hq rename ` , ` hq extract-module ` , ` hq sort ` for high-level code transforms
135140
0 commit comments