PyPLE (pronounced "pipple") is the Python Persistent Logic Engine—a framework for composing, evaluating, and storing logical expressions. With PyPLE, you can compose complex chains of simple logical operators and store them in a database. You can then apply those chains of logic to any data you like.
PyPLE now uses SQLObject for database connectivity and object-relational mapping. If you are a Python developer and don't know about SQLObject, check it out!
>>> import pyple >>> import yaml # use PyYAML for loading DB connection parameters >>> >>> E = pyple.Engine() # instantiate a PyPLE engine >>> E.connect_to_db(pyple.Engine.build_db_uri(yaml.load(open('pyple-db.yaml').read()))) # Connect to the DB Connecting to DB with: mysql://pyple:pyple@localhost:3306/pyple2?debug=1 Connected to DB: <sqlobject.mysql.mysqlconnection.MySQLConnection instance at 0x11e5d50> >>> >>> starts_with_foo = pyple.Regex(pattern="^foo") 1/QueryIns: INSERT INTO operator (name, child_name) VALUES (NULL, 'Regex') 1/QueryOne: SELECT name, child_name FROM operator WHERE id = (1) 1/QueryIns: INSERT INTO op_regex (id, pattern, child_name, case_sensitive) VALUES (1, '^foo', NULL, 0) 1/QueryOne: SELECT pattern, case_sensitive, child_name FROM op_regex WHERE id = (1) >>> starts_with_foo.eval("foo bar!") True >>> starts_with_foo.eval("bar foo!") False >>> >>> always_true = pyple.AlwaysTrueOp() 1/QueryIns: INSERT INTO operator (name, child_name) VALUES (NULL, 'AlwaysTrueOp') 1/QueryOne: SELECT name, child_name FROM operator WHERE id = (2) 1/QueryIns: INSERT INTO always_true_op (id, child_name) VALUES (2, NULL) 1/QueryOne: SELECT child_name FROM always_true_op WHERE id = (2) >>> >>> always_false = pyple.AlwaysFalseOp() 1/QueryIns: INSERT INTO operator (name, child_name) VALUES (NULL, 'AlwaysFalseOp') 1/QueryOne: SELECT name, child_name FROM operator WHERE id = (3) 1/QueryIns: INSERT INTO always_false_op (id, child_name) VALUES (3, NULL) 1/QueryOne: SELECT child_name FROM always_false_op WHERE id = (3) >>> >>> false_and_starts_with_foo = pyple.AND() 1/QueryIns: INSERT INTO operator (name, child_name) VALUES (NULL, 'AND') 1/QueryOne: SELECT name, child_name FROM operator WHERE id = (4) 1/QueryIns: INSERT INTO op_and (id, child_name) VALUES (4, NULL) 1/QueryOne: SELECT child_name FROM op_and WHERE id = (4) >>> >>> false_and_starts_with_foo.addParameter(always_false) 1/Query : INSERT INTO operator_operator (parameter_id, operator_id) VALUES (4, 3) >>> >>> false_and_starts_with_foo.addParameter(starts_with_foo) 1/Query : INSERT INTO operator_operator (parameter_id, operator_id) VALUES (4, 1) >>> >>> false_and_starts_with_foo.eval('foo bar blah blah') 1/QueryAll: SELECT operator_id FROM operator_operator WHERE parameter_id = (4) False >>> >>> test_or = pyple.OR() 1/QueryIns: INSERT INTO operator (name, child_name) VALUES (NULL, 'OR') 1/QueryOne: SELECT name, child_name FROM operator WHERE id = (5) 1/QueryIns: INSERT INTO op_or (id, child_name) VALUES (5, NULL) 1/QueryOne: SELECT child_name FROM op_or WHERE id = (5) >>> >>> test_or.addParameter(false_and_starts_with_foo) 1/Query : INSERT INTO operator_operator (parameter_id, operator_id) VALUES (5, 4) >>> >>> test_or.addParameter(always_true) 1/Query : INSERT INTO operator_operator (parameter_id, operator_id) VALUES (5, 2) >>> >>> test_or.eval('foo.. spam??') 1/QueryAll: SELECT operator_id FROM operator_operator WHERE parameter_id = (5) 1/QueryAll: SELECT operator_id FROM operator_operator WHERE parameter_id = (4) >>> >>> test_or.eval('this does not start with foo') 1/QueryAll: SELECT operator_id FROM operator_operator WHERE parameter_id = (5) 1/QueryAll: SELECT operator_id FROM operator_operator WHERE parameter_id = (4) True >>>