skillfed

bc-python-hcl2

A parser for HCL2

bc-python-hcl2 v0.4.3 4.6M downloads/30d#2,278 on PyPI5
Permissive license MIT AGING released

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

uv

uv add bc-python-hcl2

poetry

poetry add bc-python-hcl2

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

HCL2 parser PythonTerraform config parserHCL parser libraryparse HCL2 filesTerraform file parsingHCL configuration parserinfrastructure as code parsing
hcl2-parserterraforminfrastructure-as-code

More Python Modules packages