Python

Engine

Engine class and public members in the unified Python API.

Class: Engine

Python · classSince v0.10.0
Engine
Python owner created with Engine(); it reads engine.limits and tracks loaded Ruleset objects. Closing it closes native children but does not unregister domains. Use it on the creating thread.
Creation and access
  • constructor
    Engine()

    Creates the Python owner used to register domains and load rulesets.

Attributes
limitsLimitsproperty
Immutable snapshot of build capacities.
Methods
  • 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.
Protocols
  • with engine:Leaving the block closes this Engine, its rulesets and their native children.
Example
from maelys_datalog import Engine

with Engine() as engine:
    print("max_edb_facts:", engine.limits.max_edb_facts)
Outputv0.27.0, small profile
max_edb_facts: 1024

Constructor: Engine()

Python · constructorSince v0.10.0
Engine
Engine() -> Engine
Creates the Python owner used to register domains and load rulesets.
Return value
Engine

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

Example
from maelys_datalog import Engine

with Engine() as engine:
    print("max_edb_facts:", engine.limits.max_edb_facts)
Outputv0.27.0, small profile
max_edb_facts: 1024

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.

Python · methodSince v0.10.0
Engine.close
Engine.close() -> None
Closes this Python owner and its native children. It does not unregister domains from the global registry.
Return value
None

Returns None after cleanup. Repeated closure is harmless; using closed children raises RuntimeError.

Example
engine.close()

Engine.load_inline_ruleset

Use this path when the application already holds the Datalog source in memory. Register the domain first.

Python · methodSince v0.10.0
Engine.load_inline_ruleset
Engine.load_inline_ruleset(
domain: str,
policy_id: str,
source: str
) -> Ruleset
Loads one policy directly from Datalog source text against a registered domain, without reading a manifest.
Arguments
domainstr
Name of a domain that has already been registered.
policy_idstr
Identifier for the single policy loaded from this source string.
sourcestr
Datalog program text, not a filename; encoded as UTF-8 by the binding.
Return value
Ruleset

Returns a new Ruleset containing one policy, selected with policy_index=0. Invalid source or domain vocabulary raises MaelysDatalogError; loading does not solve runtime facts.

Example
ruleset = engine.load_inline_ruleset(
    "documents", "access",
    "allow(User, Doc) :- owns(User, Doc).",
)
print("policies:", ruleset.policy_count)

Engine.load_manifest

Use a manifest to package policy identities, source digests and public queries. Permissions are independent, explicit keyword arguments.

Python · methodSince v0.10.0
Engine.load_manifest
Engine.load_manifest(
path: str | os.PathLike[str],
*,
allow_test_only: bool = False,
allow_undeclared_policy_atoms: bool = False
) -> Ruleset
Loads a policy set from a manifest file, applying its source-hash checks, domain validation and public query permissions.
Arguments
pathstr | os.PathLike[str]
Path to a JSON manifest; its referenced policy files are verified by the native loader.
allow_test_onlybool
False by default. True explicitly permits enabled manifest policies marked test_only; they execute normally.
allow_undeclared_policy_atomsbool
False by default. True admits undeclared source strings into this loaded policy only; it does not change the registered domain.
Return value
Ruleset

Returns a new Ruleset containing the admitted policies. File, integrity or policy-validation failures raise MaelysDatalogError; no partially loaded set is returned.

Example
ruleset = engine.load_manifest("policies/manifest.json")
print("policies:", ruleset.policy_count)

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.

Python · methodSince v0.10.0
Engine.register_domain
Engine.register_domain(
name: str,
predicates: Sequence[Predicate],
*,
atoms: Sequence[str] = ()
) -> None
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.
Arguments
namestr
Process-wide domain name.
predicatesSequence[Predicate]
Nonempty sequence of Predicate declarations.
atomsSequence[str]
Optional policy-source string constants; runtime fact values do not belong here.
Return value
None

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

Example
from maelys_datalog import Predicate

engine.register_domain("documents", [
    Predicate.edb("owns", 2),
    Predicate.idb_query("allow", 2),
])

Protocols

with engine:

Python · protocolSince v0.10.0
with engine:
Leaving the block closes this Engine, its rulesets and their native children.
Behavior

Exiting the context delegates to close(), including on exceptional exit. Cleanup does not suppress the exception.

Example
from maelys_datalog import Engine

with Engine() as engine:
    print("max_edb_facts:", engine.limits.max_edb_facts)
Outputv0.27.0, small profile
max_edb_facts: 1024
Explicit form

Perform the same operations with explicit cleanup in a finally block.

from maelys_datalog import Engine

engine = Engine()
try:
    print("max_edb_facts:", engine.limits.max_edb_facts)
finally:
    engine.close()
Outputv0.27.0, small profile
max_edb_facts: 1024

Usage guides