panzi-json-logic is a Pure Python 3 implementation of JsonLogic and CertLogic. It aims to closely emulate the behavior of the JavaScript JsonLogic specification, including specific operator semantics. The library facilitates sharing declarative rules (logic) between frontend and backend applications, storing them in databases, and evaluating them reliably across different environments. It is currently at version 1.0.1 and appears to be in a maintenance phase, focusing on correctness and compliance with the JsonLogic standard.
pip install panzi-json-logicVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic rule evaluation, including a data-driven example and how to register a custom operation, such as the UTF-16 specific substring implementation.
If strict JavaScript `substr` emulation is required, import and use `json_logic.builtins.UTF16_SUBSTR` as a custom operation: `from json_logic.builtins import UTF16_SUBSTR; jsonLogic(rule, operations={'substr': UTF16_SUBSTR})`.Always use `===` for strict type-and-value equality comparisons to avoid implicit type coercion behavior.
Ensure all JsonLogic rule definitions strictly adhere to the JSON specification. Use a JSON linter or validator for complex rules.
Install the package using pip: `pip install panzi-json-logic`
Ensure the logic passed to `evaluate()` is a dictionary, structured as `{"operator": [arguments, ...]}`.Use one of the standard JsonLogic operators (e.g., `and`, `or`, `==`, `>`, `<`, `+`, `-`) or register a custom operator using `JsonLogic().add_operator('my_op', my_function)`.Ensure that the data passed to operators has compatible types. Pre-process the input data to convert types as needed before evaluation.
No dependency data recorded yet.