Python V1 · Deprecated
Solving
Solving in the Python V1 binding.The Python V1 solving reference continues the Python V1 overview.
Solve
edb = ruleset.edb()
edb.add_fact('owns', ['alice', 'roadmap.pdf'])
result = ruleset.solve(edb)
result.enumerate_predicate_facts('allow', 2) # [('alice', 'roadmap.pdf')]Unlike WASM's clearFacts(), which clears the input after releasing its live result inside one MaelysPlayground
instance, ruleset.edb() returns a new, independent object every time —
nothing to reset, no session to carry state across by accident. ruleset.solve(edb)
finalizes edb exactly once before calling the native solver; after a
successful solve, edb is closed for mutation — a later add_fact()
raises RuntimeError before reaching C. Calling solve() again on the same,
already-finalized edb is allowed and reuses the finalized snapshot; it does
not require adding facts again.
Diagnostics
from maelys_datalog import MaelysDatalogError
try:
ruleset = engine.load_inline_ruleset('document_access', 'doc.main', bad_source)
except MaelysDatalogError as exc:
exc.code # int — last error code
exc.message # str — last error message
exc.hint # str — corrective hint, empty string if nonehint mirrors the C-level hint field of maelys_datalog_diagnostic_t —
see Errors — Diagnostic codes.
The current WASM binding likewise carries an
independent diagnostic snapshot on its error, instead of mutable instance fields.
Derived fact count
result = ruleset.solve(edb)
result.derived_fact_count() # int — total IDB facts derived by this solveSame meaning as WASM's derivedFactCount() — a property of one solve, not a
session constant. A SolveResult corresponds to exactly one solve() call,
so there is no "current EDB session" to read it against; call it on the
SolveResult returned by the solve() you care about.