Registry / devops / tfparse

tfparse

JSON →
library0.6.20pypypi✓ verified 84d ago

tfparse is a Python library providing a fast, robust parser for HCL (HashiCorp Configuration Language) and Terraform files. It leverages a Go extension for its core parsing capabilities, making it efficient for use cases like security scanning (e.g., AquaSecurity defsec). The library is actively maintained with frequent minor releases, often on a weekly or bi-weekly cadence, reflecting ongoing improvements and bug fixes.

pip install tfparse
INSTALL
IMPORT
SIG · TFPARSE
T
tfparse
devopspythonv0.6.20
Install
3.9s avg
Import
Disk
40MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.9s · import 0.000s · 77MB
40MB installed
● package 40MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

load_from_path
from tfparse import load_from_path
from tfparse import parse
ParseError
from tfparse import ParseError
Path
from tfparse import Path

Demonstrates parsing a Terraform configuration string and accessing structured data from the result. For parsing entire directories, use `tfparse.load_from_path`.

from tfparse import parse # Example Terraform configuration as a string terraform_config = """ resource "aws_s3_bucket" "my_bucket" { bucket = "my-unique-bucket-name" acl = "private" tags = { Environment = "Dev" Project = "tfparse-example" } } variable "region" { description = "AWS region" type = string default = "us-east-1" } """ try: # Parse the HCL configuration string parsed_data = parse(terraform_config) print("Successfully parsed Terraform configuration:") # Access some parsed data, e.g., the resource block s3_bucket = parsed_data.get("resource", {}).get("aws_s3_bucket", {}).get("my_bucket") if s3_bucket: print(f" Resource 'aws_s3_bucket.my_bucket' found. Bucket name: {s3_bucket.get('bucket')}") print(f" Tags: {s3_bucket.get('tags')}") # Access a variable block region_var = parsed_data.get("variable", {}).get("region") if region_var: print(f" Variable 'region' default: {region_var.get('default')}") except Exception as e: print(f"Error parsing configuration: {e}")
Debug
Known issues
breakingVersion 0.6.15 introduced a breaking change to internal reference-tracking, specifically to support multiple references within a single block. Code that directly manipulates or relies on the structure of tracked references will need updating.
fix
Review the reference-tracking changes (e.g., in the `c7n-left` project, linked in release notes) and adapt your code to the new data structure for references.
affects: 0.6.15 and later
gotchaParsing configurations with dynamic blocks (`for_each`) or values that are not 'wholly known' (e.g., runtime outputs, sensitive data) can lead to unexpected parsing behavior or errors.
fix
Upgrade to `tfparse >= 0.6.18` which includes fixes for handling partially unknown `for_each` blocks. Ensure that values required for static parsing are resolvable or handle potential `None`/`unknown` gracefully in your application logic.
affects: <0.6.18
gotchaHCL strings intended to be JSON, but containing unresolved references or malformed content, may result in `tfparse` returning non-valid JSON strings, leading to subsequent JSON parsing failures.
fix
Ensure that any HCL string values intended to be JSON are fully resolved and syntactically correct at the time of parsing. Upgrade to `tfparse >= 0.6.19` which contains a fix for these `unresolved JSON strings`.
affects: <0.6.19
Upgrade
Version history
0.6.20latest on PyPI · released May 28, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
tfparse — pip install tfparse · libregistry