Skip to content

reed1898/bazi-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏮 八字排盘工具 (BaZi Chart Calculator)

专业级八字排盘与分析工具。节气精确计算、真太阳时修正、完整十神/五行/大运/刑冲合害分析。

功能

  • 四柱排盘 — 年柱、月柱、日柱、时柱,天干地支完整计算
  • 节气精确计算 — 基于天文算法(ephem),月柱严格按节气划分
  • 真太阳时修正 — 根据出生地经度 + 均时差自动修正,默认开启
  • 藏干 — 每个地支的本气、中气、余气
  • 十神 — 以日干为我,推算所有天干的十神关系
  • 五行力量分析 — 天干地支含藏干的五行分布 + 日主强弱判断
  • 大运排列 — 根据性别和年干阴阳决定顺逆,精确计算起运年龄
  • 刑冲合害 — 六合、三合、六冲、三刑、六害、天干五合、天干冲
  • 流年分析 — 指定年份的干支及与命盘的关系
  • 50+ 中国城市 — 内置经纬度表,支持城市名直接查询

快速开始

git clone https://github.com/reed1898/bazi-tool.git
cd bazi-tool
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# 排盘
python scripts/bazi.py --date 1990-08-18 --time 06:00 --city 上海 --gender male

使用示例

# 基础排盘(人类可读格式)
python scripts/bazi.py --date 1983-05-15 --time 14:30 --city 上海 --gender male

# JSON 输出
python scripts/bazi.py --date 1983-05-15 --time 14:30 --city 上海 --gender male --format json

# 指定经纬度
python scripts/bazi.py --date 1983-05-15 --time 14:30 --lat 31.23 --lon 121.47 --gender male

# 关闭真太阳时修正
python scripts/bazi.py --date 1983-05-15 --time 14:30 --city 上海 --gender male --no-solar-correction

# 查看流年
python scripts/bazi.py --date 1983-05-15 --time 14:30 --city 上海 --gender male --year 2026

输出示例

【命盘】男 · 1983-05-15 14:30 上海
(真太阳时:14:39)

     年柱    月柱    日柱    时柱
天干   癸      丁      癸      己
地支   亥      巳      卯      未
藏干  壬甲     丙庚戊    乙      己丁乙
十神  比肩     偏财     (日主)   偏官

日主:癸水(阴) | 偏弱

五行:木18%  火24%  土21%  金4%  水34%
关系:年支亥·日支卯·时支未 → 亥卯未合木局  |  年支亥·月支巳 → 巳亥冲

大运(3岁起运,逆排):
  3-12  丙辰  |  13-22  乙卯  |  23-32  甲寅
  33-42  癸丑  |  43-52  壬子  |  53-62  辛亥

项目结构

bazi-tool/
├── scripts/
│   └── bazi.py            # 主入口 CLI
├── lib/
│   ├── pillars.py         # 四柱计算
│   ├── solar_terms.py     # 节气计算(天文算法)
│   ├── true_solar_time.py # 真太阳时修正
│   ├── hidden_stems.py    # 藏干
│   ├── ten_gods.py        # 十神
│   ├── five_elements.py   # 五行分析
│   ├── major_luck.py      # 大运
│   ├── relationships.py   # 刑冲合害
│   ├── cities.py          # 城市经纬度查询
│   └── constants.py       # 常量定义
├── data/
│   └── cities.json        # 中国城市经纬度表
├── tests/
│   ├── test_pillars.py    # 单元测试
│   └── fixtures/
│       └── known_charts.json
├── requirements.txt
└── README.md

技术说明

  • 节气计算:使用 ephem 天文库计算太阳黄经,精确到分钟级别
  • 真太阳时:北京时间 + (经度差 × 4分钟) + 均时差
  • 日主强弱:综合得令、得地、得生、得助四个维度判断
  • 藏干权重:本气 60%、中气 30%、余气 10%

测试

python -m pytest tests/ -v

License

MIT

About

🏮 专业八字排盘工具 - BaZi chart calculator with precise solar terms, true solar time correction, and complete analysis

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages