Python
Rulesets
Rulesets in the unified Python binding.The Python rulesets reference continues the Python overview.
Classes
| Class | Kind | Role |
|---|---|---|
Ruleset | Resource-owning class | Owns one loaded policy set and creates input buffers and sessions. |
Methods
| Method | Purpose |
|---|---|
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 / protocol | Type | Meaning |
|---|---|---|
ruleset.policy_count | int | Number of loaded policies; valid indices run from 0 to count minus 1. |
ruleset.fingerprint | str | Identity 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
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- Ruleset.close()Release the loaded policy set
- Ruleset.edb()Create an input buffer
- Ruleset.prepare()Prepare a reusable session
- Ruleset.solve()Solve with a private session
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.
| Operation | Purpose |
|---|---|
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 / protocol | Type | Meaning |
|---|---|---|
ruleset.policy_count | int | Number of loaded policies; valid indices run from 0 to count minus 1. |
ruleset.fingerprint | str | Identity 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.
Ruleset.close() -> NoneNoneReturns None after releasing the ruleset and remaining native children. Repeated closure is harmless; those children cannot subsequently be used.
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.
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.