Skip to main content

shamy-hijri

PyPI version Python versions License: MIT tests

Umm al-Qura (Hijri) to Gregorian date conversion in pure Python. No dependencies, no data files, no network.

تحويل التاريخ الهجري (أم القرى) والميلادي في بايثون، بدون أي مكتبات خارجية.

>>> import datetime as dt
>>> from shamy_hijri import to_hijri, to_gregorian
>>> to_hijri(dt.date(2024, 3, 11))
HijriDate(year=1445, month=9, day=1)
>>> to_gregorian(1446, 1, 1)
datetime.date(2024, 7, 7)

Why this one

  • The whole calendar is built in. The Umm al-Qura month table for 1343-1500 AH (1924-08-01 to 2077-11-16) ships as one compact string, so conversion is a bisect over month start ordinals: O(log n), no I/O.
  • Both directions, one type. HijriDate is immutable, comparable and sortable, and knows its Gregorian twin.
  • Bilingual output. Month and weekday names in Arabic and English, with optional Arabic-Indic digits.
  • Tested across the entire range. Every single day from 1924 to 2077 round-trips, plus published reference dates and a cross-check against the independent hijri-converter package.

Install

pip install shamy-hijri

Python 3.8 or newer. Nothing else is required.

Quick start

import datetime as dt
from shamy_hijri import to_hijri, to_gregorian, HijriDate

h = to_hijri(dt.date(2024, 3, 11))
print(h)                                     # 1445-09-01
print(h.format())                            # 1 Ramadan 1445 AH
print(h.format("ar"))                        # 1 رمضان 1445 هـ
print(h.format("ar", arabic_digits=True))    # ١ رمضان ١٤٤٥ هـ
print(h.weekday_name_en, h.weekday_name_ar)  # Monday الاثنين

print(to_gregorian(1446, 1, 1))              # 2024-07-07
print(HijriDate(1445, 9, 1).to_gregorian())  # 2024-03-11
print(HijriDate.from_gregorian(dt.date(2024, 7, 7)))  # 1446-01-01

to_hijri() also accepts a datetime; the time part is ignored.

API

Function / attribute Returns Notes
to_hijri(date_or_datetime) HijriDate Raises ValueError outside the supported range.
to_gregorian(year, month, day) datetime.date Raises ValueError for invalid or unsupported dates.
HijriDate(year, month, day) HijriDate Validates on construction; frozen dataclass, so it compares and sorts.
HijriDate.from_gregorian(date) HijriDate Same as to_hijri.
HijriDate.to_gregorian() datetime.date
HijriDate.format(lang="en", arabic_digits=False) str "1 Ramadan 1445 AH" or "١ رمضان ١٤٤٥ هـ".
HijriDate.isoformat() / str(h) str "1445-09-01".
HijriDate.month_name_ar / month_name_en str
HijriDate.weekday_name_ar / weekday_name_en str
month_length(year, month) int 29 or 30 (28 or 31 only in pre-1356 AH historical data).
year_length(year) int 353-355 days.
is_valid(year, month, day) bool Never raises.
today() HijriDate Today in the local timezone.
SUPPORTED_RANGE (date, date) (1924-08-01, 2077-11-16).
MONTHS_AR, MONTHS_EN, WEEKDAYS_AR, WEEKDAYS_EN tuples Index 0 is Muharram / Monday.

Range and accuracy

  • Supported: 1 Muharram 1343 AH (1924-08-01) through the end of 1500 AH (2077-11-16). Anything outside raises ValueError instead of returning a quietly wrong date.
  • Month lengths follow the published Umm al-Qura calendar. Years before 1356 AH are historical and contain a few 28 or 31 day months; official Umm al-Qura starts at 1356 AH.
  • Umm al-Qura is an administrative calendar. Actual moon sighting in a given country can differ by a day, so treat this as the Saudi civil calendar, not as a religious ruling.
  • The table was cross-checked against the MIT-licensed hijri-converter project, and the test suite compares both implementations over decades of dates.

Development

git clone https://github.com/omarelshamyx-dotcom/shamy-hijri.git
cd shamy-hijri
pip install -e .
pip install pytest hijri-converter
pytest -q

The test suite walks every day in the supported range, so it takes a few seconds.

License

MIT. See LICENSE. Copyright (c) 2026 Omar Elshamy.

Month data credit: cross-checked against hijri-converter (MIT).

Metadata

Release files for shamy-hijri 0.1.1

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

Source distribution (sdist)

Source distribution for shamy-hijri 0.1.1
File Size Uploaded Provenance Actions
shamy_hijri-0.1.1.tar.gz 7.5 kB Without provenance Details for shamy_hijri-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shamy-hijri 0.1.1
File Interpreter ABI Platform Actions
shamy_hijri-0.1.1-py3-none-any.whl Python 3 none any Details for shamy_hijri-0.1.1-py3-none-any.whl

Total release size: 14.8 kB

Release files / shamy_hijri-0.1.1.tar.gz

Download URL shamy_hijri-0.1.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
aba7bc67b6c159bf34c7771a744273e737777d9843c5579d60b587d04592b254
BLAKE2b-256 checksum
How to use checksums
d3c109dbf0bf489a67bc6bb72604b1d1601fa724b48837547410c02e028bbeba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / shamy_hijri-0.1.1-py3-none-any.whl

Download URL shamy_hijri-0.1.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
247c4f7ef3a0d1ef5682841cbf3defee3497aef282c44ec762d52d3f92e6d770
BLAKE2b-256 checksum
How to use checksums
f83fdb87ae55304f21415dca48b97f2fb39f06f0e40da7d0c096540f86691a86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Security for shamy-hijri 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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