Metadata-Version: 2.5
Name: iirule
Version: 0.0.2
Summary: 按优先级排列规则，返回第一条命中的结果。
Project-URL: Homepage, https://pypi.org/project/iirule/
Author-email: lqxnjk <lqxnjk@qq.com>
License: MIT
License-File: LICENSE
Keywords: dispatch,first-match,policy,priority,rules
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# iirule

[English](#english) | 中文

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

## 安装

```console
pip install iirule
```

## 用法

```python
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

---

<a id="english"></a>
## English

Order rules by priority and return the first match.

## Install

```console
pip install iirule
```

## Usage

```python
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
