Jsonnet is a data templating language that helps you generate configuration data. The `jsonnet` Python library provides official Python bindings for the original C++ implementation, allowing evaluation of Jsonnet code from Python. The current version is 0.22.0, released on March 24, 2026. Releases are made periodically, typically driven by updates to the core Jsonnet language and its C++ implementation.
pip install jsonnetVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to evaluate a Jsonnet snippet using `_jsonnet.evaluate_snippet` and access external variables. The output is a JSON string, which is then parsed into a Python dictionary.
Ensure bitwise operation arguments are within the safe-integer range. Review usage of `std.objectRemoveKey` if upgrading from pre-0.22.0 versions.
For most users installing via `pip`, this should be seamless. If you encounter build issues when installing from source, ensure your Python environment and compiler toolchain are up-to-date and compatible with ABI3.
NEVER evaluate untrusted Jsonnet code without robust sandboxing (e.g., gVisor, Firecracker VM) and/or implementing a custom `import_callback` to restrict file access. For API servers, `exec` the Jsonnet CLI in a `ulimit` child process to bound CPU/RAM.
Always provide the `jpathdir` argument (a string or list of directory paths) to `evaluate_snippet` if your Jsonnet code uses imports, or implement a custom `import_callback` function for more advanced import logic. Example: `_jsonnet.evaluate_snippet('name', snippet_code, jpathdir=['./my_jsonnet_libs'])`.Be mindful of Jsonnet's lazy evaluation model, especially when debugging errors or optimizing performance. Understand that variable initializers are not evaluated until the variable is used. Explicit assertions can help pinpoint evaluation issues.
pip install jsonnet
Ensure that all variables referenced in the Jsonnet code are either defined within the Jsonnet file itself, or passed as `ext_vars`, `ext_codes`, `tla_vars`, or `tla_codes` arguments to `_jsonnet.evaluate_file` or `_jsonnet.evaluate_snippet` in Python. For example: `_jsonnet.evaluate_snippet('snippet.jsonnet', 'std.extVar("myVar")', ext_vars={'myVar': 'value'})`Provide a `jpathdir` argument (a string or list of strings) to `_jsonnet.evaluate_file` or `_jsonnet.evaluate_snippet` to specify directories where imported files should be searched. Alternatively, implement a custom `import_callback` function to handle file resolution logic.
Ensure your Python environment, build tools, and `jsonnet` installation are consistent. Try reinstalling `jsonnet` in a clean virtual environment or updating your system's development tools (e.g., Xcode on macOS, build-essential on Linux). If building from source, ensure the correct Python version's headers are used. This specific error has been noted in older Python 3.5 contexts.
Examine the Jsonnet code snippet or file at the indicated line and column to correct the syntax or logic error.
No dependency data recorded yet.