Skip to main content

农历日历工具,支持干支、节气、斋日查询

Project description

lunarz - 农历日历工具包

lunarz 是一个功能强大的农历日历工具包,提供干支、节气、斋日等传统农历信息计算功能,专为需要处理中国传统历法功能的开发者设计。

功能特性

  • 干支系统:准确计算年、月、日的干支
  • 🌿 节气信息:提供当前节气状态及距离节气的天数
  • 🕉️ 斋日计算:识别十斋日及距离下一个斋日的天数和名称
  • 🌙 农历日期:精确显示农历年月日信息

安装方法

pip install lunarz

使用指南

Python API

from lunarz import LunarCalendar
import datetime

# 创建指定日期的农历日历
date = datetime.date(2025, 6, 15)  # 公历日期
lc = LunarCalendar(date)

# 获取农历日期
print(lc.get_lunar_day())  # 输出: 五月廿一

# 获取干支信息
print(lc.get_ganzhi())
# 输出: {'year': '乙巳', 'month': '壬午', 'day': '丙辰'}

# 获取节气信息
print(lc.get_solar_term_info())
# 输出: "芒种后9天,6天后夏至"

# 获取斋日信息
print(lc.get_fasting_info())
# 输出: "3天后廿三" 或 "今日斋日"

命令行工具

# 查询今日完整信息
lunarz

# 查询指定日期
lunarz --date 2025-12-01

# 查询特定字段
lunarz --date 2025-12-01 --field ganzhi  # 输出: 乙巳 丁亥 乙巳
lunarz --field fasting                    # 输出: 今日斋日 或 3天后初八
lunarz --field solar_term                # 输出: 小雪后5天,10天后大雪

功能详解

1. 干支系统 (get_ganzhi)

返回包含三个键的字典:

  • year: 年干支 (如 "甲辰")
  • month: 月干支 (如 "己巳")
  • day: 日干支 (如 "丙子")

2. 节气信息 (get_solar_term_info)

提供当前位置的节气信息,格式为:

  • 当前是节气日:直接返回节气名称
  • 在节气之间:返回上一个节气后X天,Y天后下一个节气
  • 靠近节气:返回 "X天后节气名" 或 "节气后X天"

3. 斋日信息 (get_fasting_info)

提供斋日信息,返回格式:

  • 今日斋日: 当天是十斋日
  • X天后Y: 距离本月下一个斋日X天(Y为农历日期名称)
  • X天后初一: 本月无剩余斋日,计算到下月初一

4. 农历日期 (get_lunar_day)

返回中文农历日期

  • 示例:十月廿三、冬月初一、腊月廿九

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lunarz-0.0.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lunarz-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file lunarz-0.0.1.tar.gz.

File metadata

  • Download URL: lunarz-0.0.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for lunarz-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bdddce596d792d45b14fde1625c0793b9d1b4f1eade06b876f734cc3b3fd01e9
MD5 a13b9f1658fe9ec185b43b6ef77d5fd7
BLAKE2b-256 55fb6e440c345cd21b704fca0dc43b3d98348880dbb9a1f152a4f5e9fc16dbc6

See more details on using hashes here.

File details

Details for the file lunarz-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: lunarz-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for lunarz-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5197b36b295dfe1fdb2b961dc1a4b9bfa84df43b8e66a780889f8b320ccbb43d
MD5 ea1c9800d4caffc39ebb7f85ba08be83
BLAKE2b-256 f83800c8b4707e68f0a7de4a781ed2dc1446206715696a629df68ef397a0e53c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page