A simple and accurate Python library for the Persian Jalali calendar with no dependencies.
Project description
Persian Jalali Calendar
A simple, accurate, and lightweight Python library for the Persian Jalali calendar with no external dependencies.
This library allows for easy conversion between Jalali and Gregorian dates, provides date arithmetic, and offers helpful methods for formatting and date information, all through an intuitive API modeled after Python's datetime module.
Installation
Install the library from PyPI using pip:
pip install persian-jalali-calendar
Quick Start
Creating a JalaliDate Object
from jalali_calendar import JalaliDate
import datetime
# Create a Jalali date directly
d = JalaliDate(1404, 4, 13)
print(d)
# > 1404-04-13
# Get today's date
today = JalaliDate.today()
print(f"Today is: {today}")
# Create from a Gregorian datetime.date object
g_date = datetime.date(2025, 7, 4)
j_date = JalaliDate.from_gregorian(g_date)
print(f"Gregorian {g_date} is Jalali {j_date}")
# > Gregorian 2025-07-04 is Jalali 1404-04-13
Converting Back to Gregorian
from jalali_calendar import JalaliDate
j_date = JalaliDate(1404, 4, 13)
g_date = j_date.to_gregorian()
print(f"Jalali {j_date} is Gregorian {g_date}")
# > Jalali 1404-04-13 is Gregorian 2025-07-04
Accessing Date Properties
from jalali_calendar import JalaliDate
d = JalaliDate(1403, 1, 1) # Nowruz 1403
print(f"Year: {d.year}") # > 1403
print(f"Month: {d.month}") # > 1
print(f"Day: {d.day}") # > 1
print(f"Weekday: {d.weekday()}") # > 4 (Wednesday, since Saturday=0)
print(f"Weekday Name: {d.weekday_name()}") # > چهارشنبه
print(f"Month Name: {d.month_name()}") # > فروردین
print(f"Is Leap Year? {d.is_leap()}") # > True
Formatting with strftime
Use strftime for custom string formatting, including Persian names.
from jalali_calendar import JalaliDate
d = JalaliDate(1404, 4, 13)
formatted = d.strftime("%A، %d %B %Y")
print(formatted)
# > جمعه، ۱۳ تیر ۱۴۰۴
Date Arithmetic
You can perform standard date arithmetic using datetime.timedelta.
from jalali_calendar import JalaliDate
import datetime
d1 = JalaliDate(1404, 4, 13)
d2 = JalaliDate(1404, 4, 1)
# Subtract two Jalali dates to get a timedelta
time_diff = d1 - d2
print(f"Difference is {time_diff.days} days") # > 12
# Add or subtract a timedelta from a Jalali date
ten_days_later = d1 + datetime.timedelta(days=10)
print(f"10 days after {d1} is {ten_days_later}") # > 1404-04-23
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file persian_jalali_calendar-1.0.0.tar.gz.
File metadata
- Download URL: persian_jalali_calendar-1.0.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fe11df946dba9a79bcf9dfc386709a40358434ed801cf20f39124e78c16ccf2
|
|
| MD5 |
c2b2a3eecb3f46cf195f77e9240b39a6
|
|
| BLAKE2b-256 |
c37ea446f179273169a3314ae88512a955f02928fa88ad9f4084159502b2dfc6
|
File details
Details for the file persian_jalali_calendar-1.0.0-py3-none-any.whl.
File metadata
- Download URL: persian_jalali_calendar-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12ee27591305d9ed47a8e9ea152f64abc0e87d8d7902dc00394bf17c109522af
|
|
| MD5 |
dcc1aed59d467d88709a027cd14746eb
|
|
| BLAKE2b-256 |
6c5fac4d8880510de5153e82c56961cae6bfa83eff6e9119f693866272745429
|