Skip to main content

Bazi

面向中文用户的 Python 3.11+ 八字排盘库,提供四柱、五行、十神、纳音、关系与流运查询。 也可不创建命盘,直接查阅带出处与适用限度的知识条目。运行时只用标准库及随包数据,不联网。

安装

在已有的 Python、conda 或虚拟环境中安装:

python -m pip install bazi

需要新建环境时,可在文档站选择版本后查看“快速开始”。普通使用不需要测试或文档构建工具。

排第一张盘

下面使用虚构的出生信息,按东八区(UTC+8)公历钟填写;默认入口不自动换算时区。 可在 Python 交互环境中直接运行,也可保存为 UTF-8 脚本后运行;不要命名为 bazi.py,以免遮蔽安装包。

from bazi.bazi import 八字
from bazi.bazi_chart import 命盘

盘 = 命盘(八字.create('1990-05-17 10:30', '女'))
print('四柱', ' '.join(map(str, 盘.八字.四柱)))
print('日主', 盘.八字.日主)
print('年干十神', 盘.十神.年.天干)
四柱 庚午 辛巳 壬午 乙巳
日主 壬
年干十神 偏印

四柱依次为年、月、日、时。性别接受 女/男 或 female/male。 中文名与 Bazi、BaziChart 等原名可混用;类型从定义模块导入。 默认采用 DAY 精度和 23:00 换日柱。DAY 只按日期比较节气,出生小时仍用于时柱。 海外当地钟与真太阳时的输入方法,见文档站中对应版本的“配置与时间口径”。

继续使用

从文档站选择发布版阅读;当前源码的说明另见开发版文档。

“快速开始”介绍命盘文本、保存结果和可选的环境准备;其余指南包括“配置与时间口径”“公历、农历与节气”“关系与流运”、 “集成开发”和“查阅知识库”,知识目录与 API 参考供随时查阅。

只需公历与农历换算时,从 bazi.calendar.utils 导入 to_lunar、to_date,无需创建命盘。 往返示例及闰月编号见文档站中所选版本的“公历、农历与节气”指南。

不写 Python 时可使用安装后的 bazi 命令,先运行 bazi chart --help 查看排盘选项,更多用法见站点的“命令行”指南。

知识条目带有来源、前提与读法;已核出处不证明条文本身为真或适用于某张命盘。 关系与前提匹配返回结构事实,不预测现实事件。

开发

开发环境和完整检查见贡献指南,升级旧调用见发布与迁移。

贡献与许可

欢迎通过 issue 提交勘误和出处;PR 先开 issue 讨论。

作者自有材料采用 MIT License;第三方材料说明 另列历法数据、引文等权利范围, 不由作者的 MIT 授权重新许可。

Metadata

Release files for bazi 3.0.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 bazi 3.0.0
File Size Uploaded Provenance Actions
bazi-3.0.0.tar.gz 1.3 MB With provenance Details for bazi-3.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.7 MB

Release files / bazi-3.0.0.tar.gz

Download URL bazi-3.0.0.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
9e68755e7ee0846cc1bc40dca7afa14ccb2b9fa776f40bf7805072ee3142c087
BLAKE2b-256 checksum
How to use checksums
f451702896d774b36ea003413e59779e50820a59d8b9f3db384d4df6b34c02dd
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 19, 2026.

Transparency log

Release files / bazi-3.0.0-py3-none-any.whl

Download URL bazi-3.0.0-py3-none-any.whl
Size 382.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4f355428f7447064ca1d5b775e704fc706a4617ab2c9e0140104f0faf172f87
BLAKE2b-256 checksum
How to use checksums
4668bcdbc05772cd24aa0e9b0a806282567999730b26b350f679e4ee1d060317
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 19, 2026.

Transparency log

Security for bazi 3.0.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 bazi-3.0.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 19, 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.

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