Skip to main content

ziwei-chart

确定性紫微斗数排盘库:输入出生时刻(可带经纬度换算真太阳时),输出生辰十二宫 安星、大限索引与流年/流月视图的带版本号 JSON(ziwei_chart.v1)。 不含任何 AI 解读与星曜释义文本。

纯 Python;日历后端为 lunar-python。 真太阳时(天文中天法)是可选依赖,需 pip install ziwei-chart[solar]。

安装

pip install ziwei-chart          # 基础(民用时间排盘)
pip install ziwei-chart[solar]   # + 真太阳时(skyfield)

使用

from datetime import datetime
from zoneinfo import ZoneInfo

from ziwei_chart import BirthInput, CalendarRules, cast_chart

chart = cast_chart(BirthInput(
    datetime=datetime(2004, 4, 25, 9, 20, tzinfo=ZoneInfo("Asia/Shanghai")),
    gender="男",
    longitude=116.39,          # 可选;给了就换算真太阳时(需 [solar])
    latitude=39.90,
))
chart.to_dict()                                   # 本命盘(ziwei_chart.v1)
chart.horoscope(year=2026).to_dict()              # 大限 + 流年
chart.horoscope(year=2026, month=3, is_leap=False).to_dict()  # 流月

已有八字/农历串的应用可以走预算好的日历路径:

chart = cast_chart(BirthInput(
    gender="女",
    bazi="甲申戊辰甲戌己巳",
    lunar_date_str="2004-03-07 09:20:00",
))

BirthInput.datetime 必须带 IANA 时区(如 ZoneInfo("Asia/Shanghai"))。 固定偏移的 datetime.timezone(timedelta(hours=8)) 会被拒绝,因为真太阳时和 历史夏令时都要按时区名换算。

默认口径(流派差异参数化)

  • CalendarRules(day_rule="zi-early", time_rule="next-day"):子初换日、 夜子归次日(与现行 suanqiu 口径一致)。可选 day_rule="midnight" | "solar-midnight"、time_rule="midnight" | "prev-day"。
  • 农历日期本身按民用午夜切日,不跟随日柱换日口径。
  • 四化表可通过 rules= 注入自定义版本(如庚干派别分歧): cast_chart(inp, rules=RuleSet.default().with_sihua(my_table))。

真太阳时星历

[solar] extra 依赖 skyfield;DE421 星历(约 17 MB)按以下顺序解析: eph_path 参数 → 环境变量 ZIWEI_CHART_EPHEMERIS → 首次使用时自动下载到 用户缓存目录。

输出契约

顶层 schema 固定为 ziwei_chart.v1,JSON Schema 随包发布于 ziwei_chart/schema/ziwei_chart.v1.json。与旧实现的差异:

字段 处理
schema / input 新增;本命盘和大限/流年/流月视图都带
horoscope 新增,仅视图带:mode、year、month、is_leap、age,所在大限的 age_range / year_range,流月斗君元数据 monthly
Star.property、Palace.palace_implication 删除(释义文本由应用层补回)
decennial_age_index 等 range 字符串键 改为 [{start, end, palace_index, ...}] 列表

字段有破坏性变更时升级到 v2。

许可证

Apache-2.0,全文见 LICENSE。规则表(四化、五虎遁、纳音、主星安星表)整理自公开资料,属传统排盘规则;不含第三方代码。

Metadata

Release files for ziwei-chart 0.1.0

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

Source distribution (sdist)

Source distribution for ziwei-chart 0.1.0
File Size Uploaded Provenance Actions
ziwei_chart-0.1.0.tar.gz 32.8 kB With provenance Details for ziwei_chart-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ziwei-chart 0.1.0
File Interpreter ABI Platform Actions
ziwei_chart-0.1.0-py3-none-any.whl Python 3 none any Details for ziwei_chart-0.1.0-py3-none-any.whl

Total release size: 62.2 kB

Release files / ziwei_chart-0.1.0.tar.gz

Download URL ziwei_chart-0.1.0.tar.gz
Size 32.8 kB
Tags Source
SHA-256 checksum
How to use checksums
36ba89190ec77d2788a85c97075246847546dc7f45f3f42c942dc78c4d3ed46a
BLAKE2b-256 checksum
How to use checksums
003d2590462b7e9648796695401868c4a706da1ca8008d40ebd013daf2fd112c
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 Oct 28, 2026.

Transparency log

Release files / ziwei_chart-0.1.0-py3-none-any.whl

Download URL ziwei_chart-0.1.0-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb5ba9eadbdc8ac4c8af3a30b6589ad4b3445cbae516ee03a0087f01e2320851
BLAKE2b-256 checksum
How to use checksums
265a0340df407bc4898b47b4ff94369d1ef5d2e9229a6cf8722f8c96d2c8bffe
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 Oct 28, 2026.

Transparency log

Security for ziwei-chart 0.1.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.

Select from 2 files

Attestation for ziwei_chart-0.1.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 Oct 28, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full 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