jsonnet 0.22.0


pip install jsonnet

  Latest version

Released: Mar 24, 2026

Project Links

Meta
Author: David Cunningham

Classifiers

Jsonnet - The data templating language

For an introduction to Jsonnet and documentation, visit our website.

This is the Python module for the original C++ implementation of Jsonnet.

Security notes: The C++ implementation is not suitable for processing untrusted inputs without significant external effort to sandbox it. It is not hardened and may have unknown exploitable bugs. It is intended for use to evaluate Jsonnet code that you trust not to be malicious (e.g., code written by you/your organisation). Even ignoring the risk of exploitable bugs in the implementation, the import, importstr, and importbin language constructs can potentially be used to exfiltrate sensitive data unless you take extra steps to restrict these or sandbox the jsonnet interpreter. By default, these constructs can import from any path accessible to the interpreter process.

Using the Jsonnet Python module

You can install from PyPI with uv add jsonnet or with your preferred Python package management tool.

The two main functions in the _jsonnet package are evaluate_file and evaluate_snippet:

  • evaluate_file(filename, ...) reads and evalutes the file at the given path, returning an output as a JSON string.
  • evaluate_snippet(filename, src, ...) evaluates the given source code (src), returning an output as a JSON string. The provided filename is used in error messages.

The functions support keyword arguments:

  • jpathdir: A string (path to a directory) or list of strings (list of directories) to be added to the import search path.
  • ext_vars, ext_codes: Dictionaries of variables to set; these can be used from within the evaluated code through the std.extVar Jsonnet function. ext_codes values are Jsonnet expressions, ext_vars values are provided to Jsonnet as plain strings.
  • tla_vars, tla_codes: Dictionaries of Top-Level arguments. If the provided Jsonnet code to evaluate represents a function, that function is called with these values as (named) arguments.
  • import_callback: A function which will be called when import (or importstr, importbin) expressions are evaluated. See below.
  • native_callbacks: A dictionary of functions which can be called from Jsonnet using the Jsonnet std.native function. See below.

And some configuration for internal implementation details:

  • max_stack
  • max_trace
  • gc_min_objects
  • gc_growth_trigger

import_callback

Usage example:

import _jsonnet

FILES = {
    "the_message.txt": b"hello, world",
}

def import_callback_memfile(dir, rel):
    """Custom import function which only returns files from some in-memory storage.
    
    Args:
      dir: The directory part of the file in which the `import` occurred.
      rel: The path string passed to the `import` expression.
    """
    if rel in FILES:
        # Note that the returned file _content_ should be a bytes value, not a string.
        return rel, FILES[rel]
    raise RuntimeError('File not found')

result = _jsonnet.evaluate_snippet(
    'example',
    'local the_message = importstr "the_message.txt"; ' +
    '{ msg: the_message }',
    import_callback=import_callback_memfile)

assert result == '{\n   "msg": "hello, world"\n}\n';

native_callbacks

Usage example:

import _jsonnet

def concat(a, b):
    return a + b
    
native_callbacks = {
    'concat': (('a', 'b'), concat),
}

result = _jsonnet.evaluate_snippet(
    'example',
    'local concat = std.native("concat"); ' +
    'concat("hello, ", "world")',
    native_callbacks=native_callbacks)

assert result == '"hello, world"\n';
0.22.0 Mar 24, 2026
0.22.0rc1 Mar 08, 2026
0.21.0 May 07, 2025
0.21.0rc2 Mar 12, 2025
0.21.0rc1 Feb 22, 2025
0.20.0 Apr 17, 2023
0.20.0rc1 Apr 17, 2023
0.19.1 Oct 27, 2022
0.19.0 Oct 26, 2022
0.19.0rc1 Oct 26, 2022
0.18.0 Dec 21, 2021
0.18.0rc4 Dec 21, 2021
0.18.0rc3 Dec 21, 2021
0.18.0rc2 Dec 21, 2021
0.18.0rc1 Dec 21, 2021
0.17.0 Nov 22, 2020
0.17.0rc1 Nov 22, 2020
0.16.0 May 22, 2020
0.16.0rc1 May 22, 2020
0.15.0 Feb 09, 2020
0.15.0rc1 Feb 09, 2020
0.14.0 Sep 16, 2019
0.14.0rc1 Sep 16, 2019
0.13.0 Jun 03, 2019
0.13.0rc1 Jun 03, 2019
0.12.2rc1 Dec 18, 2018
0.12.1 Dec 19, 2018
0.12.1rc1 Dec 19, 2018
0.12.0 Dec 18, 2018
0.12.0rc1 Dec 18, 2018
0.11.2 Jul 19, 2018
0.11.0 Jul 19, 2018
0.11.0rc1 Jul 19, 2018
0.10.0 Mar 16, 2018
0.10.0rc1 Mar 16, 2018
0.9.5 Sep 30, 2017
0.9.5rc1
0.9.4 Jun 21, 2017
0.9.4rc1
0.9.3 Feb 01, 2017
0.9.3rc1 Feb 01, 2017
0.9.2 Jan 31, 2017
0.9.1 Jan 28, 2017
0.9.0 Oct 17, 2016
0.8.9 Jul 06, 2016
0.8.7 Mar 01, 2016
0.8.7rc6
0.8.7rc5
0.8.7rc4
0.8.7rc3
0.8.7rc2
0.8.7rc1
0.8.6 Dec 12, 2015
0.8.6rc1
0.8.6rc0
0.8.5 Dec 12, 2015
0.8.5rc0
0.8.4 Oct 20, 2015
0.8.4rc1
0.8.3 Oct 20, 2015
0.8.2 Oct 20, 2015
0.8.1 Sep 24, 2015
0.8.0 Aug 20, 2015
0.7.9 Aug 04, 2015
0.7.8 Aug 04, 2015
0.7.7 Jun 05, 2015
0.7.7.dev0
0.7.6 Jun 03, 2015
0.7.5 Jun 02, 2015
No dependencies