shamy-hijri
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
bisectover month start ordinals: O(log n), no I/O. - Both directions, one type.
HijriDateis 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-converterpackage.
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
ValueErrorinstead 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/omarelshamy25x/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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shamy_hijri-0.1.2.tar.gz | 7.5 kB | Without provenance | Details for shamy_hijri-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shamy_hijri-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for shamy_hijri-0.1.2-py3-none-any.whl |
Total release size: 14.8 kB
Release files / shamy_hijri-0.1.2.tar.gz
| Download URL | shamy_hijri-0.1.2.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53f5ff5ee519d87c7d2aa831e41745153d2428fa335c0bf41eaa765bc065559a
|
|
BLAKE2b-256 checksum How to use checksums |
f3e67240c9795ac2136e9e8414d87a53dc151cd678922be4ed4db5c5835a1c4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Release files / shamy_hijri-0.1.2-py3-none-any.whl
| Download URL | shamy_hijri-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b4d83941341714c17ee6e941a15f7d251c37db6615c8208ab827a534c2b48017
|
|
BLAKE2b-256 checksum How to use checksums |
be9f1af603ad1be4c30159180c42631025c8b068de7f29f53c3a6706c4feafcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Security for shamy-hijri 0.1.2
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.