ziwei
Python 紫微斗数排盘与知识库。历法与时间由 celestial-calendar 提供;本仓记录紫微斗数的安星规则、 四化口径、流派变体与出处,并组织可复现的命盘结果。
本页介绍所在源码版本的功能与用法。GitHub上main分支的本页与在线文档随开发更新,
可能包含尚未发行的接口。版本变化见发行说明,公开发行记录以
PyPI和GitHub Releases为准。
目前提供出生记录、显式口径配置、民用时刻消歧、干支基础、celestial 历法适配、解析层 (公历/农历记录到计算输入)、命宫身宫与十二宫、五行局、36星安星、具名生年四化与大限, 以及完整命盘组合、十四主星七级亮度、流年十二宫、具名年度四化与禄羊陀、小限、童限与运限查询、只读按宫查询与宫位关系、文本十二宫格、静态SVG盘面和独立知识目录。 用法见出生输入、历法与时间、 解析层、命宫身宫与十二宫、 五行局、安星、 四化与大限、完整命盘与盘面 和知识查询。亮度的具名表、调用与来源限度见 亮度指南。年度查询、两种日期年界与本命叠读见 流年指南。小限、童限的查询与起限当岁选项见 运限指南。开发检查与协作约定见 参与开发,发布状态与失败处理见 发布指南。
当前不提供命盘JSON保存/恢复与旧盘重算接口,也不读取旧JSON命盘;历史兼容变化见 发行说明。
安装
先确认下方安装要求中的平台限制,再在已激活的独立虚拟环境中从正式PyPI安装当前发行版。
python -m pip install ziwei
python -m pip check
发行版接口与main文档可能不同,请先核对发行说明中的兼容变化。
需要使用开发中的接口时,可从源码安装。
从0.4.1起,也可用doushu(斗数)安装和导入:
python -m pip install doushu
from doushu.chart import create_chart
from doushu.knowledge import load_catalog
doushu精确依赖同版本ziwei,对应公开子模块中的函数、类型、枚举和数据是原对象。
下方示例的ziwei.*可换成doushu.*;原有路径继续可用,平台与Python要求相同。
请从对应子模块导入;具体转发范围见API参考。
安装要求
支持Python 3.11–3.14。运行时精确依赖celestial-calendar==1.1.1与tzdata==2026.6。
celestial-calendar 1.1.1在PyPI只提供下列原生wheel,没有源码分发包;ziwei自身的纯Python wheel不扩大这个范围:
| 平台 | 架构与最低系统要求 |
|---|---|
| macOS | arm64,macOS 15或更新 |
| Linux | x86_64,glibc 2.26或更新;aarch64,glibc 2.24或更新 |
| Windows | amd64 |
Intel macOS、Windows ARM64、较旧macOS和musl Linux不在上述制品覆盖范围内,不能依靠pip自动回退源码构建。 请使用独立虚拟环境;与不同精确版本的celestial-calendar或tzdata显式共装会冲突。 安装ziwei时,pip也可能将环境中已有的较新celestial-calendar或tzdata降到上述精确版本。 允许的依赖版本与复查条件见依赖兼容策略。
最小排盘
下面用合成的2024年农历正月初一子时女命演示最小排盘。 “口径”指闰月归属、子时换日和换年界线这三项计算选择;本例逐项指定,并选择一张具名生年四化表。 本例不是闰月,闰月归属不影响结果。农历记录只给时辰、没有钟点和时区,因此按农历正月初一换年,子时采用同日口径。 若要用立春换年,或区分早晚子时以执行晚子时归次日,须改用带钟点与时区的公历记录; 解析层有立春换年的完整示例,也列出其他出生资料的口径选择与输入要求。
>>> from ziwei.birth import Gender, LunarBirthRecord
>>> from ziwei.chart import create_chart
>>> from ziwei.config import ChartConfig, DayRollover, LeapMonthPolicy, YearBoundary
>>> from ziwei.ganzhi import Dizhi
>>> from ziwei.render import render_text
>>> from ziwei.sihua import SihuaVariant
>>> record = LunarBirthRecord(
... year=2024, month=1, day=1, is_leap_month=False, shichen=Dizhi.子, gender=Gender.女,
... )
>>> choices = ChartConfig(
... leap_month_policy=LeapMonthPolicy.上半月归本月下半月归下月,
... day_rollover=DayRollover.早晚子时同日,
... year_boundary=YearBoundary.农历正月初一,
... )
>>> chart = create_chart(record, choices, sihua_variant=SihuaVariant.排命盘口诀转录)
>>> text = render_text(chart)
>>> print(text.splitlines()[0])
火六局 · 大限逆行 · 虚岁首尾包含
这里仅显示盘面摘要。用print(text, end="")查看十二宫、36星、四化与大限;
同一输入的完整盘面及其计算与验证边界见指南。
未知时辰或性别可以保存在出生记录中,但完整命盘入口会拒绝,不代填。
功能范围
已知出生时刻与性别,排出可复现的本命盘:
- 保存出生原始记录,显式处理时区与可选的真太阳时,保留解析后的农历年月日时与所用历法算法。
- 闰月归属、子时换日、换年三个口径作为具名配置,不设静默默认。
- 月系星(辅弼、月马与刑姚)的归月未单独指定时跟随命身,也可单独选择;示例推荐半月法,其他两种仍可显式选用。
- 安命宫、身宫与十二宫宫干,定五行局,安紫微、天府两系十四主星。
- 安六吉、六煞、禄存、天马、红鸾天喜、刑姚、哭虚与固定法伤使;按所选具名四化表取生年四化。
- 起大限:顺逆由年干阴阳与性别定,首限起始虚岁由五行局数定。
- 命盘结果不可变,保留输入、口径、历法版本与派生结果;另提供文本与静态SVG盘面用于显示。
功能与改进进度见项目议题。
设计边界
也可独立查知识:无需出生资料或先排盘,就能查到星曜、宫位、四化等概念, 以及安星规则的流派变体、书中对星曜的解释与各自出处。来源核验状态、适用前提与展示资格分别记录。
通用概念用惯用英语,术数专有词用拼音;领域类型和结果另有中文读取入口,
如流年星曜(2024).陀罗,枚举也有中文成员。文档、issue 与 PR 使用中文。
后续方向
这些 milestone 记录方向,不设发布日期。每项技术在实现前须明确定义、出处与参考盘例。
许可证
MIT。
Metadata
Release files for ziwei 0.5.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 | Provenance | Actions |
|---|---|---|---|---|
| ziwei-0.5.0.tar.gz | 476.8 kB | With provenance | Details for ziwei-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ziwei-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for ziwei-0.5.0-py3-none-any.whl |
Total release size: 602.2 kB
Release files / ziwei-0.5.0.tar.gz
| Download URL | ziwei-0.5.0.tar.gz |
|---|---|
| Size | 476.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
facccb747b3c430eb623a6c081ca11e74ac689afb8dda28ee25ed3fd3704c02d
|
|
BLAKE2b-256 checksum How to use checksums |
b1e221b9bfea3dbe391d6e9c3de04f7e2a0373f3b5d59cc026bb38cd96b7fe2d
|
| 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 Nov 14, 2026.
Transparency logRelease files / ziwei-0.5.0-py3-none-any.whl
| Download URL | ziwei-0.5.0-py3-none-any.whl |
|---|---|
| Size | 125.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8cd2b3ac7d10e8b090f2f7a27fb8fca6520e96fdc74f0b14ac5ee0771586c645
|
|
BLAKE2b-256 checksum How to use checksums |
350a3834506e5fcfb631ef4669914188e858a6f9ea89c51c1bad91cbd1977b22
|
| 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 Nov 14, 2026.
Transparency logSecurity for ziwei 0.5.0
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 ziwei-0.5.0.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 Nov 14, 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.