However, it gives the error # janus.PrologError: janus:py_call/4: Unknown procedure: happy/1. Moreover, calling janus.query_once("listing(X)") shows that the literal string 'happy(A):- rich(A)' is added to the database.
What is the correct way to assert rules with Janus?
Your first attempt fails because the query succeeds, trying to return the binding for the variable to Python, but as Python cannot represent logical variables, this fails. The error should be better. The second approach fails as well because you cannot create an arbitrary Prolog term from Python. Possibly we should add a constructor to the class Term. There are several ways to add a rule.
You can cheat by adding ,fail, that will fail, so there are no bindings to report.