JSON Logic Qubit Python Parser

0.9.1 · maintenance · verified Wed Apr 15

json-logic-qubit is a Python parser that accepts JsonLogic rules and executes them. It is a port of the JavaScript json-logic-js project, designed to allow sharing rules (logic) between front-end and back-end code, and for storing logic in databases. The current version is 0.9.1. The project appears to be in maintenance mode with infrequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use the `jsonLogic` function with both a simple comparison rule and a more complex, data-driven rule that checks nested properties.

from json_logic import jsonLogic

# Simple rule: 1 == 1
result1 = jsonLogic({ "==" : [1, 1] })
print(f"Simple rule (1 == 1): {result1}")

# Data-driven rule: check if 'temp' < 110 AND 'pie.filling' == 'apple'
rules = {
    "and" : [
        { "<" : [ { "var" : "temp" }, 110 ] },
        { "==" : [ { "var" : "pie.filling" }, "apple" ] }
    ]
}
data = { "temp" : 100, "pie" : { "filling" : "apple" } }

result2 = jsonLogic(rules, data)
print(f"Complex rule (pie ready): {result2}")

view raw JSON →