Python

Rulesets

Rulesets in the unified Python binding.

The Python rulesets reference continues the Python overview.

Classes

ClassKindRole
RulesetResource-owning classOwns one loaded policy set and creates input buffers and sessions.

Methods

MethodPurpose
Ruleset.close()Release the loaded policy set

Properties and attributes

Read properties without parentheses. Their links lead to the class card defined on this page.

Property / protocolTypeMeaning
ruleset.policy_countintNumber of loaded policies; valid indices run from 0 to count minus 1.
ruleset.fingerprintstrIdentity of the whole loaded policy set, not a hash of request facts.

Detailed API reference

Every class and method indexed at the start of this page has its detailed card here. A class’s method list also links to related operations documented on other topic pages; those links do not duplicate their cards.

Value-class declarations and public creation signatures below come from the published binding inventory. Resource-owning classes list their methods as individual links with a short explanation. Each link opens the complete signature, arguments, return behavior and example; the creation signatures are a reference, not executable class source. The examples are fragments: engine, ruleset, edb, session and result refer to the live objects explained on this page and in the complete examples. Import the named classes before using them.

Ruleset reference

Python · class
Ruleset
Creation
Engine.load_inline_ruleset(
    domain: str,
    policy_id: str,
    source: str,
) -> Ruleset

Engine.load_manifest(
    path: str | os.PathLike[str],
    *,
    allow_test_only: bool = False,
    allow_undeclared_policy_atoms: bool = False,
) -> Ruleset
Loaded policy-set owner returned by Engine.load_inline_ruleset() or Engine.load_manifest(); do not construct it from native handles. Its read-only policy_count is an int and fingerprint is a str. Close it explicitly or with a context manager.
Methods
Example
print(ruleset.policy_count)
print(ruleset.fingerprint)

Creating a Ruleset

Obtain this object through one of these methods. Do not call its internal handle-taking constructor.

OperationPurpose
Engine.load_inline_ruleset()Load a policy from text
Engine.load_manifest()Load verified policy files

Ruleset attributes

Read these attributes without parentheses; they are not callable methods.

Attribute / protocolTypeMeaning
ruleset.policy_countintNumber of loaded policies; valid indices run from 0 to count minus 1.
ruleset.fingerprintstrIdentity of the whole loaded policy set, not a hash of request facts.

Release the loaded policy set

Close the ruleset when none of its sessions, results or input buffers are needed. Its children are closed first.

Python · method
Ruleset.close
Ruleset.close() -> None
Closes the loaded policy set and its dependent Python resources when the application has finished using them.
Arguments
Return value
None

Returns None after releasing the ruleset and remaining native children. Repeated closure is harmless; those children cannot subsequently be used.

Example
ruleset.close()

Usage and examples

Inspect what was loaded, use it to create inputs and sessions, then manage the policy set’s lifetime.

The reference above gives the exact declarations; the sections below explain their use.

Inspect the loaded policy set

A Ruleset is returned by either loader. It owns the validated policies; request facts and solved answers are separate objects.

Read ruleset.policy_count to learn how many policies are available. Session creation selects one by a zero-based policy_index; it does not merge their rules. An inline load returns a one-policy set, so its only valid index is 0. A manifest may load several policies.

Read ruleset.fingerprint for the identity of the loaded set. This identifies policy content, not the facts of a particular request.

CODE
print(ruleset.policy_count)
print(ruleset.fingerprint)

Use the loaded policy

Create its input buffer and supply facts in Runtime EDB. Then prepare a reusable session or perform an independent evaluation in Solving.

The loading examples and all their explanations, including the policy-filter example, are now grouped under Loading & manifests.

Lifetime

Keep the Ruleset open while using its input buffers, sessions and results. Closing it closes those children first. Use ruleset.close() explicitly or a Ruleset context manager; the cleanup reference describes the behavior.