{"id":6023,"library":"panzi-json-logic","title":"panzi-json-logic: JsonLogic and CertLogic Implementation","description":"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.","status":"maintenance","version":"1.0.1","language":"en","source_language":"en","source_url":"https://github.com/panzi/panzi-json-logic","tags":["JsonLogic","CertLogic","rules engine","pure python","logic","declarative"],"install":[{"cmd":"pip install panzi-json-logic","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary evaluation function `jsonLogic` is directly imported from the `json_logic` package.","wrong":"import json_logic","symbol":"jsonLogic","correct":"from json_logic import jsonLogic"}],"quickstart":{"code":"from json_logic import jsonLogic\n\n# Simple rule evaluation\nrule_simple = { \"==\": [1, 1] }\nresult_simple = jsonLogic(rule_simple)\nprint(f\"Simple rule (1 == 1): {result_simple}\")\n\n# Data-driven rule evaluation\nrule_data = { \">\": [{ \"var\": \"temp\" }, 100] }\ndata = { \"temp\": 105 }\nresult_data = jsonLogic(rule_data, data)\nprint(f\"Data-driven rule (temp > 100 with temp=105): {result_data}\")\n\n# Custom operations (example: using UTF16_SUBSTR for JS-like substr behavior)\nfrom json_logic.builtins import UTF16_SUBSTR\ncustom_operations = { 'substr_utf16': UTF16_SUBSTR }\nrule_substr = { 'substr_utf16': ['hello world', 0, 5] }\nresult_substr = jsonLogic(rule_substr, operations=custom_operations)\nprint(f\"Custom substr (hello world, 0, 5): {result_substr}\")","lang":"python","description":"Demonstrates basic rule evaluation, including a data-driven example and how to register a custom operation, such as the UTF-16 specific substring implementation."},"warnings":[{"fix":"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})`.","message":"The `substr` operator in `panzi-json-logic` operates on Unicode code points, which differs from the `json-logic-js` JavaScript implementation that operates on UTF-16 code units. This can lead to different string slicing behavior for certain non-ASCII strings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `===` for strict type-and-value equality comparisons to avoid implicit type coercion behavior.","message":"The `==` operator attempts to emulate JavaScript's loose equality, which performs type coercion. This can lead to unexpected results if Python's strict `==` behavior is anticipated. For strict equality, use the `===` operator.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all JsonLogic rule definitions strictly adhere to the JSON specification. Use a JSON linter or validator for complex rules.","message":"JsonLogic rules are standard JSON. Common JSON syntax errors (e.g., trailing commas, unquoted keys, single quotes instead of double quotes, incorrect casing for `true`/`false`/`null`) will cause parsing failures before the logic can be evaluated.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}