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 comparison test against
hijridate. The month table itself is derived from hijridate's (see Month data credit below), so that comparison guards against transcription errors, not against errors in the published calendar.
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 |
|
HijriDate.from_iso(value) |
HijriDate |
Parses "1445-09-01" (the isoformat() shape); raises ValueError otherwise. |
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 month table is derived from the MIT-licensed hijridate project (formerly hijri-converter), whose data is compiled from the officially published Umm al-Qura calendars. It is not an independent source, and the test suite's comparison with hijridate only checks that this library reads the table correctly.
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.
Contributing
Contributions are welcome, including small ones. You do not need to ask first.
- Pick an issue labelled
good first issueand comment that you are taking it. - Fork the repo and install it with
pip install -e ., then runpython -m pytest. - Make one focused change with a test, and open a pull request that says what it changes and why.
Details are in CONTRIBUTING.md. Arabic and English are both fine in issues and pull requests.
License
MIT. See LICENSE. Copyright (c) 2026 Omar Elshamy.
Month data credit: the month-length table is derived from hijridate by Mohammed Alshehri (MIT). See the Third-party notice in LICENSE.
Metadata
Release files for shamy-hijri 0.1.3
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.3.tar.gz | 9.0 kB | Without provenance | Details for shamy_hijri-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shamy_hijri-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for shamy_hijri-0.1.3-py3-none-any.whl |
Total release size: 17.0 kB
Release files / shamy_hijri-0.1.3.tar.gz
| Download URL | shamy_hijri-0.1.3.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9089ee281ccfe8bc2d7cba68df1803ed49894950ecc3a3c7bc4e4bbda4e8d75
|
|
BLAKE2b-256 checksum How to use checksums |
16abfee032543e3db468377ffd0f029e01c504c6f4bc85876cf4788e2a3223a7
|
| 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.3-py3-none-any.whl
| Download URL | shamy_hijri-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fdefddaa490aacaf5153768643a71839409076b59f922e8d5bb4ed23539bd2b
|
|
BLAKE2b-256 checksum How to use checksums |
407e10c97544e02c36bd0500f42e0ea859d74d4867db25fe5bae66a985b3fe8c
|
| 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.3
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.