Python
Edb
Edb class and public members in the unified Python API.| Used by | Ruleset.solve · Session.solve |
|---|
Class: Edb
- constructor
Edb(ruleset, *, fact_capacity=None, text_capacity=None)Creates an empty input buffer associated with an open Ruleset, using optional fixed storage capacities.
- returned by
Ruleset.edb()Creates an empty input buffer associated with this ruleset. Fill it with runtime facts before solving a request.
- Edb.add_fact()Appends one typed input fact, copying its text values into native storage. This call does not evaluate the policy.
- Edb.add_facts()Appends a batch of input facts atomically: if validation or storage fails, none of this batch is added. Earlier successful additions are retained.
- Edb.clear()Empties an input buffer that has not been successfully solved. Use reset() instead when starting a new request after a successful solve.
- Edb.close()Releases native input storage. Results already produced from this buffer remain valid.
- Edb.reset()Starts a new, empty input batch in the same buffer, including after a successful solve. It does not release the session’s previous result.
- len(edb)Counts stored input entries before deduplication through Python’s len(edb) protocol.
edb = ruleset.edb()
edb.add_fact("owns", ["alice", "roadmap.pdf"])
print("facts:", len(edb))facts: 1
Constructor: Edb()
Edb(
ruleset: Ruleset,
*,
fact_capacity: int | None = None,
text_capacity: int | None = None
) -> EdbEdbReturns an empty Edb. Invalid capacities raise Python exceptions; native creation failures raise MaelysDatalogError. Close it explicitly or through its Ruleset owner; it is not a context manager.
Methods
Each method has its own signature, arguments, return behavior and stable link.
Edb.add_fact
This copies one fact into the input buffer. It does not run rules or validate the complete policy vocabulary.
Edb.add_fact(
predicate: str,
terms: Sequence[object]
) -> NoneNoneReturns None after a successful copy. Python shape errors and native storage errors raise exceptions; earlier successful additions remain. Exact predicate vocabulary is checked at solve.
Edb.add_facts
Prefer a batch when several facts form one logical addition: either all are appended or none are.
Edb.add_facts(
facts: Iterable[tuple[str, Sequence[object]]]
) -> NoneNoneReturns None after appending the whole batch. Python validation, generator or native storage failure appends none of this batch. Earlier additions remain; generator side effects are not rolled back.
Edb.clear
Clear input after correcting an invalid unsolved request. This reuses the same native storage.
Edb.clear() -> NoneNoneReturns None after emptying an unsolved Edb. A successfully solved Edb is frozen: clear() then raises RuntimeError; use reset() to start a new request.
Edb.close
Once solving has produced a retained result, the input buffer is no longer required to query that result.
Edb.close() -> NoneNoneReturns None after releasing native input storage. Already returned results remain valid. Repeated closure is harmless; using the closed Edb raises RuntimeError.
Edb.reset
Reset explicitly ends the mutation freeze after successful solving and removes all input facts. It does not release an existing result.
Edb.reset() -> NoneNoneReturns None with an empty, mutable Edb. The session still rejects a second solve while its previous result remains open. Native failures raise MaelysDatalogError.
with session.solve(edb) as result:
print("alice / roadmap.pdf allowed:", result.contains_fact("allow", ["alice", "roadmap.pdf"]))
edb.reset()
edb.add_fact("owns", ["bob", "notes.txt"])
with session.solve(edb) as result:
print("bob / notes.txt allowed:", result.contains_fact("allow", ["bob", "notes.txt"]))alice / roadmap.pdf allowed: True bob / notes.txt allowed: True
Protocols
len(edb)
Python’s len(edb) protocol returns an int counting stored entries before deduplication; it is not an Edb.count() method.
len(edb) -> intintReturns an int counting stored entries before deduplication. A closed Edb or Ruleset raises RuntimeError; native failures raise MaelysDatalogError.