Skip to main content

Vietnamese lunar calendar conversion (Ho Ngoc Duc algorithm, per calrules) - Enterprise Ready

Project description

Âm Lịch Việt Nam

PyPI version CI License PyPI Downloads Monthly Downloads

Python library for converting between Gregorian (solar) calendar and Vietnamese lunar calendar.

Goal: lightweight - simple – accurate – easy to reuse - Enterprise Ready


FEATURES

  • No Dependencies: Ready for enterprise usage with strict typing support (PEP-561 compliant).
  • Support Can Chi: Heavenly Stems and Earthly Branches for year, month, day, hour.
  • Vietnamese Holidays: Common solar and lunar holidays included.
  • Convert Solar → Lunar: Accepts robust datetime.date inputs.
  • Convert Lunar → Solar: Accurate conversion using the Ho Ngoc Duc algorithm.
  • Supported Range: High precision conversion from years 1900 to 2100.
  • Leap month support: Handled automatically.
  • Timezone support: Default UTC+7 (Vietnam).
  • Processing Time Benchmark: High-performance conversions utilizing automated caching (clear_cache supported).

INSTALLATION

pip install lunar-vn

USAGE EXAMPLE

Basic Conversion

import datetime as dt
from lunar_vn import solar_to_lunar, lunar_to_solar, LunarDate

# Solar -> Lunar
date = dt.date(2026, 2, 17)
l = solar_to_lunar(date)   # Vietnamese Lunar New Year 2026
print(l)  # LunarDate(day=1, month=1, year=2026, leap=False)

# Lunar -> Solar
d = lunar_to_solar(LunarDate(1, 1, 2026))
print(d)  # 2026-02-17

Can Chi and Holidays

from lunar_vn import solar_to_lunar, can_chi, holidays
import datetime as dt

date = dt.date(2024, 2, 10)
lunar = solar_to_lunar(date)

# Get Year Can Chi
print(can_chi.get_year_can_chi(lunar.year))  # Giáp Thìn

# Get Day Can Chi (requires JDN)
from lunar_vn import jd_from_date
jdn = jd_from_date(date.day, date.month, date.year)
print(can_chi.get_day_can_chi(jdn))  # Giáp Thìn

# Check for Holiday
print(holidays.get_holiday(date))  # Tết Nguyên Đán

BENCHMARK

To run the benchmark script:

python scripts/benchmark.py

Expected: > 100,000 conversions per second.


COMPARISON WITH CHINESE LUNAR CALENDAR

See documentation.


ATTRIBUTION

The Vietnamese lunar calendar algorithm is described by Ho Ngoc Duc on the website: https://xemamlich.uhm.vn

This library is a Python re-implementation of the published algorithm.


LICENSE

MIT License

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

lunar_vn-1.2.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

lunar_vn-1.2.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file lunar_vn-1.2.0.tar.gz.

File metadata

  • Download URL: lunar_vn-1.2.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lunar_vn-1.2.0.tar.gz
Algorithm Hash digest
SHA256 57e87b9b16b5174bb96748a7a2a32462ed0fac4590f76e9d5ffdc2e69989dc32
MD5 e825a56709f53a03417afe71dd596ab7
BLAKE2b-256 0ec12e2995a9186f82a5cf69993b198ba87630948470a32d48852fd3fc983e7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lunar_vn-1.2.0.tar.gz:

Publisher: publish.yml on junkeythong/amlichvietnam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lunar_vn-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: lunar_vn-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lunar_vn-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2883fbdc40c47193c8a83b850893edd3f4381fb4dcdeeb68f0b4465edf8fbdaf
MD5 8888c69a57da87e463d4c6f3c0a1fdcb
BLAKE2b-256 bade4a04bb072482957feffa76fd032f18905c22f616432ac8c071a7f8908d3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lunar_vn-1.2.0-py3-none-any.whl:

Publisher: publish.yml on junkeythong/amlichvietnam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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