{"id":1648,"library":"pyhcl","title":"HCL Configuration Parser","description":"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.","status":"active","version":"0.4.5","language":"en","source_language":"en","source_url":"https://github.com/virtuald/pyhcl","tags":["HCL","parser","configuration","terraform","hashicorp"],"install":[{"cmd":"pip install pyhcl","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"hcl","correct":"import hcl"}],"quickstart":{"code":"import hcl\n\nhcl_string = '''\nvariable \"region\" {\n  description = \"AWS region\"\n  type        = string\n  default     = \"us-east-1\"\n}\n\nresource \"aws_instance\" \"web\" {\n  ami           = \"ami-0abcdef1234567890\"\n  instance_type = \"t2.micro\"\n  tags = {\n    Name = \"HelloWorld\"\n  }\n}\n'''\n\nparsed_data = hcl.loads(hcl_string)\nprint(parsed_data.get('resource'))\nprint(parsed_data.get('variable'))","lang":"python","description":"Parses an HCL string into a Python dictionary. The `hcl.loads()` function handles string input, while `hcl.load()` is used for file-like objects."},"warnings":[{"fix":"Upgrade Python to 3.6+ or pin pyhcl to a version prior to 0.3.0 (e.g., `pyhcl==0.2.0`).","message":"pyhcl dropped support for Python 2 in version 0.3.0. Users on older Python 2 environments must upgrade their Python version or use pyhcl < 0.3.0.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Update parsing logic to expect and handle a standard Python dictionary. Access data using dictionary methods like `.get()` or `[]`.","message":"The return type of `hcl.load` and `hcl.loads` changed significantly in version 0.2.0. Previously, it returned a custom `hcl.parser.HCL` object; now, it returns a standard Python `dict`. Code expecting the old object structure will break.","severity":"breaking","affected_versions":"<0.2.0"},{"fix":"Always use `import hcl` to access the parsing functions.","message":"The primary module for importing is `hcl`, not `pyhcl`. Developers sometimes try `from pyhcl import hcl` or `from pyhcl import load`, which will result in an `ImportError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"While `pyhcl` aims for broad HCL compatibility, it may not perfectly support every nuance or the very latest syntax of the evolving HCL specification, especially complex expressions or new language features introduced in newer HCL versions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}