skillfed

tree-sitter-hcl

HCL and terraform grammar for tree-sitter

tree-sitter-hcl v1.2.0 132.1K downloads/30d#11,565 on PyPI145
Permissive license Apache-2.0 AGING released

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-hcl

uv

uv add tree-sitter-hcl

poetry

poetry add tree-sitter-hcl

Installing 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

Intended Audience :: DevelopersTopic :: Software Development :: CompilersTopic :: Text Processing :: LinguisticTyping :: Typed

Tags

HCL parsertree-sitter grammarterraform parsingincremental parsingHCL syntax analysisconfiguration language parsertree-sitter HCL
terraformparsingsyntax-tree

More Linguistic packages