Hacker News new | ask | show | jobs
Show HN: Serializable infix expressions and a Python evaluator (github.com)
1 points by sb13 762 days ago
I had written a tiny Python utility for evaluating serializable infix expressions a couple of years ago (inspired by JsonLogic). Last week, I talked to an old colleague who was looking for something very identical so I thought I'd share it here.

Quick examples:

xpress.evaluate([[3, ">", 1], "and", [1, "<", 3]]) # True

rules = [["var:temp", "<", 110], "and", ["var:pie.filling", "==", "apple"]]

data = { "temp" : 100, "pie" : { "filling" : "apple" } }

xpress.evaluate(rules, data) # True

The original purpose was building a flexible query builder. Later, I also used it for expressing log routing conditions in our config file.