Go to file
Elara6331 f48f76d9f8
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Add CI badge to README
2024-11-13 19:04:16 -08:00
hisscl Allow calling arbitrary values 2024-11-13 15:30:50 -08:00
test Allow calling arbitrary values 2024-11-13 15:30:50 -08:00
.gitignore Initial Commit 2024-11-09 23:12:29 -08:00
.woodpecker.yml Add CI pipeline 2024-11-13 19:01:01 -08:00
LICENSE Initial Commit 2024-11-09 23:12:29 -08:00
pyproject.toml Update pyproject.toml 2024-11-09 23:26:00 -08:00
README.md Add CI badge to README 2024-11-13 19:04:16 -08:00

HissCL

A HashiCorp Config Language parser for Python

status-badge

Usage

For most simple use-cases, you can use the load* convenience functions:

load_file():

import hisscl
cfg = hisscl.load_file("config.hcl")

loads():

import hisscl
# Use the optional name argument to specify a filename for errors
cfg = hisscl.loads("x = 2 * 4", name='string.hcl')

load():

import hisscl
with open('test.hcl', 'r') as fl:
    # Use the optional name argument to specify a filename for errors
    cfg = hisscl.load(fl, name=fl.name)

Each load* function has an optional vars: dict[str, Any] parameter, whose elements are used as variables in your config file. For example, if you have x = y + 1, y must be defined in vars.

For more advanced use-cases, lexer, parser, ast, and interp submodules are provided.

Output Format

The interpreter outputs a python dictionary containing field values and blocks. Blocks are stored in a list of interp.Block values. interp.Block is a subclass of dict with an extra labels attribute that can be used to get a list of block labels. For example:

import hisscl
cfg = hisscl.loads('x "y" "z" { a = "b" }')
print(cfg['x'][0].labels) # ['y', 'z']
print(cfg['x'][0]['a']) # b

Features

Currently, this parser supports all HCL features except:

Support for these features is planned.