tree-sitter-hcl
HCL and terraform grammar for tree-sitter
What it is and what it does
tree-sitter-hcl is a tree-sitter grammar binding for parsing HCL and Terraform configuration files in Python. It wraps the tree-sitter incremental parsing engine, which builds a concrete syntax tree that can be queried and traversed programmatically. The package ships as precompiled wheels for most platforms, eliminating the need to build the grammar from source in typical use.
The parser is designed for developers who need to analyze, transform, or validate HCL configurations programmatically—common in infrastructure-as-code tooling, linters, and Terraform-related utilities. Testing against a real-world corpus of HCL files achieved 100% parse success rate across all files tested.
Use it for:
- Build a Terraform linter or static analyzer that inspects HCL syntax and structure.
- Extract metadata from Terraform configurations such as resource names and variable definitions.
- Implement IDE features like syntax highlighting and code completion for HCL editors.
- Validate HCL configuration files before deployment in CI/CD pipelines.
- Migrate or refactor Terraform code by programmatically rewriting the syntax tree.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a tree-sitter parser grammar for HCL and Terraform, enabling incremental parsing and syntax analysis of HCL configuration files.
Yes, if you need to parse or analyze HCL/Terraform files programmatically. The package is stable with no known vulnerabilities and permissively licensed. Install friction is moderate due to compilation, but prebuilt wheels are available for common platforms. The aging maintenance status is acceptable for a grammar binding—updates are typically infrequent unless the underlying HCL specification changes.
Install
tree-sitter-hcl on PyPI
pip
pip install tree-sitter-hcluv
uv add tree-sitter-hclpoetry
poetry add tree-sitter-hclInstalling tree-sitter-hcl
Before you install
Medium install friction due to compiled wheels; prebuilt binaries are available for common platforms (x86_64, ARM64, macOS, Linux, Windows). Repository remains active and unarchived, though last release was 424 days ago.
License in practice
Licensed under Apache-2.0 (permissive), allowing free use, modification, and distribution with minimal restrictions; suitable for both open-source and commercial projects.
Quickstart
pip install tree-sitter-hcl
from tree_sitter_hcl import language
parser = language.parser()
tree = parser.parse(b'resource "aws_instance" { }')
Requires Python >=3.10; compiled wheels provided for common platforms but may require a C compiler on unsupported architectures.
Verify before relying
- Whether the parser handles all HCL2 syntax variants beyond the core language specification.
- Performance characteristics and memory overhead for parsing large configurations.
- Compatibility with specific tree-sitter versions or ecosystem tooling beyond Python >=3.10.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | aging — 424 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 132,104/month — #11,565 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: tree_sitter_hcl-1.2.0-cp310-abi3-macosx_10_9_x86_64.whl; tree_sitter_hcl-1.2.0-cp310-abi3-macosx_11_0_arm64.whl; tree_sitter_hcl-1.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; tree_sitter_hcl-1.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; tree_sitter_hcl-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl; tree_sitter_hcl-1.2.0-cp310-abi3-win_amd64.whl; tree_sitter_hcl-1.2.0-cp310-abi3-win_arm64.whl
Keywords: incremental, parsing, tree-sitter, hcl
Tags
More Linguistic packages
Detects and normalizes text encoding from…
permissive · top 100 on PyPI
tiktokentiktoken is a fast BPE tokenizer that converts…
permissive · top 1,000 on PyPI
chardetDetects character encoding and language in byte…
permissive · top 1,000 on PyPI
text-unidecodeConverts Unicode text to ASCII by…
copyleft · top 1,000 on PyPI
larkLark is a parsing library that builds abstract…
permissive · top 1,000 on PyPI
tree-sitterPython bindings to the tree-sitter parsing…
permissive · top 1,000 on PyPI
tree-sitter-elixirProvides an Elixir language grammar for…
permissive · top 5,000 on PyPI
tfparsetfparse parses and evaluates Terraform HCL…
permissive · top 15,000 on PyPI
python-hcl2Parses HCL2 configuration files (used by…
permissive · top 5,000 on PyPI
pyhclParses HCL (HashiCorp Configuration Language)…
copyleft · top 5,000 on PyPI
bc-python-hcl2Parses HCL2 configuration files (such as…
permissive · top 5,000 on PyPI
tree-sitter-javaProvides a Java language grammar for…
permissive · top 5,000 on PyPI
tree-sitter-goProvides a Go language grammar for tree-sitter,…
permissive · top 5,000 on PyPI
tree-sitter-pythonProvides a Python grammar for tree-sitter,…
permissive · top 5,000 on PyPI
tree-sitter-sqlProvides a tree-sitter SQL grammar for parsing…
permissive · top 5,000 on PyPI
tree-sitter-powershellProvides a tree-sitter grammar for parsing…
permissive · top 5,000 on PyPI