Verdict — Python
The Python implementation of Verdict — a small, zero-dependency, async-native rule-evaluation engine.
Install
pip install verdict-rules
from verdict import Rule, FunctionRule, AndRule, OrRule, NotRule, RuleResult, RulesEngine
A first rule
FunctionRule wraps a plain async predicate — a reusable one can build
several named rules from the same code, each checking a different field
against its own floor:
import asyncio
from verdict import AndRule, FunctionRule, PredicateOutcome, RulesEngine
def at_least(name: str, field: str, floor: float) -> FunctionRule:
async def predicate(context: dict) -> PredicateOutcome:
value = context[field]
return PredicateOutcome(passed=value >= floor, detail=f"{value} vs {floor}")
return FunctionRule(name, predicate)
async def main() -> None:
eligible = AndRule("eligible", [
at_least("age_ok", "age", 18),
at_least("score_ok", "score", 60),
])
engine = RulesEngine([eligible])
verdict = await engine.run_named("eligible", {"age": 21, "score": 55})
print(verdict.passed) # False
failed = verdict.failing_leaves[0]
print(failed.rule_name, "|", failed.detail) # score_ok | 55 vs 60
asyncio.run(main())
A predicate reports a PredicateOutcome; the FunctionRule wrapping it
owns the name and builds the RuleResult. A composite's own detail is
empty — read failing_leaves for which leaf check refused, and key an
audit trail on that leaf's rule_name rather than the composite's.
If it has the shape, it is a rule
Rule is a Protocol, and Python's typing is structural — so any
object with the right attributes and an evaluate coroutine already
is a Rule. No inheritance, no registration:
class IsBusinessHours:
name = "is_business_hours"
group = None
async def evaluate(self, context: dict) -> RuleResult:
hour = context["hour"]
return RuleResult(rule_name="is_business_hours", passed=9 <= hour < 17)
await AndRule("open", [IsBusinessHours()]).evaluate({"hour": 21})
Most rules need no class at all either: FunctionRule wraps a plain
async function.
What it guarantees
- Sequential evaluation, never concurrent. Composites use a plain
forloop withawait, neverasyncio.gather. Short-circuiting only means something if later work never starts — and because the returned boolean is identical either way, getting this wrong is silent. - Vacuous truth has a polarity.
AndRule([])passes,OrRule([])fails. Deliberately asymmetric. - Emptiness is not absence. An empty composite folds to its
identity; an unknown rule name or group raises
KeyError. A group exists only because some rule declared it, so a lookup matching nothing can only be a mistake — and a misspelled group silently approving is the worst failure an eligibility check can have. Userule_names/group_namesto check membership, ortry_run_named/try_run_groupwhere your own domain has an answer for absence — both returnNoneinstead of raising. RuleResult.datais opaque — never read or written by this package; it carries whatever a predicate attached, unchanged.- A composite's children live in
sub_results, and are exactly what it evaluated: never padded to the full sub-rule list, never flattened into the parent.leaves/failing_leaveswalk that tree for you, anddecided_bynames which sub-results explain a result's own verdict. - Zero runtime dependencies.
Where to go next
| Doc | For |
|---|---|
docs/quickstart.md |
The quickstart — core concepts and a full worked example |
docs/architecture/ |
Why it's shaped this way, in depth — type structure, the execution model |
docs/extending/ |
Building on top of it from your own code, with no changes here |
docs/maintenance/ |
Changing this package itself |
docs/testing/ |
How the test suite is organized, and what a change needs to prove |
fixtures/ |
The two worked scenarios — each one's problem, design, and the cross-language data contract every port reproduces |
examples/ |
Full, tested mini-projects behind the fixtures — real code, real tests, real docs |
Metadata
Release files for verdict-rules 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| verdict_rules-0.4.1.tar.gz | 14.6 kB | With provenance | Details for verdict_rules-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| verdict_rules-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for verdict_rules-0.4.1-py3-none-any.whl |
Total release size: 30.5 kB
Release files / verdict_rules-0.4.1.tar.gz
| Download URL | verdict_rules-0.4.1.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46637775ca7f897f67f20f46592c82dac50a203ff5ea6233ec630032a42ebcfd
|
|
BLAKE2b-256 checksum How to use checksums |
6aec32b2b18ee3781e76ddd6a6eebb3a86e50d7adfb3c1154099f6a6e4ddc948
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / verdict_rules-0.4.1-py3-none-any.whl
| Download URL | verdict_rules-0.4.1-py3-none-any.whl |
|---|---|
| Size | 15.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc01d7fecba931324a12b0ab271b7b8ad379947d5d924129686cf4973bb485f5
|
|
BLAKE2b-256 checksum How to use checksums |
5970134b899041bd7e943b648e887fa876a000ad77495e9dc8cb00f6e670bcce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for verdict-rules 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for verdict_rules-0.4.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.