Metadata-Version: 2.4
Name: shamy-hijri
Version: 0.1.1
Summary: Umm al-Qura (Hijri) date conversion, dependency-free. By Omar Elshamy.
Author: Omar Elshamy
License: MIT
Project-URL: Homepage, https://github.com/omarelshamyx-dotcom/shamy-hijri
Project-URL: Source, https://github.com/omarelshamyx-dotcom/shamy-hijri
Project-URL: PyPI, https://pypi.org/project/shamy-hijri/
Keywords: hijri,umm al-qura,islamic calendar,arabic,dates
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Natural Language :: Arabic
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# shamy-hijri

[![PyPI version](https://img.shields.io/pypi/v/shamy-hijri.svg)](https://pypi.org/project/shamy-hijri/)
[![Python versions](https://img.shields.io/pypi/pyversions/shamy-hijri.svg)](https://pypi.org/project/shamy-hijri/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![tests](https://github.com/omarelshamyx-dotcom/shamy-hijri/actions/workflows/tests.yml/badge.svg)](https://github.com/omarelshamyx-dotcom/shamy-hijri/actions/workflows/tests.yml)

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

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

```python
>>> 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

```bash
pip install shamy-hijri
```

Python 3.8 or newer. Nothing else is required.

## Quick start

```python
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](https://github.com/dralshehri/hijri-converter) project, and the test suite compares both implementations over decades of dates.

## Development

```bash
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](LICENSE). Copyright (c) 2026 Omar Elshamy.

Month data credit: cross-checked against [hijri-converter](https://github.com/dralshehri/hijri-converter) (MIT).
