Python

Edb

Edb class and public members in the unified Python API.

Class: Edb

Python · classSince v0.10.0
Edb
Native input buffer for one evaluation. Close it explicitly or through its Ruleset owner; Edb is not a context manager.
Creation and access
Methods
  • 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.
Protocols
  • len(edb)Counts stored input entries before deduplication through Python’s len(edb) protocol.
Example
edb = ruleset.edb()
edb.add_fact("owns", ["alice", "roadmap.pdf"])
print("facts:", len(edb))

Constructor: Edb()

Python · constructorSince v0.10.0
Edb
Edb(
ruleset: Ruleset,
*,
fact_capacity: int | None = None,
text_capacity: int | None = None
) -> Edb
Creates an empty input buffer associated with an open Ruleset, using optional fixed storage capacities.
Arguments
rulesetRuleset
Open Ruleset that owns this input buffer.
fact_capacityint | None
Maximum stored entries before deduplication. None uses engine.limits.max_edb_facts.
text_capacityint | None
Native text-storage budget in bytes. None uses engine.limits.input_edb_text_bytes.
Return value
Edb

Returns 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.

Example
from maelys_datalog import Edb

edb = Edb(ruleset)
edb.add_fact("owns", ["alice", "roadmap.pdf"])
print("facts:", len(edb))

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.

Python · methodSince v0.10.0
Edb.add_fact
Edb.add_fact(
predicate: str,
terms: Sequence[object]
) -> None
Appends one typed input fact, copying its text values into native storage. This call does not evaluate the policy.
Arguments
predicatestr
Nonempty predicate name declared by the selected policy; the operation also checks its arity and permissions.
termsSequence[object]
Concrete str, signed 64-bit int or bool values in predicate order. A string alone is not a term sequence.
Return value
None

Returns 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.

Example
edb.add_fact("owns", ["alice", "roadmap.pdf"])

Edb.add_facts

Prefer a batch when several facts form one logical addition: either all are appended or none are.

Python · methodSince v0.10.0
Edb.add_facts
Edb.add_facts(
facts: Iterable[tuple[str, Sequence[object]]]
) -> None
Appends a batch of input facts atomically: if validation or storage fails, none of this batch is added. Earlier successful additions are retained.
Arguments
factsIterable[tuple[str, Sequence[object]]]
Iterable of (predicate, terms) pairs. The complete addition is atomic; previously stored facts remain on failure.
Return value
None

Returns 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.

Example
edb.add_facts([
    ("user", ["alice"]),
    ("owns", ["alice", "roadmap.pdf"]),
    ("blocked", ["mallory"]),
])

Edb.clear

Clear input after correcting an invalid unsolved request. This reuses the same native storage.

Python · methodSince v0.10.0
Edb.clear
Edb.clear() -> None
Empties an input buffer that has not been successfully solved. Use reset() instead when starting a new request after a successful solve.
Return value
None

Returns None after emptying an unsolved Edb. A successfully solved Edb is frozen: clear() then raises RuntimeError; use reset() to start a new request.

Example
edb.clear()
edb.add_fact("owns", ["alice", "corrected.pdf"])

Edb.close

Once solving has produced a retained result, the input buffer is no longer required to query that result.

Python · methodSince v0.10.0
Edb.close
Edb.close() -> None
Releases native input storage. Results already produced from this buffer remain valid.
Return value
None

Returns None after releasing native input storage. Already returned results remain valid. Repeated closure is harmless; using the closed Edb raises RuntimeError.

Example
edb.close()

Edb.reset

Reset explicitly ends the mutation freeze after successful solving and removes all input facts. It does not release an existing result.

Python · methodSince v0.10.0
Edb.reset
Edb.reset() -> None
Starts a new, empty input batch in the same buffer, including after a successful solve. It does not release the session’s previous result.
Return value
None

Returns None with an empty, mutable Edb. The session still rejects a second solve while its previous result remains open. Native failures raise MaelysDatalogError.

Example
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.

Python · protocolSince v0.10.0
len(edb)
len(edb) -> int
Counts stored input entries before deduplication through Python’s len(edb) protocol.
Return value
int

Returns an int counting stored entries before deduplication. A closed Edb or Ruleset raises RuntimeError; native failures raise MaelysDatalogError.

Example
print("facts:", len(edb))

Usage guides