pyhcl


Namepyhcl JSON
Version 0.4.5 PyPI version JSON
download
home_pagehttps://github.com/virtuald/pyhcl
SummaryHCL configuration parser for python
upload_time2023-09-01 05:25:16
maintainer
docs_urlNone
authorDustin Spicuzza
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pyhcl
=====

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 (dustin@virtualroadside.com)

Note: This project is not associated with Hashicorp

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/virtuald/pyhcl",
    "name": "pyhcl",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Dustin Spicuzza",
    "author_email": "dustin@virtualroadside.com",
    "download_url": "https://files.pythonhosted.org/packages/20/b9/ff5019eef43b613f49a4695253d8814f8a7012745ae570158e5b64967200/pyhcl-0.4.5.tar.gz",
    "platform": null,
    "description": "pyhcl\n=====\n\nImplements a parser for `HCL (HashiCorp Configuration\nLanguage) <https://github.com/hashicorp/hcl>`__ in Python. This\nimplementation aims to be compatible with the original golang version of\nthe parser.\n\npyhcl does not support HCL2 (which is what modern terraform uses). You might try\nhttps://pypi.org/project/python-hcl2/ instead (though I've never personally tried it).\n\nThe grammar and many of the tests/fixtures were copied/ported from the\ngolang parser into pyhcl. All releases are tested with a variety of \npython versions from Python 2.7 onward.\n\nThis version has been modified to work with terraform 0.12 syntax.  \nIt should be backward compatible with earlier versions.  \nIt doesn't cover every situation.  See discussion in pull request:\nhttps://github.com/virtuald/pyhcl/pull/57\n\nInstallation\n============\n\n::\n\n    pip install pyhcl\n\nUsage\n=====\n\nThis module is intended to be used in mostly the same way that one would\nuse the json module in python, and load/loads/dumps are implemented.\n\n::\n\n    import hcl\n\n    with open('file.hcl', 'r') as fp:\n        obj = hcl.load(fp)\n\nCurrently the dumps function outputs JSON, and not HCL.\n\nConvert HCL to JSON\n-------------------\n\npyhcl comes with a script that you can use to easily convert HCL to JSON,\nsimilar to the json.tool that comes with python::\n\n\thcltool INFILE [OUTFILE]\n\t\nStructure Validation\n--------------------\n\nSimilar to JSON, the output of parsing HCL is a python dictionary with\nno defined structure. The golang library for HCL implements support for\nparsing HCL according to defined objects, but this implementation does\nnot currently support such constructs.\n\nInstead, I recommend that you use tools designed to validate JSON, such\nas the `schematics <https://pypi.python.org/pypi/schematics>`_ library. \n\nSyntax\n======\n\n-  Single line comments start with ``#`` or ``//``\n\n-  Multi-line comments are wrapped in ``/*`` and ``*/``\n\n-  Values are assigned with the syntax ``key = value`` (whitespace\n   doesn't matter). The value can be any primitive: a string, number,\n   boolean, object, or list.\n\n-  Strings are double-quoted and can contain any UTF-8 characters.\n   Example: ``\"Hello, World\"``\n\n-  Numbers are assumed to be base 10. If you prefix a number with 0x, it\n   is treated as a hexadecimal. If it is prefixed with 0, it is treated\n   as an octal. Numbers can be in scientific notation: \"1e10\".\n\n-  Boolean values: ``true``, ``false``\n\n-  Arrays can be made by wrapping it in ``[]``. Example:\n   ``[\"foo\", \"bar\", 42]``. Arrays can contain primitives and other\n   arrays, but cannot contain objects. Objects must use the block syntax\n   shown below.\n\nObjects and nested objects are created using the structure shown below::\n\n    variable \"ami\" {\n        description = \"the AMI to use\"\n    }\n\nTesting\n=======\n\nTo run the tests::\n\n    pip install -r testing-requirements.txt\n    tests/run_tests.sh\n    \nDebug Mode\n----------\n\nTo enable debug mode::\n\n    import hcl\n    hcl.parser.DEBUG = True\n\nAuthors\n=======\n\nDustin Spicuzza (dustin@virtualroadside.com)\n\nNote: This project is not associated with Hashicorp\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "HCL configuration parser for python",
    "version": "0.4.5",
    "project_urls": {
        "Homepage": "https://github.com/virtuald/pyhcl"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8b4b766fd33774b55cc15f240916219c4ce9c1bd7bef4acd997ad36ff3622d0",
                "md5": "2d3099daf8b7d0f7b77cd9f30e55d0b0",
                "sha256": "30ee337d330d1f90c9f5ed8f49c468f66c8e6e43192bdc7c6ece1420beb3070c"
            },
            "downloads": -1,
            "filename": "pyhcl-0.4.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2d3099daf8b7d0f7b77cd9f30e55d0b0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 50160,
            "upload_time": "2023-09-01T05:25:15",
            "upload_time_iso_8601": "2023-09-01T05:25:15.237540Z",
            "url": "https://files.pythonhosted.org/packages/a8/b4/b766fd33774b55cc15f240916219c4ce9c1bd7bef4acd997ad36ff3622d0/pyhcl-0.4.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "20b9ff5019eef43b613f49a4695253d8814f8a7012745ae570158e5b64967200",
                "md5": "bc426b4242875e2af665d578f9423b7a",
                "sha256": "c47293a51ccdd25e18bb5c8c0ab0ffe355b37c87f8d6f9d3280dc41efd4740bc"
            },
            "downloads": -1,
            "filename": "pyhcl-0.4.5.tar.gz",
            "has_sig": false,
            "md5_digest": "bc426b4242875e2af665d578f9423b7a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 61772,
            "upload_time": "2023-09-01T05:25:16",
            "upload_time_iso_8601": "2023-09-01T05:25:16.788996Z",
            "url": "https://files.pythonhosted.org/packages/20/b9/ff5019eef43b613f49a4695253d8814f8a7012745ae570158e5b64967200/pyhcl-0.4.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-01 05:25:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "virtuald",
    "github_project": "pyhcl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pyhcl"
}
        
Elapsed time: 0.11450s