Python
SolveResult
SolveResult class and public members in the unified Python API.Class: SolveResult
Internal constructor — do not call. Native result returned by Session.solve or Ruleset.solve; do not manufacture native handles.
- returned by
Ruleset.solve()Evaluates one complete input batch using a private session created for this call. Use prepare() when the same session should be reused for multiple requests.
- returned by
Session.solve()Evaluates a complete input batch using this prepared session. Release its previous result before solving another request; facts are not implicitly inherited. Ordinary solving is unavailable while retained input is attached.
- returned by
SessionInputs.apply()Applies an atomic delta to retained input and solves it. Additions win when the same fact is added and removed.
- returned by
SessionInputs.replace()Atomically replaces the complete retained dynamic input and solves it. The raw fact-capacity bound applies before deduplication.
- SolveResult.close()Releases this result, including any private session created by Ruleset.solve(). An explicitly prepared session remains available for another request.
- SolveResult.contains_fact()Checks whether one fully specified fact is present in the existing result. It does not solve the policy again.
- SolveResult.derived_fact_count()Reads how many facts were derived during this solve, without enumerating the model or deriving more facts.
- SolveResult.enumerate_predicate_facts()Lists a query-enabled derived relation as ordinary Python values copied from the result.
- SolveResult.enumerate_raw()Lists a derived relation as typed ResultTerm records, keeping symbols as IDs local to this live result.
- SolveResult.explain_false()Investigates obstacles to deriving an absent fact and produces a bounded Why-false document. It is not an exhaustive proof of all possible obstructions.
- SolveResult.explain_true()Explains a derivation of the requested fact as a bounded Why-true document, using the existing solve result.
- SolveResult.resolve_term()Converts a raw term from this result into its ordinary Python string, integer or boolean value.
- with result:Leaving the block closes this result.
with session.solve(edb) as result:
print("fingerprint:", result.fingerprint)
print("execution_fingerprint:", result.execution_fingerprint)
print("allowed:", result.contains_fact("allow", ["alice", "roadmap.pdf"]))fingerprint: c5ec08d836b313af6e49ab7c49e811d84e0e856884fab645282d74682ceac454 execution_fingerprint: 14c485089d7dfee8a190afa1f103684c77911b99a4cbd9ec27bc414dd919d141 allowed: True
Methods
Each method has its own signature, arguments, return behavior and stable link.
SolveResult.close
Release the answer once its queries are finished, so an explicit Session can accept another request.
SolveResult.close() -> NoneNoneReturns None after native result release. ResultTerm views can no longer be resolved. A private session created by Ruleset.solve() is also closed; an explicit prepared Session remains reusable.
SolveResult.contains_fact
Ask whether a fully specified, query-permitted fact is present in the solved model. This does not run the solver again.
SolveResult.contains_fact(
predicate: str,
terms: Sequence[object]
) -> boolboolReturns True for a present fact and False for an absent fact. Invalid predicates, arity or query permissions raise MaelysDatalogError, not False. Runtime EDB, policy facts and derived IDB may be queried when permitted.
allowed = result.contains_fact("allow", ["alice", "roadmap.pdf"])
print(allowed)SolveResult.derived_fact_count
Read the total number of distinct IDB facts already derived in this result; this is not the number of input entries.
SolveResult.derived_fact_count() -> intintReturns an int. It does not derive more facts or enumerate the model. A closed result raises RuntimeError; native failures raise MaelysDatalogError.
print("derived_facts:", result.derived_fact_count())derived_facts: 1
SolveResult.enumerate_predicate_facts
Enumerate a queryable derived predicate when you need its rows rather than a single yes/no decision.
SolveResult.enumerate_predicate_facts(
predicate: str,
arity: int
) -> list[tuple[object, ...]]list[tuple[object, ...]]Returns a list of tuples containing str, int and bool values, in native enumeration order. The copies survive result closure. Only derived IDB facts are enumerated; invalid queries raise exceptions.
rows = result.enumerate_predicate_facts("allow", 2)
users = [user for user, doc in rows if doc == "roadmap.pdf"]
print(users)['alice']
SolveResult.enumerate_raw
Use raw enumeration to inspect kinds and result-local identity without resolving every symbol immediately.
SolveResult.enumerate_raw(
predicate: str,
arity: int
) -> list[tuple[ResultTerm, ...]]list[tuple[ResultTerm, ...]]Returns tuples of immutable ResultTerm values. Symbol IDs belong only to this live result and cannot be used as later inputs. Resolve them before closing the result.
rows = result.enumerate_raw("allow", 2)
for user, document in rows:
print("raw:", user, document)
print("resolved:", user.resolve(), document.resolve())raw: ResultTerm(kind='symbol', value=1) ResultTerm(kind='symbol', value=3) resolved: alice roadmap.pdf
SolveResult.explain_false
For a successful negative membership answer, inspect the obstacles found by the bounded Why-false exploration.
SolveResult.explain_false(
predicate: str,
terms: Sequence[object]
) -> strstrReturns an independent str containing the native MAELYS-DATALOG-v2 document with document=why-false. Exploration may be truncated; this is not a proof of every possible obstruction. For a fact already present, the document is not-applicable. Unknown symbol values and native query or capability errors raise MaelysDatalogError.
if not result.contains_fact("allow", ["mallory", "roadmap.pdf"]):
print(result.explain_false("allow", ["mallory", "roadmap.pdf"]))Show output (11 lines)
MAELYS-DATALOG-v2
document=why-false
status=complete
query="allow"("mallory","roadmap.pdf") origin=none
summary=none
limit-hits=none candidate-rules=1 substitutions=0 diagnostics=1 filter-cost=0
diagnostic=0 rule=1 depth=0 target="allow"("mallory","roadmap.pdf")
binding=0 value="mallory"
binding=1 value="roadmap.pdf"
obstacle=positive-no-match body=0 origin=none pattern="owns"("mallory","roadmap.pdf")
SolveResult.explain_true
After a successful membership check, ask for a witness supporting a derived IDB fact. An explanation does not solve the policy again.
SolveResult.explain_true(
predicate: str,
terms: Sequence[object]
) -> strstrReturns an independent str containing the native MAELYS-DATALOG-v2 document with document=why-true. Inspect its status: it may be complete, truncated or not-derived. Unknown symbol values and native query or capability errors raise MaelysDatalogError.
if result.contains_fact("allow", ["alice", "roadmap.pdf"]):
print(result.explain_true("allow", ["alice", "roadmap.pdf"]))Show output (9 lines)
MAELYS-DATALOG-v2
document=why-true
status=complete
steps=1 premises=2
step=0 rule=1 fact="allow"("alice","roadmap.pdf")
premise=0 body=0 kind=positive origin=edb fact="owns"("alice","roadmap.pdf") parent=-
premise=1 body=1 kind=negative-absence origin=edb fact="blocked"("alice") parent=-
result-step=0
SolveResult.resolve_term
Convert a raw output term to a plain Python value through the same live result that produced it.
SolveResult.resolve_term(
term: ResultTerm
) -> objectobjectReturns str for a symbol, int for an integer, or bool for a boolean. A foreign or non-ResultTerm value raises ValueError; use after result closure raises RuntimeError.
term = result.enumerate_raw("allow", 2)[0][0]
user = result.resolve_term(term)
print("user:", user)user: alice
Protocols
with result:
Exiting the context delegates to close(), including on exceptional exit. Cleanup does not suppress the exception.
with session.solve(edb) as result:
print(result.contains_fact("allow", ["alice", "roadmap.pdf"]))Perform the same operations with explicit cleanup in a finally block.
result = session.solve(edb)
try:
print(result.contains_fact("allow", ["alice", "roadmap.pdf"]))
finally:
result.close()