qimen-rs Python 绑定
Python 3.10+;使用 PyO3 和 maturin,计算期间释放 GIL。calculate 返回 Python 字典,
calculate_json 提供与 Rust 完全一致的 JSON 接口。CPython 常规 GIL 构建使用 abi3 wheel。
快速开始
from qimen_rs import calculate
chart = calculate({
"year": 2024,
"month": 2,
"day": 10,
"hour": 12,
"utc_offset_minutes": 480,
"day_boundary": "zi_start",
})
print(chart["palaces"])
输入是指定 UTC 偏移下的民用时间;不会读取机器时区。默认 UTC+08:00,23:00 换日。
midnight 可显式选择 00:00 换日。无效日期、未知参数等由核心统一拒绝为 ValueError;
非字典输入或不能编码为 JSON 的 Python 对象抛出 TypeError。返回字段约定见仓库 schema 文档。
可选扩展
可选标注默认关闭,通过 extensions 参数选择明确的计算规则:
from qimen_rs import ExtensionOptions, calculate
options: ExtensionOptions = {
"hidden_stems": "duty_door_hour_stem_with_center_fallback",
"strength": "classical_stars_and_five_elements",
"growth_stages": "yang_forward_yin_reverse_fire_earth",
"punishments": "six_instrument_branches",
"tombs": "growth_stage_fire_earth",
"day_horse": "day_branch_three_harmony",
"door_pressure": "door_controls_palace",
}
chart = calculate({"year": 2026, "month": 9, "day": 18, "hour": 18}, extensions=options)
print(chart["extensions"]["day_horse"]["horse"])
只填写需要的项目即可;也可将 extensions 放入请求字典,与 JSON 接口完全一致。
同时使用两种位置会报 ValueError,避免静默覆盖。空配置不生成 extensions 输出字段。
每项结果记录实际 rule,寄干保留来源和盘层,日马与基础盘的时马分别返回。
tombs 也可选择 traditional_three_wonders;该规则只判断三奇,不适用的六仪结果为
None,与“未入墓”的 False 有区别。两种入墓约定不能混用。
公共类型在 qimen_rs.types 中,返回 schema 为 1.1。
完整规则与适用范围见 扩展约定。
开发与构建
在仓库根目录开发和测试:
python -m venv .venv
# 激活虚拟环境后
python -m pip install 'maturin>=1.9,<2'
maturin develop --manifest-path bindings/python/Cargo.toml --locked
python -m unittest discover -s bindings/python/tests -v
构建发行文件:
maturin build --release --locked \
--manifest-path bindings/python/Cargo.toml --out dist
maturin sdist --manifest-path bindings/python/Cargo.toml --out dist
尚未发布到 PyPI 的版本请从源码构建或安装 CI wheel。算法仅在 qimen-core 中实现;
Python 包负责类型转换和错误映射,不维护独立排盘规则。
Release files for qimen-rs 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| qimen_rs-0.1.0.tar.gz | 57.9 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| qimen_rs-0.1.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| qimen_rs-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| qimen_rs-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| qimen_rs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| qimen_rs-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 1.8 MB
Release files / qimen_rs-0.1.0.tar.gz
| Download URL | qimen_rs-0.1.0.tar.gz |
|---|---|
| Size | 57.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5133238edddf2b52f6d8539e48350629f016b96acab6d79824398792ba8bbeaa
|
|
BLAKE2b-256 checksum How to use checksums |
b20e233114969365049414f06035d662e4a95d8c54e7e700257a853c83a81be9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / qimen_rs-0.1.0-cp310-abi3-win_amd64.whl
| Download URL | qimen_rs-0.1.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 262.4 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
3e6b6df4c3f963f48d109c67b50e8f769a55b09dd2819b56483bea2513451f38
|
|
BLAKE2b-256 checksum How to use checksums |
9eaf42468a9d9f3280731a690da75471d88dedc843bdeef14d71c99910e4c0bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / qimen_rs-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | qimen_rs-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 390.3 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
09dce2885333ae91d24730bee61154df11b56715bbe21a45ab8ad8ecae700aab
|
|
BLAKE2b-256 checksum How to use checksums |
85bf5421b81eab58284cec60538d6535ec5c5610bc6f2229e7a81a974f25ea65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / qimen_rs-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | qimen_rs-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 385.0 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d73c806cf73b376b055d37e5db95d4b49b135753ead38d569519931fd685edb2
|
|
BLAKE2b-256 checksum How to use checksums |
9ebcfa2a537f3c927145a82615f3b5ad7cfa5c4f934d09582ae485d32909cbdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / qimen_rs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | qimen_rs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 355.2 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
56985b0401c3c5609d745174c34341a5406616b80d6a1ee0130f2bc170e80090
|
|
BLAKE2b-256 checksum How to use checksums |
3cdfebe35ca9cd1a44efb8b2910f8a2a66b0e5ec6d0ef46c575d9a01d62b38b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / qimen_rs-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | qimen_rs-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 362.1 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
686b0bf89414be7faa5ea6b2d38787ea530b28cb01e5bc8059e454bff69f79f6
|
|
BLAKE2b-256 checksum How to use checksums |
d6a8eb42bde3bdfa0fe9bfd84ab67b85c35b626d56e2bc5a67a66bab89080c32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|