bc-python-hcl2
A parser for HCL2
What it is and what it does
bc-python-hcl2 is a HCL2 parser for Python that converts HashiCorp Configuration Language v2 files into native Python dictionaries. It uses Lark, a parsing toolkit, to handle the HCL2 grammar and is commonly used to programmatically read and process Terraform configuration files. The package is a maintained fork of the original python-hcl2 project, officially supported by Bridgecrew, and supports Python 3.8 through 3.12.
The parser is designed specifically for HCL2 and does not support the older HCL v1 syntax. It provides a simple API—typically just calling `hcl2.load()` on an open file—making it straightforward to integrate into tools that need to inspect or manipulate infrastructure-as-code configurations programmatically.
Use it for:
- Parse Terraform .tf files to extract resource definitions and configuration values for analysis or validation
- Build tooling that reads HCL2 configs to generate documentation or reports about infrastructure
- Integrate HCL2 parsing into policy-as-code or security scanning tools that inspect infrastructure definitions
- Convert HCL2 configurations to other formats (JSON, YAML) for interoperability with non-Terraform tools
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses HCL2 configuration files (such as Terraform configs) into Python dictionaries using a Lark-based parser.
Yes, if you need to parse HCL2 files programmatically. The package has low install friction, permissive licensing, and no known vulnerabilities. However, note that maintenance is aging (last release 396 days ago) and the project has minimal community activity (5 stars). It remains suitable for stable use cases but may not receive rapid updates for new HCL2 features or edge cases.
Install
bc-python-hcl2 on PyPI
pip
pip install bc-python-hcl2uv
uv add bc-python-hcl2poetry
poetry add bc-python-hcl2Installing bc-python-hcl2
Before you install
Low install friction with only two runtime dependencies (lark and importlib-resources). Maintenance status is aging—last release was 396 days ago and the repo shows minimal activity (5 stars), though it remains actively maintained and not archived.
License in practice
MIT license is permissive, allowing use in both open-source and commercial projects with minimal restrictions.
Quickstart
pip install bc-python-hcl2
import hcl2
with open('foo.tf', 'r') as file:
config = hcl2.load(file)
Requires Python 3.8 or higher.
Verify before relying
- Completeness of HCL2 spec coverage beyond basic parsing—which features or edge cases may not be fully supported
- Performance characteristics when parsing large or deeply nested configuration files
- Whether the fork divergence from upstream python-hcl2 introduces breaking changes for existing users
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — lark, importlib-resources |
| Maintenance | aging — 396 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,595,690/month — #2,278 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: bc_python_hcl2-0.4.3-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 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
tfparsetfparse parses and evaluates Terraform HCL…
permissive · top 15,000 on PyPI
tree-sitter-hclProvides a tree-sitter parser grammar for HCL…
permissive · top 15,000 on PyPI
pycep-parserParses Azure Bicep infrastructure-as-code files…
permissive · top 5,000 on PyPI
cdktfDefines cloud infrastructure using Python code…
copyleft · top 15,000 on PyPI
lark-parserLark is a parsing library that builds abstract…
permissive · top 5,000 on PyPI
lark-jsLark-js is a command-line tool that generates…
permissive · top 15,000 on PyPI
python-terraformWraps the Terraform command-line tool, allowing…
permissive · top 15,000 on PyPI
larkLark is a parsing library that builds abstract…
permissive · top 1,000 on PyPI