Python
Engine
Engine class and public members in the unified Python API.Class: Engine
- constructor
Engine()Creates the Python owner used to register domains and load rulesets.
- Engine.close()Closes this Python owner and its native children. It does not unregister domains from the global registry.
- Engine.load_inline_ruleset()Loads one policy directly from Datalog source text against a registered domain, without reading a manifest.
- Engine.load_manifest()Loads a policy set from a manifest file, applying its source-hash checks, domain validation and public query permissions.
- Engine.register_domain()Registers the domain’s predicate vocabulary and optional policy-source atoms before policies are loaded against it. It does not load or evaluate a policy.
- with engine:Leaving the block closes this Engine, its rulesets and their native children.
Constructor: Engine()
Engine() -> EngineEngineReturns an Engine with its build-capacity snapshot. Domain registration, policy loading and evaluation happen through its methods. Close it explicitly or use it as a context manager.
Methods
Each method has its own signature, arguments, return behavior and stable link.
Engine.close
Release its loaded rulesets and their native children. This does not unregister the process-wide domain vocabulary.
Engine.close() -> NoneNoneReturns None after cleanup. Repeated closure is harmless; using closed children raises RuntimeError.
Engine.load_inline_ruleset
Use this path when the application already holds the Datalog source in memory. Register the domain first.
Engine.load_inline_ruleset(
domain: str,
policy_id: str,
source: str
) -> RulesetRulesetReturns a new Ruleset containing one policy, selected with policy_index=0. Invalid source or domain vocabulary raises MaelysDatalogError; loading does not solve runtime facts.
ruleset = engine.load_inline_ruleset(
"documents", "access",
"allow(User, Doc) :- owns(User, Doc).",
)
print("policies:", ruleset.policy_count)policies: 1
Engine.load_manifest
Use a manifest to package policy identities, source digests and public queries. Permissions are independent, explicit keyword arguments.
Engine.load_manifest(
path: str | os.PathLike[str],
*,
allow_test_only: bool = False,
allow_undeclared_policy_atoms: bool = False
) -> RulesetRulesetReturns a new Ruleset containing the admitted policies. File, integrity or policy-validation failures raise MaelysDatalogError; no partially loaded set is returned.
ruleset = engine.load_manifest("policies/manifest.json")
print("policies:", ruleset.policy_count)policies: 1
Engine.register_domain
Register the complete vocabulary before loading a policy. This instance method validates the declaration and sends it to the native process-wide registry.
Engine.register_domain(
name: str,
predicates: Sequence[Predicate],
*,
atoms: Sequence[str] = ()
) -> NoneNoneReturns None after a successful registration; it returns no domain handle. Invalid Python arguments raise TypeError or ValueError. A native registration failure raises MaelysDatalogError, so do not load a policy for that domain.
Protocols
with engine:
Exiting the context delegates to close(), including on exceptional exit. Cleanup does not suppress the exception.