All Projects → virtuald → Pyhcl

virtuald / Pyhcl

Licence: mpl-2.0
HCL is a configuration language. pyhcl is a python parser for it.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pyhcl

Jk
Configuration as Code with ECMAScript
Stars: ✭ 322 (+23.85%)
Mutual labels:  hcl, configuration
Resticprofile
Configuration profiles for restic backup
Stars: ✭ 48 (-81.54%)
Mutual labels:  hcl, configuration
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (-66.92%)
Mutual labels:  configuration, hcl
envkeygo
EnvKey's official Go client library
Stars: ✭ 36 (-86.15%)
Mutual labels:  configuration
Simple-YAML
A Java API that provides an easy-to-use way to store data using the YAML format.
Stars: ✭ 68 (-73.85%)
Mutual labels:  configuration
zshrc
📝 Zsh Configuration for nerds with zplug
Stars: ✭ 28 (-89.23%)
Mutual labels:  configuration
Citrix K8s Ingress Controller
Citrix ADC (NetScaler) Ingress Controller for Kubernetes:
Stars: ✭ 256 (-1.54%)
Mutual labels:  hcl
environment
🌳 Environment variable configuration for Node.js made easy.
Stars: ✭ 12 (-95.38%)
Mutual labels:  configuration
Terraform Examples
Terraform samples for all the major clouds you can copy and paste. The future, co-created.
Stars: ✭ 256 (-1.54%)
Mutual labels:  hcl
myawesomerc
My Awesome WM config files
Stars: ✭ 86 (-66.92%)
Mutual labels:  configuration
rails-settings-ui
User interface for manage settings in rails application (using rails-settings gem) / Интерфейс для управления настройками в Rails приложении
Stars: ✭ 93 (-64.23%)
Mutual labels:  configuration
Charles-Proxy-Mobile-Guide
The mobile hackers' guide to Charles Proxy 👍
Stars: ✭ 105 (-59.62%)
Mutual labels:  configuration
project-migration-tools
Project Migration tools to help you migrating to IAR Embedded Workbench more efficiently.
Stars: ✭ 36 (-86.15%)
Mutual labels:  configuration
envconfig-rs
Build a config structure from environment variables in Rust without boilerplate
Stars: ✭ 135 (-48.08%)
Mutual labels:  configuration
Tmux Powerline
A hackable statusbar for tmux consisting of dynamic & beautiful looking segments, inspired by vim-powerlline, written purely in bash.
Stars: ✭ 2,802 (+977.69%)
Mutual labels:  configuration
nest-typed-config
Intuitive, type-safe configuration module for Nest framework ✨
Stars: ✭ 47 (-81.92%)
Mutual labels:  configuration
Cloudblock
Cloudblock automates deployment of secure ad-blocking for all of your devices - even when mobile. Step-by-step text and video guides included! Compatible clouds include AWS, Azure, Google Cloud, and Oracle Cloud. Cloudblock deploys Wireguard VPN, Pi-Hole DNS Ad-blocking, and DNS over HTTPS in a cloud provider - or locally - using Terraform and Ansible.
Stars: ✭ 257 (-1.15%)
Mutual labels:  hcl
LKI
LKI's dotfiles.
Stars: ✭ 31 (-88.08%)
Mutual labels:  configuration
goconfig
.gitconfig syntax parser
Stars: ✭ 15 (-94.23%)
Mutual labels:  configuration
xcode-config
My Xcode config - Alfred Workflow, File templates, Xcode code snippets, themes, IDETextKeyBindingSet
Stars: ✭ 16 (-93.85%)
Mutual labels:  configuration

pyhcl

|Build Status|

Implements a parser for HCL (HashiCorp Configuration Language) <https://github.com/hashicorp/hcl>__ in Python. This implementation aims to be compatible with the original golang version of the parser.

pyhcl does not support HCL2 (which is what modern terraform uses). You might try https://pypi.org/project/python-hcl2/ instead (though I've never personally tried it).

The grammar and many of the tests/fixtures were copied/ported from the golang parser into pyhcl. All releases are tested with a variety of python versions from Python 2.7 onward.

This version has been modified to work with terraform 0.12 syntax.
It should be backward compatible with earlier versions.
It doesn't cover every situation. See discussion in pull request: https://github.com/virtuald/pyhcl/pull/57

Installation

::

pip install pyhcl

Usage

This module is intended to be used in mostly the same way that one would use the json module in python, and load/loads/dumps are implemented.

::

import hcl

with open('file.hcl', 'r') as fp:
    obj = hcl.load(fp)

Currently the dumps function outputs JSON, and not HCL.

Convert HCL to JSON

pyhcl comes with a script that you can use to easily convert HCL to JSON, similar to the json.tool that comes with python::

hcltool INFILE [OUTFILE]

Structure Validation

Similar to JSON, the output of parsing HCL is a python dictionary with no defined structure. The golang library for HCL implements support for parsing HCL according to defined objects, but this implementation does not currently support such constructs.

Instead, I recommend that you use tools designed to validate JSON, such as the schematics <https://pypi.python.org/pypi/schematics>_ library.

Syntax

  • Single line comments start with # or //

  • Multi-line comments are wrapped in /* and */

  • Values are assigned with the syntax key = value (whitespace doesn't matter). The value can be any primitive: a string, number, boolean, object, or list.

  • Strings are double-quoted and can contain any UTF-8 characters. Example: "Hello, World"

  • Numbers are assumed to be base 10. If you prefix a number with 0x, it is treated as a hexadecimal. If it is prefixed with 0, it is treated as an octal. Numbers can be in scientific notation: "1e10".

  • Boolean values: true, false

  • Arrays can be made by wrapping it in []. Example: ["foo", "bar", 42]. Arrays can contain primitives and other arrays, but cannot contain objects. Objects must use the block syntax shown below.

Objects and nested objects are created using the structure shown below::

variable "ami" {
    description = "the AMI to use"
}

Testing

To run the tests::

pip install -r testing-requirements.txt
tests/run_tests.sh

Debug Mode

To enable debug mode::

import hcl
hcl.parser.DEBUG = True

Authors

Dustin Spicuzza ([email protected])

Note: This project is not associated with Hashicorp

.. |Build Status| image:: https://travis-ci.org/virtuald/pyhcl.svg?branch=master :target: https://travis-ci.org/virtuald/pyhcl

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].