News for hackers. Stuff that matters.

Show HN: Serializable infix expressions and a Python evaluator

https://github.com/shrir/xpress

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.

( no comments | on HN )

There are no comments yet.