calbridgepy
calbridgepy is a high-performance Python package for fast and accurate conversion between Jalali (Shamsi), Gregorian, and Hijri calendars.
It efficiently handles large datasets using a pre-built mapping table covering Gregorian years 1700–2200, with exact aligned mappings for Jalali and Hijri dates.
The package provides five main functions:
normalize_date(): Normalize date strings to"YYYY-MM-DD"format, preserving optional time components.convert_date(): Convert dates between any two calendars (Jalali, Gregorian, Hijri) using vectorized joins/lookups.day2day(): Generate a sequence of dates between two endpoints in the chosen calendar, including optional start and end times.date_diff(): Compute the difference in days between two dates in any supported calendar using fast index lookups.date_time_diff(): Compute the difference between two date-time values in any calendar. Returns both raw seconds and a formatted"X days HH:MM:SS"string.
Performance & Backend Flexibility
The package is designed with zero heavy runtime overhead:
- Uses polars when available for lightning-fast vectorized joins and parallel processing.
- Automatically falls back to pandas if Polars is not installed.
- Requires no heavy binary serialization dependencies (such as
pyarrow).
Installation
From PyPI (Recommended)
Install the standard version via pip:
pip install calbridgepy
To install with optional Polars acceleration support:
pip install "calbridgepy[polars]"
You can also install directly from the GitHub repository:
pip install https://github.com/bistoonh/calbridgepy/archive/refs/heads/main.zip
To install with optional Polars acceleration support:
pip install "calbridgepy[polars] @ https://github.com/bistoonh/calbridgepy/archive/refs/heads/main.zip"
Examples
from calbridgepy import (
normalize_date,
convert_date,
day2day,
date_diff,
date_time_diff,
)
# 1. Normalize dates (Jalali)
normalize_date(["14020101", "1402-01", "1402-01-01 14:30:00"])
# ['1402-01-01', '1402-01-01', '1402-01-01 14:30:00']
# Single string input returns a string
normalize_date("14020101")
# '1402-01-01'
# 2. Convert Jalali to Gregorian
convert_date("1402-01-01", from_cal="j", to_cal="g")
# '2023-03-21'
# Convert Gregorian to Hijri
convert_date("2023-03-21", from_cal="g", to_cal="h")
# '1444-08-29'
# Vectorized conversions
dates = ["1402-01-01", "1402-05-15", "1402-12-29"]
convert_date(dates, from_cal="j", to_cal="g")
# ['2023-03-21', '2023-08-06', '2024-03-18']
# 3. Generate a sequence of Hijri dates
day2day("1447-09-01", "1447-09-03", calendar="h")
# ['1447-09-01', '1447-09-02', '1447-09-03']
# Include start and end times (only attached at endpoints)
day2day("2025-03-21 08:00:00", "2025-03-23 18:00:00", calendar="g")
# ['2025-03-21 08:00:00', '2025-03-22', '2025-03-23 18:00:00']
# 4. Compute day differences (Gregorian)
date_diff("2025-03-21", "2025-03-25", calendar="g")
# 4
# Vectorized day differences (Hijri)
date_diff(
["1447-09-01", "1447-09-05"],
["1447-09-03", "1447-09-10"],
calendar="h",
)
# [2, 5]
# 5. Compute date-time differences (seconds + formatted)
res = date_time_diff("1402-01-01 12:00:00", "1402-01-02 14:30:00", calendar="j")
print(res["seconds"])
# 95400
print(res["formatted"])
# '1 days 02:30:00'
Data
The package includes a pre-indexed calendar mapping covering 1700 to 2200 CE:
from calbridgepy.normalize_date import _get_calendar_map
df = _get_calendar_map()
# Returns a Polars DataFrame (if installed) or Pandas DataFrame
This table maps Jalali, Gregorian, and Hijri dates across multiple centuries, allowing instant O(1) lookups and fast vectorized joins without recalculating leap years or month structures on every call.
Calendar Identifier Aliases
All functions accept both full names and short aliases:
- Jalali / Shamsi:
"j","jalali" - Gregorian:
"g","gregorian" - Hijri:
"h","hijri"
License
MIT License
Metadata
Release files for calbridgepy 0.2.0
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 |
|---|---|---|---|---|
| calbridgepy-0.2.0.tar.gz | 1.3 MB | Without provenance | Details for calbridgepy-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| calbridgepy-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for calbridgepy-0.2.0-py3-none-any.whl |
Total release size: 2.5 MB
Release files / calbridgepy-0.2.0.tar.gz
| Download URL | calbridgepy-0.2.0.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c19f2fbf892c8d11cfcf6e9e771643db020817c395838995224558de95f8d653
|
|
BLAKE2b-256 checksum How to use checksums |
fa5ed46899160caf505ba4ec4b5e9b8f214de97bf1b20cb738a74c2f9f6ed82e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / calbridgepy-0.2.0-py3-none-any.whl
| Download URL | calbridgepy-0.2.0-py3-none-any.whl |
|---|---|
| Size | 1.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80bbc9d7ed6bf14177919ac44cd8c1840a87b1e54792789e3d4272bfc6d73720
|
|
BLAKE2b-256 checksum How to use checksums |
8d0e0609d02739cc2a4b03068005d15be5c692849c9c82eb7cca640aac742a01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Security for calbridgepy 0.2.0
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.