pyhcl is a Python library for parsing HCL (HashiCorp Configuration Language) files and strings into Python dictionaries. It aims to be compatible with HCL versions commonly used by tools like Terraform. The library is currently at version 0.4.5 and is actively maintained with bug fixes and compatibility updates, though releases are irregular.
pip install pyhclVerified import paths — ran on the pinned version, not inferred.
Parses an HCL string into a Python dictionary. The `hcl.loads()` function handles string input, while `hcl.load()` is used for file-like objects.
Upgrade Python to 3.6+ or pin pyhcl to a version prior to 0.3.0 (e.g., `pyhcl==0.2.0`).
Update parsing logic to expect and handle a standard Python dictionary. Access data using dictionary methods like `.get()` or `[]`.
Always use `import hcl` to access the parsing functions.
For critical or highly complex HCL parsing, validate `pyhcl`'s output against the official HCL parser or actual tool behavior. Consider simpler HCL structures if encountering parsing issues.
Remove trailing commas from lists and maps in your HCL input. For example, change `["a", "b",]` to `["a", "b"]`.
Install `ply` explicitly before or alongside `pyhcl` using `pip install ply pyhcl` or by installing `ply` first (`pip install ply`) and then `pyhcl` (`pip install pyhcl`).
Ensure that the string or file passed to `pyhcl.loads()` or `pyhcl.load()` is not empty and contains valid HCL syntax. Implement a check for empty input before parsing.
For HCL2 files, use a library specifically designed for HCL2, such as `python-hcl2`. Install it with `pip install python-hcl2` and then use `import hcl2`.
No dependency data recorded yet.