Skip to main content

Python bindings to Rust jrsonnet crate

Project description

rjsonnet-py

CI PyPI

Python bindings to Rust jrsonnet crates (Rust implementation of Jsonnet language).

Installation

pip install rjsonnet

Usage

This module provides two functions:

  1. def evaluate_file(filename: str) -> str: ...
  2. def evaluate_snippet(filename: str, src: str) -> str: ...

In the latter case, the parameter filename is used in stack traces, because all errors are given with the "filename" containing the code.

Keyword arguments to these functions are used to control the virtual machine. They are:

  • max_stack (number)
  • gc_min_objects (number, ignored)
  • gc_growth_trigger (number, ignored)
  • ext_vars (dict, string to string)
  • ext_codes (dict, string to string)
  • tla_vars (dict, string to string)
  • tla_codes (dict, string to string)
  • max_trace (number)
  • import_callback (see example in tests/)
  • native_callbacks (see example in tests/)
  • preserve_order (bool, preserve object field order during manifestification)

The argument import_callback can be used to pass a callable, to trap the Jsonnet import and importstr constructs. This allows, e.g., reading files out of archives or implementing library search paths.

The argument native_callbacks is used to allow execution of arbitrary Python code via std.native(...). This is useful so Jsonnet code can access pure functions in the Python ecosystem, such as compression, encryption, encoding, etc.

If an error is raised during the evaluation of the Jsonnet code, it is formed into a stack trace and thrown as a python RuntimeError.

import rjsonnet

# evaluate a jsonnet file
rjsonnet.evaluate_file("filename.jsonnet")

# evalute a jsonnet code snippet
rjsonnet.evaluate_snippet('filename', 'jsonnet code snippet')

License

This work is released under the MIT license. A copy of the license is provided in the LICENSE file.

Project details


Download files

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

Source Distribution

rjsonnet-0.5.4.tar.gz (15.8 kB view hashes)

Uploaded Source

Built Distributions

rjsonnet-0.5.4-cp37-abi3-win_amd64.whl (946.1 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

rjsonnet-0.5.4-cp37-abi3-win32.whl (876.0 kB view hashes)

Uploaded CPython 3.7+ Windows x86

rjsonnet-0.5.4-cp37-abi3-musllinux_1_2_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ x86-64

rjsonnet-0.5.4-cp37-abi3-musllinux_1_2_i686.whl (1.4 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ i686

rjsonnet-0.5.4-cp37-abi3-musllinux_1_2_armv7l.whl (1.5 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARMv7l

rjsonnet-0.5.4-cp37-abi3-musllinux_1_2_aarch64.whl (1.4 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARM64

rjsonnet-0.5.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

rjsonnet-0.5.4-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

rjsonnet-0.5.4-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

rjsonnet-0.5.4-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

rjsonnet-0.5.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

rjsonnet-0.5.4-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (1.3 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.5+ i686

rjsonnet-0.5.4-cp37-abi3-macosx_10_12_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ macOS 10.12+ x86-64

rjsonnet-0.5.4-cp37-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (2.2 MB view hashes)

Uploaded CPython 3.7+ macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

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