Python
SessionInputs
Retained session input in the unified Python API.Class: SessionInputs
Internal constructor — do not call. Created by Session.inputs; the binding rejects direct construction without its private token.
- returned by
Session.inputs()Attaches fixed-vocabulary retained input before the first successful solve. The binding allocates its aligned attachment storage.
- SessionInputs.apply()Applies an atomic delta to retained input and solves it. Additions win when the same fact is added and removed.
- SessionInputs.close()Releases this retained-input attachment and its aligned storage.
- SessionInputs.replace()Atomically replaces the complete retained dynamic input and solves it. The raw fact-capacity bound applies before deduplication.
- with inputs:Leaving the block closes this retained-input attachment.
with inputs.replace(inputs.base, [("owns", ["alice", "roadmap.pdf"])]) as result:
print("allowed:", result.contains_fact("allow", ["alice", "roadmap.pdf"]))allowed: True
Methods
Close the current result before replacing or applying input again. Each transaction uses the attachment’s current base.
SessionInputs.apply
SessionInputs.apply(
base: InputBase,
*,
added: Iterable[tuple[str, Sequence[object]]] = (),
removed: Iterable[tuple[str, Sequence[object]]] = ()
) -> SolveResultSolveResultReturns a leased SolveResult and commits a new base on success, even for an unchanged set. Failure preserves the committed facts and base. A non-InputBase base raises TypeError; a busy session or live result raises RuntimeError. Exceeding a raw batch capacity raises MaelysDatalogError with PAYLOAD_TOO_LARGE. Native transaction failures raise MaelysDatalogError.
with inputs.apply(inputs.base, added=[("owns", ["alice", "roadmap.pdf"])]) as result:
print("allowed:", result.contains_fact("allow", ["alice", "roadmap.pdf"]))allowed: True
SessionInputs.close
SessionInputs.close() -> NoneNoneReturns None. After successful native release, the binding clears the session’s attachment. Repeated closure is harmless.
inputs.close()
inputs.close()
print("inputs: closed")inputs: closed
SessionInputs.replace
SessionInputs.replace(
base: InputBase,
facts: Iterable[tuple[str, Sequence[object]]]
) -> SolveResultSolveResultReturns a leased SolveResult and commits a new base on success, even for an unchanged set. Failure preserves the committed facts and base. A non-InputBase base raises TypeError; a busy session or live result raises RuntimeError. Exceeding a raw batch capacity raises MaelysDatalogError with PAYLOAD_TOO_LARGE. Native transaction failures raise MaelysDatalogError.
base = inputs.base
with inputs.replace(base, [("owns", ["alice", "roadmap.pdf"])]) as result:
print("allowed:", result.contains_fact("allow", ["alice", "roadmap.pdf"]))
print("base changed:", inputs.base != base)allowed: True base changed: True
Protocols
with inputs:
Returns this open SessionInputs. Exiting delegates to close(), including on exceptional exit; exceptions are not suppressed.
with inputs:
with inputs.replace(inputs.base, [("owns", ["alice", "roadmap.pdf"])]) as result:
print("allowed:", result.contains_fact("allow", ["alice", "roadmap.pdf"]))allowed: True
Perform the same retained-input transaction with explicit cleanup.
try:
with inputs.replace(inputs.base, [("owns", ["alice", "roadmap.pdf"])]) as result:
print("allowed:", result.contains_fact("allow", ["alice", "roadmap.pdf"]))
finally:
inputs.close()allowed: True