Skip to main content

iirule

English | 中文

按优先级排列规则,返回第一条命中的结果。

安装

pip install iirule

用法

from iirule import first_match

rules = [
    {"name": "vip", "priority": 10, "when": {"tier": "gold"}, "then": "priority-queue"},
    {"name": "big", "priority": 5, "when": lambda r: r["amount"] > 1000, "then": "review"},
]

first_match({"tier": "gold"}, rules)              # 'priority-queue'
first_match({"tier": "basic", "amount": 5}, rules)  # None

说明

规则是 {name, priority, when, then},when 可以是 dict(逐字段相等)或可调用对象。优先级数值大的先判;同优先级按声明顺序。全部不命中时返回 n_default,不抛错——这是一条正常分支。

许可证

MIT


English

Order rules by priority and return the first match.

Install

pip install iirule

Usage

from iirule import first_match

rules = [
    {"name": "vip", "priority": 10, "when": {"tier": "gold"}, "then": "priority-queue"},
    {"name": "big", "priority": 5, "when": lambda r: r["amount"] > 1000, "then": "review"},
]

first_match({"tier": "gold"}, rules)              # 'priority-queue'
first_match({"tier": "basic", "amount": 5}, rules)  # None

Notes

A rule is {name, priority, when, then}; when is either a dict of equality checks or a callable. Higher priority is evaluated first, ties keep declaration order, and no match returns n_default — that is a normal outcome, not an error.

License

MIT

Metadata

Release files for iirule 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iirule 0.0.1
File Size Uploaded Provenance
iirule-0.0.1.tar.gz 3.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for iirule 0.0.1
File Interpreter ABI Platform
iirule-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.1 kB

Release files / iirule-0.0.1.tar.gz

Download URL iirule-0.0.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
248f640383a724db6927a5b699c7e28f7132e39d38201dd153bedca4c7689740
BLAKE2b-256 checksum
How to use checksums
eeb039f3586dd08d2e93db008dd06723adb7a3171afe0d31e04e0846a5044f68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / iirule-0.0.1-py3-none-any.whl

Download URL iirule-0.0.1-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5c4762121cd2d77289e6800802290eb1091b58c4442a47d971bf1a70d7a8c52
BLAKE2b-256 checksum
How to use checksums
1f374c94ddd62a07615272320aee79b657089ae752f4fc090357b7d7b744a5c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Security for iirule 0.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page