Python
Rulesets
Usage guide and preserved examples for rulesets in Python.The Python rulesets reference continues the Python overview.
Classes
| Class | Kind | Role |
|---|---|---|
ProgramCounts | Immutable value class | Compiled counts for one selected policy. |
Ruleset | Resource-owning class | Owns one loaded policy set and creates input buffers and sessions. |
Methods
| Method | Purpose |
|---|---|
Ruleset.edb() | Create an input buffer. |
Ruleset.prepare() | Prepare a reusable session. |
Ruleset.solve() | Solve one request with a private session. |
Ruleset.close() | Release the loaded policy set |
Ruleset.program_counts() | Read compiled counts without preparing a session |
Properties and attributes
Read properties without parentheses. Their links lead to the canonical class card.
| 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. |
Usage and examples
Inspect what was loaded, use it to create inputs and sessions, then manage the policy set’s lifetime.
The detailed API 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.
ruleset.program_counts(0) returns ProgramCounts for the first enabled
policy. Its predicate count includes unused domain declarations; facts exclude
runtime EDB input; rules count normalized alternatives. Compare these with
engine.limits only as separate concepts, not as remaining capacity.
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.