Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

persian_jalali_calendar-1.0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

persian_jalali_calendar-1.0.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file persian_jalali_calendar-1.0.1.tar.gz.

File metadata

  • Download URL: persian_jalali_calendar-1.0.1.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

Hashes for persian_jalali_calendar-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b82cb82f6ba4bb8717e6303d73f39bcfa297c1804122148c34c3ccee1aee41f9
MD5 02f2f9ead10ac1d427f10a308e5b74b9
BLAKE2b-256 9c1416e6bf661a298e52beff4f377f0644619b7d832b743cd281949278e36fb1

See more details on using hashes here.

File details

Details for the file persian_jalali_calendar-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for persian_jalali_calendar-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a38fccc354d034b529ed2f64512ef988a59a798ca1ccd9a9f8fd05d78ba43a67
MD5 0216953d45d9066d2570534e243d9bd8
BLAKE2b-256 7dc47f991780629661d70cc6478682fbdf4a7805eb5aeb444bf0a4928333db06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page