A Python HCL parser
Project description
HissCL
A HashiCorp Config Language parser for Python
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hisscl-0.0.4.tar.gz
.
File metadata
- Download URL: hisscl-0.0.4.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f538fb3ba772cc940c231f7e2ca6b16896c4603a9dbd38bc610ad5cd0e093198 |
|
MD5 | 6f501172905e6b04493757136b70cc38 |
|
BLAKE2b-256 | 9735312a1eda7f2e4b9ba56f5ac902c9deb45611a35026cc12254e5bcca128c2 |
File details
Details for the file hisscl-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: hisscl-0.0.4-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe23b0e8dc0010be0be57e3888dcb52b758dece5be1bc4629c12901e8bd821b0 |
|
MD5 | 29d8ecb861a2e9ea5feac50bf499fd8d |
|
BLAKE2b-256 | 5280aadf811748b4c6da79d4c293394826521360e99de6e111e2b2e06d318d7e |