https://github.com/altescy/pysonnet
📜 A pure Python implementation of the Jsonnet language
https://github.com/altescy/pysonnet
jsonnet python
Last synced: 6 months ago
JSON representation
📜 A pure Python implementation of the Jsonnet language
- Host: GitHub
- URL: https://github.com/altescy/pysonnet
- Owner: altescy
- License: mit
- Created: 2024-02-07T09:56:21.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-20T17:44:48.000Z (over 1 year ago)
- Last Synced: 2024-04-14T04:19:26.602Z (over 1 year ago)
- Topics: jsonnet, python
- Language: Python
- Homepage:
- Size: 257 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 📜 Pysonnet
[](https://github.com/altescy/pysonnet/actions/workflows/ci.yml)
[](https://github.com/altescy/pysonnet)
[](https://github.com/altescy/pysonnet/blob/main/LICENSE)
[](https://pypi.org/project/pysonnet/)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
```shell
pip install pysonnet
```## Usage
Evaluate a jsonnet file and generate a JSON string:
```python
import pysonnetjson_string = pysonnet.evaluate_file("path/to/file.jsonnet", ext_vars={...})
```Load a string and generate a Python object:
```python
import pysonnetoutput = 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:
```shell
pysonnet path/to/file.jsonnet
```