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

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.2
File Size Uploaded Provenance
iirule-0.0.2.tar.gz 3.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 7.1 kB

Release files / iirule-0.0.2.tar.gz

Download URL iirule-0.0.2.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0a4b3e7cae45187cc12b9e44507d719c256e82e02fe28488cc51ff4caa37ba8a
BLAKE2b-256 checksum
How to use checksums
4d6a4582fdcfd5b5a338a6851a462515f7319bf08e9658689bb697272195f36c
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.2-py3-none-any.whl

Download URL iirule-0.0.2-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8109891254cce0dd012eaea3f7604dfee7a1f7e6ce8f7be85fee95c0220f9544
BLAKE2b-256 checksum
How to use checksums
fe13d8d555491bebc4f5d2a5d7754d91c05789f8f46dd73040838e2a4342ab85
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.2

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