Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

hisscl-0.0.3-1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file hisscl-0.0.3-1-py3-none-any.whl.

File metadata

  • Download URL: hisscl-0.0.3-1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.6

File hashes

Hashes for hisscl-0.0.3-1-py3-none-any.whl
Algorithm Hash digest
SHA256 88e7adaf83b9829b92b3c8406ba9e43949e0a81ad1fe8ac20bc114244a2ed7e2
MD5 3f9e864262520b7dd38a1fe600656adb
BLAKE2b-256 7335c590e7adf7b19c7509b710bc29f8e8842d5ed03674d4a0c4ec7d0633ac8f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page