pysonnet

📜 A pure Python implementation of the Jsonnet language


Keywords
jsonnet, python
License
MIT
Install
pip install pysonnet==0.0.2

Documentation

📜 Pysonnet

CI Python version License pypi version

A pure Python implementation of the Jsonnet language.

Features:

  • Pure Python Implementation: Fully written in Python, ensuring compatibility and ease of integration with Python projects.
  • No External Dependencies: Operates independently without the need for any external libraries, simplifying installation and use.

Important

Pysonnet is in the early stages of development. While it supports all Jsonnet syntax, it lacks some standard library features, and users might encounter bugs.

Installation

pip install pysonnet

Usage

Evaluate a jsonnet file and generate a JSON string:

import pysonnet

json_string = pysonnet.evaluate_file("path/to/file.jsonnet", ext_vars={...})

Load a string and generate a Python object:

import pysonnet

output = pysonnet.loads(
    """
    local Person(name='Alice') = {
      name: name,
      welcome: 'Hello ' + name + '!',
    };
    {
      person1: Person(),
      person2: Person('Bob'),
    }
    """
)
assert output == {
    "person1": {
        "name": "Alice",
        "welcome": "Hello Alice!"
    },
    "person2": {
        "name": "Bob",
        "welcome": "Hello Bob!"
    }
}

Evaluate file from command line:

pysonnet path/to/file.jsonnet