Welcome to pyluach’s documentation!
pyluach
Pyluach is a Python package for dealing with Hebrew (Jewish) calendar dates.
Features
Conversion between Hebrew and Gregorian dates
Finding the difference between two dates
Finding a date at a given duration from the given date
Rich comparisons between dates
Finding the weekday of a given date
Finding the weekly Parsha reading of a given date
Getting the holiday occuring on a given date
Generating html and text Hebrew calendars
Installation
Use pip install pyluach
.
Documentation
Documentation for pyluach can be found at https://readthedocs.org/projects/pyluach/.
Examples
>>> from pyluach import dates, hebrewcal, parshios
>>> today = dates.HebrewDate.today()
>>> lastweek_gregorian = (today - 7).to_greg()
>>> lastweek_gregorian < today
True
>>> today - lastweek_gregorian
7
>>> greg = dates.GregorianDate(1986, 3, 21)
>>> heb = dates.HebrewDate(5746, 13, 10)
>>> greg == heb
True
>>> purim = dates.HebrewDate(5781, 12, 14)
>>> purim.hebrew_day()
'י״ד'
>>> purim.hebrew_date_string()
'י״ד אדר תשפ״א'
>>> purim.hebrew_date_string(True)
'י״ד אדר ה׳תשפ״א'
>>> rosh_hashana = dates.HebrewDate(5782, 7, 1)
>>> rosh_hashana.holiday()
'Rosh Hashana'
>>> rosh_hashana.holiday(hebrew=True)
'ראש השנה'
>>> (rosh_hashana + 3).holiday()
None
>>> month = hebrewcal.Month(5781, 10)
>>> month.month_name()
'Teves'
>>> month.month_name(True)
'טבת'
>>> month + 3
Month(5781, 1)
>>> for month in hebrewcal.Year(5774).itermonths():
... print(month.month_name())
Tishrei Cheshvan ...
>>> date = dates.GregorianDate(2010, 10, 6)
>>> parshios.getparsha(date)
[0]
>>> parshios.getparsha_string(date, israel=True)
'Beraishis'
>>> parshios.getparsha_string(date, hebrew=True)
'בראשית'
>>> new_date = dates.GregorianDate(2021, 3, 10)
>>> parshios.getparsha_string(new_date)
'Vayakhel, Pekudei'
>>> parshios.getparsha_string(new_date, hebrew=True)
'ויקהל, פקודי'
Contact
For questions and comments please raise an issue in github or contact me at simlist@gmail.com.
License
Pyluach is licensed under the MIT license.
dates module
The dates module implements classes for representing and manipulating several date types.
Contents
Note
All instances of the classes in this module should be treated as read only. No attributes should be changed once they’re created.
- class pyluach.dates.Rounding(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
Enumerator to provide options for rounding Hebrew dates.
This provides constants to use as arguments for functions. It should not be instantiated.
- PREVIOUS_DAY
If the day is the 30th and the month only has 29 days, round to the 29th of the month.
- NEXT_DAY
If the day is the 30th and the month only has 29 days, round to the 1st of the next month.
- EXCEPTION
If the day is the 30th and the month only has 29 days, raise a ValueError.
- class pyluach.dates.BaseDate[source]
Bases:
ABC
BaseDate is a base class for all date types.
It provides the following arithmetic and comparison operators common to all child date types.
Operation
Result
d2 = date1 + int
New date
int
days after date1d2 = date1 - int
New date
int
days before date1int = date1 - date2
Positive integer equal to the duration from date1 to date2
date1 > date2
True if date1 occurs later than date2
date1 < date2
True if date1 occurs earlier than date2
date1 == date2
True if date1 occurs on the same day as date2
date1 != date2
True if
date1 == date2
is FalseAny subclass of
BaseDate
can be compared to and diffed with any other subclass date.- abstract property jd
Return julian day number.
- Returns:
The Julian day number at midnight (as
n.5
).- Return type:
- weekday()[source]
Return day of week as an integer.
- Returns:
An integer representing the day of the week with Sunday as 1 through Saturday as 7.
- Return type:
- isoweekday()[source]
Return the day of the week corresponding to the iso standard.
- Returns:
An integer representing the day of the week where Monday is 1 and and Sunday is 7.
- Return type:
- shabbos()[source]
Return the Shabbos on or following the date.
- Returns:
self if the date is Shabbos or else the following Shabbos as the same date type as called from.
- Return type:
Examples
>>> heb_date = HebrewDate(5781, 3, 29) >>> greg_date = heb_date.to_greg() >>> heb_date.shabbos() HebrewDate(5781, 4, 2) >>> greg_date.shabbos() GregorianDate(2021, 6, 12)
- festival(israel=False, hebrew=False, include_working_days=True, prefix_day=False)[source]
Return name of Jewish festival of date.
This method will return all major and minor religous Jewish holidays not including fast days.
- Parameters:
israel (bool, optional) –
True
if you want the holidays according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the festival name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.include_working_days (bool, optional) –
True
to include festival days on which melacha (work) is allowed; ie. Pesach Sheni, Chol Hamoed, etc. Default isTrue
.prefix_day (bool, optional) –
True
to prefix multi day festivals with the day of the festival. Default isFalse
.
- Returns:
The name of the festival or
None
if the given date is not a Jewish festival.- Return type:
str or None
Examples
>>> pesach = HebrewDate(2023, 1, 15) >>> pesach.festival(prefix_day=True) '1 Pesach' >>> pesach.festival(hebrew=True, prefix_day=True) 'א׳ פסח' >>> shavuos = HebrewDate(5783, 3, 6) >>> shavuos.festival(israel=True, prefix_day=True) 'Shavuos'
- holiday(israel=False, hebrew=False, prefix_day=False)[source]
Return name of Jewish holiday of the date.
The holidays include the major and minor religious Jewish holidays including fast days.
- Parameters:
israel (bool, optional) –
True
if you want the holidays according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the holiday name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.prefix_day (bool, optional) –
True
to prefix multi day holidays with the day of the holiday. Default isFalse
.
- Returns:
The name of the holiday or
None
if the given date is not a Jewish holiday.- Return type:
str or None
Examples
>>> pesach = HebrewDate(2023, 1, 15) >>> pesach.holiday(prefix_day=True) '1 Pesach' >>> pesach.holiday(hebrew=True, prefix_day=True) 'א׳ פסח' >>> taanis_esther = HebrewDate(5783, 12, 13) >>> taanis_esther.holiday(prefix_day=True) 'Taanis Esther'
- class pyluach.dates.CalendarDateMixin(year, month, day, jd=None)[source]
Bases:
object
CalendarDateMixin is a mixin for Hebrew and Gregorian dates.
- tuple()[source]
Return date as tuple.
- Returns:
A tuple of ints in the form
(year, month, day)
.- Return type:
tuple of ints
- dict()[source]
Return the date as a dictionary.
- Returns:
A dictionary in the form
{'year': int, 'month': int, 'day': int}
.- Return type:
- class pyluach.dates.JulianDay(day)[source]
Bases:
BaseDate
A JulianDay object represents a Julian Day at midnight.
- Parameters:
day (float or int) – The julian day. Note that Julian days start at noon so day number 10 is represented as 9.5 which is day 10 at midnight.
- static from_pydate(pydate)[source]
Return a JulianDay from a python date object.
- Parameters:
pydate (datetime.date) – A python standard library
datetime.date
instance- Return type:
- static today()[source]
Return instance of current Julian day from timestamp.
Extends the built-in
datetime.date.today()
.- Returns:
A JulianDay instance representing the current Julian day from the timestamp.
- Return type:
Warning
Julian Days change at noon, but pyluach treats them as if they change at midnight, so at midnight this method will return
JulianDay(n.5)
until the following midnight when it will returnJulianDay(n.5 + 1)
.
- to_greg()[source]
Convert JulianDay to a Gregorian Date.
- Returns:
The equivalent Gregorian date instance.
- Return type:
Notes
This method uses the Fliegel-Van Flandern algorithm.
- to_heb()[source]
Convert to a Hebrew date.
- Returns:
The equivalent Hebrew date instance.
- Return type:
- to_pydate()[source]
Convert to a datetime.date object.
- Returns:
A standard library
datetime.date
instance.- Return type:
- fast_day(hebrew=False)
Return name of fast day of date.
- festival(israel=False, hebrew=False, include_working_days=True, prefix_day=False)
Return name of Jewish festival of date.
This method will return all major and minor religous Jewish holidays not including fast days.
- Parameters:
israel (bool, optional) –
True
if you want the holidays according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the festival name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.include_working_days (bool, optional) –
True
to include festival days on which melacha (work) is allowed; ie. Pesach Sheni, Chol Hamoed, etc. Default isTrue
.prefix_day (bool, optional) –
True
to prefix multi day festivals with the day of the festival. Default isFalse
.
- Returns:
The name of the festival or
None
if the given date is not a Jewish festival.- Return type:
str or None
Examples
>>> pesach = HebrewDate(2023, 1, 15) >>> pesach.festival(prefix_day=True) '1 Pesach' >>> pesach.festival(hebrew=True, prefix_day=True) 'א׳ פסח' >>> shavuos = HebrewDate(5783, 3, 6) >>> shavuos.festival(israel=True, prefix_day=True) 'Shavuos'
- holiday(israel=False, hebrew=False, prefix_day=False)
Return name of Jewish holiday of the date.
The holidays include the major and minor religious Jewish holidays including fast days.
- Parameters:
israel (bool, optional) –
True
if you want the holidays according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the holiday name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.prefix_day (bool, optional) –
True
to prefix multi day holidays with the day of the holiday. Default isFalse
.
- Returns:
The name of the holiday or
None
if the given date is not a Jewish holiday.- Return type:
str or None
Examples
>>> pesach = HebrewDate(2023, 1, 15) >>> pesach.holiday(prefix_day=True) '1 Pesach' >>> pesach.holiday(hebrew=True, prefix_day=True) 'א׳ פסח' >>> taanis_esther = HebrewDate(5783, 12, 13) >>> taanis_esther.holiday(prefix_day=True) 'Taanis Esther'
- isoweekday()
Return the day of the week corresponding to the iso standard.
- Returns:
An integer representing the day of the week where Monday is 1 and and Sunday is 7.
- Return type:
- shabbos()
Return the Shabbos on or following the date.
- Returns:
self if the date is Shabbos or else the following Shabbos as the same date type as called from.
- Return type:
Examples
>>> heb_date = HebrewDate(5781, 3, 29) >>> greg_date = heb_date.to_greg() >>> heb_date.shabbos() HebrewDate(5781, 4, 2) >>> greg_date.shabbos() GregorianDate(2021, 6, 12)
- class pyluach.dates.GregorianDate(year, month, day, jd=None)[source]
Bases:
BaseDate
,CalendarDateMixin
A GregorianDate object represents a Gregorian date (year, month, day).
This is an idealized date with the current Gregorian calendar infinitely extended in both directions.
- Parameters:
Warning
Although B.C.E. dates are allowed, they should be treated as approximations as they may return inconsistent results when converting between date types and using arithmetic and comparison operators!
- strftime(fmt)[source]
Return formatted date.
Wraps
datetime.date.strftime()
method and uses the same format options.
- property jd
Return the corresponding Julian day number.
- Returns:
The Julian day number at midnight.
- Return type:
- classmethod from_pydate(pydate)[source]
Return a GregorianDate instance from a python date object.
- Parameters:
pydate (datetime.date) – A python standard library
datetime.date
instance.- Return type:
- static today()[source]
Return a GregorianDate instance for the current day.
This static method wraps the Python standard library’s date.today() method to get the date from the timestamp.
- Returns:
The current Gregorian date from the computer’s timestamp.
- Return type:
- is_leap()[source]
Return if the date is in a leap year
- Returns:
True if the date is in a leap year, False otherwise.
- Return type:
- to_pydate()[source]
Convert to a standard library date.
- Returns:
The equivalent datetime.date instance.
- Return type:
- dict()
Return the date as a dictionary.
- Returns:
A dictionary in the form
{'year': int, 'month': int, 'day': int}
.- Return type:
- fast_day(hebrew=False)
Return name of fast day of date.
- festival(israel=False, hebrew=False, include_working_days=True, prefix_day=False)
Return name of Jewish festival of date.
This method will return all major and minor religous Jewish holidays not including fast days.
- Parameters:
israel (bool, optional) –
True
if you want the holidays according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the festival name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.include_working_days (bool, optional) –
True
to include festival days on which melacha (work) is allowed; ie. Pesach Sheni, Chol Hamoed, etc. Default isTrue
.prefix_day (bool, optional) –
True
to prefix multi day festivals with the day of the festival. Default isFalse
.
- Returns:
The name of the festival or
None
if the given date is not a Jewish festival.- Return type:
str or None
Examples
>>> pesach = HebrewDate(2023, 1, 15) >>> pesach.festival(prefix_day=True) '1 Pesach' >>> pesach.festival(hebrew=True, prefix_day=True) 'א׳ פסח' >>> shavuos = HebrewDate(5783, 3, 6) >>> shavuos.festival(israel=True, prefix_day=True) 'Shavuos'
- holiday(israel=False, hebrew=False, prefix_day=False)
Return name of Jewish holiday of the date.
The holidays include the major and minor religious Jewish holidays including fast days.
- Parameters:
israel (bool, optional) –
True
if you want the holidays according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the holiday name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.prefix_day (bool, optional) –
True
to prefix multi day holidays with the day of the holiday. Default isFalse
.
- Returns:
The name of the holiday or
None
if the given date is not a Jewish holiday.- Return type:
str or None
Examples
>>> pesach = HebrewDate(2023, 1, 15) >>> pesach.holiday(prefix_day=True) '1 Pesach' >>> pesach.holiday(hebrew=True, prefix_day=True) 'א׳ פסח' >>> taanis_esther = HebrewDate(5783, 12, 13) >>> taanis_esther.holiday(prefix_day=True) 'Taanis Esther'
- isoweekday()
Return the day of the week corresponding to the iso standard.
- Returns:
An integer representing the day of the week where Monday is 1 and and Sunday is 7.
- Return type:
- replace(year=None, month=None, day=None)
Return new date with new values for the specified field.
- shabbos()
Return the Shabbos on or following the date.
- Returns:
self if the date is Shabbos or else the following Shabbos as the same date type as called from.
- Return type:
Examples
>>> heb_date = HebrewDate(5781, 3, 29) >>> greg_date = heb_date.to_greg() >>> heb_date.shabbos() HebrewDate(5781, 4, 2) >>> greg_date.shabbos() GregorianDate(2021, 6, 12)
- class pyluach.dates.HebrewDate(year, month, day, jd=None)[source]
Bases:
BaseDate
,CalendarDateMixin
A class for manipulating Hebrew dates.
The following format options are available similar to strftime:
Format
Example
Meaning
%a
Sun
Weekday as locale’s abbreviated name
%A
Sunday
Weekday as locale’s full name
%w
1
Weekday as decimal number 1-7 Sunday-Shabbos
%d
07
Day of the month as a 0-padded 2 digit decimal number
%-d
7
Day of the month as a decimal number
%B
Iyar
Month name transliterated into English
%m
02
Month as a 0-padded 2 digit decimal number
%-m
2
Month as a decimal number
%y
82, 01
Year without century as a zero-padded decimal number
%Y
5782
Year as a decimal number
%*a
א׳
Weekday as a Hebrew numeral
%*A
ראשון
Weekday name in Hebrew
%*d
ז׳, ט״ז
Day of month as Hebrew numeral
%*-d
א, טו
Day of month without gershayim
%*B
אייר
Name of month in Hebrew
%*y
תשפ״ב
Year in Hebrew numerals without the thousands place
%*Y
ה’תשפ״ב
Year in Hebrew numerals with the thousands place
%%
%
A literal ‘%’ character
Example
>>> date = HebrewDate(5783, 1, 15) >>> f'Today is {date:%a - %*-d %*B, %*y}' 'Today is Thu - טו אייר, תשפ"ג'
- Parameters:
- month
The Hebrew month starting with Nissan as 1 (and Tishrei as 7). If there is a second Adar it has a value of 13.
- Type:
- Raises:
ValueError – If the year is less than 1, if the month is less than 1 or greater than the last month, or if the day does not exist in the month a
ValueError
will be raised.
- property jd
Return the corresponding Julian day number.
- Returns:
The Julian day number at midnight.
- Return type:
- static from_pydate(pydate)[source]
Return a HebrewDate from a python date object.
- Parameters:
pydate (datetime.date) – A python standard library
datetime.date
instance- Return type:
- static today()[source]
Return HebrewDate instance for the current day.
This static method wraps the Python standard library’s
date.today()
method to get the date from the timestamp.- Returns:
The current Hebrew date from the computer’s timestamp.
- Return type:
Warning
Pyluach treats Hebrew dates as if they change at midnight. If it’s after nightfall but before midnight, to get the true Hebrew date do
HebrewDate.today() + 1
.
- to_greg()[source]
Convert to a Gregorian date.
- Returns:
The equivalent GregorianDate instance.
- Return type:
- to_pydate()[source]
Convert to a standard library date.
- Returns:
The equivalent datetime.date instance.
- Return type:
- hebrew_day(withgershayim=True)[source]
Return the day of the month in Hebrew letters.
- Parameters:
withgershayim (bool, optional) – Default is
True
which includes a geresh with a single character and gershayim between two characters.- Returns:
The day of the month in Hebrew letters.
- Return type:
Examples
>>> date = HebrewDate(5782, 3, 6) >>> date.hebrew_day() 'ו׳' >>> date.hebrew_day(False) 'ו' >>> HebrewDate(5783, 12, 14).hebrew_day() 'י״ד'
- hebrew_year(thousands=False, withgershayim=True)[source]
Return the year in Hebrew letters.
- Parameters:
- Return type:
- hebrew_date_string(thousands=False)[source]
Return a Hebrew string representation of the date.
The date is in the form
f'{day} {month} {year}'
.- Parameters:
thousands (bool) –
True
to have the thousands include in the year. Default isFalse
.- Return type:
Examples
>>> date = HebrewDate(5781, 9, 25) >>> date.hebrew_date_string() 'כ״ה כסלו תשפ״א' >>> date.hebrew_date_string(True) 'כ״ה כסלו ה׳תשפ״א'
- add(years=0, months=0, days=0, adar1=False, rounding=Rounding.NEXT_DAY)[source]
Add years, months, and days to date.
- Parameters:
years (int, optional) – The number of years to add. Default is 0.
months (int, optional) – The number of months to add. Default is 0.
days (int, optional) – The number of days to add. Default is 0.
adar1 (bool, optional) – True to return a date in Adar Aleph if self is in a regular Adar and after adding the years it’s leap year. Default is
False
which will return the date in Adar Beis.rounding (Rounding, optional) – Choose what to do if self is the 30th day of the month, and there are only 29 days in the destination month.
Rounding.NEXT_DAY
to return the first day of the next month.Rounding.PREVIOUS_DAY
to return the last day of the month.Rounding.EXCEPTION
to raise a ValueError. Default isRounding.NEXT_DAY
.
- Return type:
Note
This method first adds the years. If the starting month is Adar and the destination year has two Adars, it chooses which one based on the adar1 argument, then it adds the months. If the starting day doesn’t exist in that month it adjusts it based on the rounding argument, then it adds the days.
Examples
>>> date = HebrewDate(5783, 11, 30) >>> date.add(months=1) HebrewDate(5783, 1, 1) >>> date.add(months=1, rounding=Rounding.PREVIOUS_DAY) HebrewDate(5783, 12, 29)
- dict()
Return the date as a dictionary.
- Returns:
A dictionary in the form
{'year': int, 'month': int, 'day': int}
.- Return type:
- fast_day(hebrew=False)
Return name of fast day of date.
- festival(israel=False, hebrew=False, include_working_days=True, prefix_day=False)
Return name of Jewish festival of date.
This method will return all major and minor religous Jewish holidays not including fast days.
- Parameters:
israel (bool, optional) –
True
if you want the holidays according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the festival name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.include_working_days (bool, optional) –
True
to include festival days on which melacha (work) is allowed; ie. Pesach Sheni, Chol Hamoed, etc. Default isTrue
.prefix_day (bool, optional) –
True
to prefix multi day festivals with the day of the festival. Default isFalse
.
- Returns:
The name of the festival or
None
if the given date is not a Jewish festival.- Return type:
str or None
Examples
>>> pesach = HebrewDate(2023, 1, 15) >>> pesach.festival(prefix_day=True) '1 Pesach' >>> pesach.festival(hebrew=True, prefix_day=True) 'א׳ פסח' >>> shavuos = HebrewDate(5783, 3, 6) >>> shavuos.festival(israel=True, prefix_day=True) 'Shavuos'
- holiday(israel=False, hebrew=False, prefix_day=False)
Return name of Jewish holiday of the date.
The holidays include the major and minor religious Jewish holidays including fast days.
- Parameters:
israel (bool, optional) –
True
if you want the holidays according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the holiday name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.prefix_day (bool, optional) –
True
to prefix multi day holidays with the day of the holiday. Default isFalse
.
- Returns:
The name of the holiday or
None
if the given date is not a Jewish holiday.- Return type:
str or None
Examples
>>> pesach = HebrewDate(2023, 1, 15) >>> pesach.holiday(prefix_day=True) '1 Pesach' >>> pesach.holiday(hebrew=True, prefix_day=True) 'א׳ פסח' >>> taanis_esther = HebrewDate(5783, 12, 13) >>> taanis_esther.holiday(prefix_day=True) 'Taanis Esther'
- isoweekday()
Return the day of the week corresponding to the iso standard.
- Returns:
An integer representing the day of the week where Monday is 1 and and Sunday is 7.
- Return type:
- replace(year=None, month=None, day=None)
Return new date with new values for the specified field.
- shabbos()
Return the Shabbos on or following the date.
- Returns:
self if the date is Shabbos or else the following Shabbos as the same date type as called from.
- Return type:
Examples
>>> heb_date = HebrewDate(5781, 3, 29) >>> greg_date = heb_date.to_greg() >>> heb_date.shabbos() HebrewDate(5781, 4, 2) >>> greg_date.shabbos() GregorianDate(2021, 6, 12)
- subtract(years=0, months=0, days=0, adar1=False, rounding=Rounding.NEXT_DAY)[source]
Subtract years, months, and days from date.
- Parameters:
years (int, optional) – The number of years to subtract. Default is 0.
months (int, optional) – The number of months to subtract. Default is 0.
days (int, optional) – The number of days to subtract. Default is 0.
adar1 (bool, optional) – True to return a date in Adar Aleph if self is in a regular Adar and the destination year is leap year. Default is
False
which will return the date in Adar Beis.rounding (Rounding, optional) – Choose what to do if self is the 30th day of the month, and there are only 29 days in the destination month.
Rounding.NEXT_DAY
to return the first day of the next month.Rounding.PREVIOUS_DAY
to return the last day of the month.Rounding.EXCEPTION
to raise a ValueError. Default isRounding.NEXT_DAY
.
- Return type:
Note
This method first subtracts the years. If the starting month is Adar and the destination year has two Adars, it chooses which one based on the adar1 argument, then it subtracts the months. If the starting day doesn’t exist in that month it adjusts it based on the rounding argument, then it subtracts the days.
hebrewcal module
The hebrewcal module contains Hebrew calendar related classes and functions.
It contains classes for representing a Hebrew year and month, functions
for getting the holiday or fast day for a given date, and classes adapting
calendar
classes to render Hebrew calendars.
Contents
- exception pyluach.hebrewcal.IllegalMonthError(month)[source]
Bases:
ValueError
An exception for an illegal month.
Subclasses
ValueError
to show a message for an invalid month number for the Hebrew calendar. Mimicscalendar.IllegalMonthError
.- Parameters:
month (int) – The invalid month number
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception pyluach.hebrewcal.IllegalWeekdayError(weekday)[source]
Bases:
ValueError
An exception for an illegal weekday.
Subclasses
ValueError
to show a message for an invalid weekday number. Mimicscalendar.IllegalWeekdayError
.- Parameters:
month (int) – The invalid month number
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class pyluach.hebrewcal.Year(year)[source]
Bases:
object
A Year object represents a Hebrew calendar year.
It provided the following operators:
Operation
Result
year2 = year1 + int
New
Year
int
days after year1.year2 = year1 - int
New
Year
int
days before year1.int = year1 - year2
int
equal to the absolute value of the difference between year2 and year1.bool = year1 == year2
True if year1 represents the same year as year2.
bool = year1 > year2
True if year1 is later than year2.
bool = year1 >= year2
True if year1 is later or equal to year2.
bool = year1 < year2
True if year 1 earlier than year2.
bool = year1 <= year2
True if year 1 earlier or equal to year 2.
- Parameters:
year (int) – A Hebrew year.
- itermonths()[source]
Yield Month instance for each month of the year.
- Yields:
Month
– The next month in the Hebrew calendar year as aMonth
instance beginning with Tishrei through Elul.
- iterdays()[source]
Yield integer for each day of the year.
- Yields:
int
– An integer beginning with 1 for the the next day of the year.
- iterdates()[source]
Iterate through each Hebrew date of the year.
- Yields:
pyluach.dates.HebrewDate
– The next date of the Hebrew calendar year starting with the first of Tishrei.
- classmethod from_pydate(pydate)[source]
Return Year object from python date object.
- Parameters:
pydate (datetime.date) – A python standard library date object
- Returns:
The Hebrew year the given date occurs in
- Return type:
- class pyluach.hebrewcal.Month(year, month)[source]
Bases:
object
A Month object represents a month of the Hebrew calendar.
It provides the same operators as a Year object.
- Parameters:
- month
The month as an integer starting with 7 for Tishrei through 13 if necessary for Adar Sheni and then 1-6 for Nissan - Elul.
- Type:
- classmethod from_pydate(pydate)[source]
Return Month object from python date object.
- Parameters:
pydate (datetime.date) – A python standard library date object
- Returns:
The Hebrew month the given date occurs in
- Return type:
- starting_weekday()[source]
Return first weekday of the month.
- Returns:
The weekday of the first day of the month starting with Sunday as 1 through Saturday as 7.
- Return type:
- iterdates()[source]
Iterate through the Hebrew dates of the month.
- Yields:
pyluach.dates.HebrewDate
– The next Hebrew date of the month.
- molad()[source]
Return the month’s molad.
- Returns:
A dictionary in the form
{weekday: int, hours: int, parts: int}
- Return type:
Note
This method does not return the molad in the form that is traditionally announced in the shul. This is the molad in the form used to calculate the length of the year.
See also
molad_announcement
The molad as it is traditionally announced.
- molad_announcement()[source]
Return the month’s molad in the announcement form.
Returns a dictionary in the form that the molad is traditionally announced. The weekday is adjusted to change at midnight and the hour of the day and minutes are given as traditionally announced. Note that the hour is given as in a twenty four hour clock ie. 0 for 12:00 AM through 23 for 11:00 PM.
- Returns:
A dictionary in the form:
{ weekday: int, hour: int, minutes: int, parts: int }
- Return type:
- pyluach.hebrewcal.to_hebrew_numeral(num, thousands=False, withgershayim=True)[source]
Convert int to Hebrew numeral.
Function useful in formatting Hebrew calendars.
- Parameters:
num (int) – The number to convert
thousands (bool, optional) – True if the hebrew returned should include a letter for the thousands place ie. ‘ה׳’ for five thousand. Default is
False
.withgershayim (bool, optional) –
True
to include a geresh after a single letter and double geresh before the last letter if there is more than one letter. Default isTrue
.
- Returns:
The Hebrew numeral representation of the number.
- Return type:
- class pyluach.hebrewcal.HebrewCalendar(firstweekday=1, hebrewnumerals=True, hebrewweekdays=False, hebrewmonths=False, hebrewyear=False)[source]
Bases:
Calendar
Calendar base class.
This class extends the python library
Calendar
class for the Hebrew calendar. The weekdays are 1 for Sunday through 7 for Shabbos.- Parameters:
firstweekday (int, optional) – The weekday to start each week with. Default is
1
for Sunday.hebrewnumerals (bool, optional) – Default is
True
, which shows the days of the month with Hebrew numerals.False
shows the days of the month as a decimal number.hebrewweekdays (bool, optional) –
True
to show the weekday in Hebrew. Default isFalse
, which shows the weekday in English.hebrewmonths (bool, optional) –
True
to show the month name in Hebrew. Default isFalse
, which shows the month name transliterated into English.hebrewyear (bool, optional) –
True
to show the year in Hebrew numerals. Default isFalse
, which shows the year as a decimal number.
Note
All of the parameters other than firstweekday are not used in the
HebrewCalendar
base class. They’re there for use in child classes.- iterweekdays()[source]
Return one week of weekday numbers.
The numbers start with the configured first one.
- Yields:
int
– The next weekday with 1-7 for Sunday - Shabbos. The iterator starts with theHebrewCalendar
object’s configured first weekday ie. if configured to start with Monday it will first yield 2 and end with 1.
- itermonthdates(year, month)[source]
Yield dates for one month.
The iterator will always iterate through complete weeks, so it will yield dates outside the specified month.
- Parameters:
- Yields:
pyluach.dates.HebrewDate
– The next Hebrew Date of the month starting with the first date of the week the first of the month falls in, and ending with the last date of the week that the last day of the month falls in.
- itermonthdays(year, month)[source]
Like
itermonthdates()
but will yield day numbers. For days outside the specified month the day number is 0.
- yeardatescalendar(year, width=3)[source]
Return data of specified year ready for formatting.
- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains either 5 or 6 weeks, and each week contains 7 days. Days are
HebrewDate
objects.- Return type:
list
of list of list of list ofpyluach.dates.HebrewDate
- yeardays2calendar(year, width=3)[source]
Return the data of the specified year ready for formatting.
This method is similar to the
yeardatescalendar
except the entries in the week lists are(day number, weekday number)
tuples.- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains between 4 and 6 weeks, and each week contains 1-7 days. Days are tuples with the form
(day number, weekday number)
.- Return type:
- yeardayscalendar(year, width=3)[source]
Return the data of the specified year ready for formatting.
This method is similar to the
yeardatescalendar
except the entries in the week lists are day numbers.- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains either 5 or 6 weeks, and each week contains 1-7 days. Each day is the day of the month as an int.
- Return type:
- monthdatescalendar(year, month)[source]
Return matrix (list of lists) of dates for month’s calendar.
Each row represents a week; week entries are HebrewDate instances.
- Parameters:
- Returns:
List of weeks in the month containing 7
HebrewDate
instances each.- Return type:
list
of list ofpyluach.dates.HebrewDate
- monthdays2calendar(year, month)
Return a matrix representing a month’s calendar. Each row represents a week; week entries are (day number, weekday number) tuples. Day numbers outside this month are zero.
- monthdayscalendar(year, month)
Return a matrix representing a month’s calendar. Each row represents a week; days outside this month are zero.
- class pyluach.hebrewcal.HebrewHTMLCalendar(firstweekday=1, hebrewnumerals=True, hebrewweekdays=False, hebrewmonths=False, hebrewyear=False, rtl=False)[source]
Bases:
HebrewCalendar
,HTMLCalendar
Class to generate html calendars .
Adapts
calendar.HTMLCalendar
for the Hebrew calendar.- Parameters:
firstweekday (int, optional) – The weekday to start each week with. Default is
1
for Sunday.hebrewnumerals (bool, optional) – Default is
True
, which shows the days of the month with Hebrew numerals.False
shows the days of the month as a decimal number.hebrewweekdays (bool, optional) –
True
to show the weekday in Hebrew. Default isFalse
, which shows the weekday in English.hebrewmonths (bool, optional) –
True
to show the month name in Hebrew. Default isFalse
, which shows the month name transliterated into English.hebrewyear (bool, optional) –
True
to show the year in Hebrew numerals. Default isFalse
, which shows the year as a decimal number.rtl (bool, optional) –
True
to arrange the months and the days of the month from right to left. Default isFalse
.
- formatweek(theweek)
Return a complete week as a table row.
- formatweekheader()
Return a header for a week as a table row.
- formatyearpage(theyear, width=3, css='calendar.css', encoding=None)
Return a formatted year as a complete HTML page.
- itermonthdates(year, month)
Yield dates for one month.
The iterator will always iterate through complete weeks, so it will yield dates outside the specified month.
- Parameters:
- Yields:
pyluach.dates.HebrewDate
– The next Hebrew Date of the month starting with the first date of the week the first of the month falls in, and ending with the last date of the week that the last day of the month falls in.
- itermonthdays(year, month)
Like
itermonthdates()
but will yield day numbers. For days outside the specified month the day number is 0.
- itermonthdays2(year, month)
Return iterator for the days and weekdays of the month.
- itermonthdays3(year, month)
Return iterator for the year, month, and day of the month.
- itermonthdays4(year, month)
Return iterator for the year, month, day, and weekday
- iterweekdays()
Return one week of weekday numbers.
The numbers start with the configured first one.
- Yields:
int
– The next weekday with 1-7 for Sunday - Shabbos. The iterator starts with theHebrewCalendar
object’s configured first weekday ie. if configured to start with Monday it will first yield 2 and end with 1.
- monthdatescalendar(year, month)
Return matrix (list of lists) of dates for month’s calendar.
Each row represents a week; week entries are HebrewDate instances.
- Parameters:
- Returns:
List of weeks in the month containing 7
HebrewDate
instances each.- Return type:
list
of list ofpyluach.dates.HebrewDate
- monthdays2calendar(year, month)
Return a matrix representing a month’s calendar. Each row represents a week; week entries are (day number, weekday number) tuples. Day numbers outside this month are zero.
- monthdayscalendar(year, month)
Return a matrix representing a month’s calendar. Each row represents a week; days outside this month are zero.
- yeardatescalendar(year, width=3)
Return data of specified year ready for formatting.
- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains either 5 or 6 weeks, and each week contains 7 days. Days are
HebrewDate
objects.- Return type:
list
of list of list of list ofpyluach.dates.HebrewDate
- yeardays2calendar(year, width=3)
Return the data of the specified year ready for formatting.
This method is similar to the
yeardatescalendar
except the entries in the week lists are(day number, weekday number)
tuples.- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains between 4 and 6 weeks, and each week contains 1-7 days. Days are tuples with the form
(day number, weekday number)
.- Return type:
- yeardayscalendar(year, width=3)
Return the data of the specified year ready for formatting.
This method is similar to the
yeardatescalendar
except the entries in the week lists are day numbers.- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains either 5 or 6 weeks, and each week contains 1-7 days. Each day is the day of the month as an int.
- Return type:
- class pyluach.hebrewcal.HebrewTextCalendar(firstweekday=1, hebrewnumerals=True, hebrewweekdays=False, hebrewmonths=False, hebrewyear=False)[source]
Bases:
HebrewCalendar
,TextCalendar
Subclass of HebrewCalendar that outputs a plaintext calendar.
HebrewTextCalendar
adaptscalendar.TextCalendar
for the Hebrew calendar.- Parameters:
firstweekday (int, optional) – The weekday to start each week with. Default is
1
for Sunday.hebrewnumerals (bool, optional) – Default is
True
, which shows the days of the month with Hebrew numerals.False
shows the days of the month as a decimal number.hebrewweekdays (bool, optional) –
True
to show the weekday in Hebrew. Default isFalse
, which shows the weekday in English.hebrewmonths (bool, optional) –
True
to show the month name in Hebrew. Default isFalse
, which shows the month name transliterated into English.hebrewyear (bool, optional) –
True
to show the year in Hebrew numerals. Default isFalse
, which shows the year as a decimal number.
Note
This class generates plain text calendars. Any program that adds any formatting may misrender the calendars especially when using any Hebrew characters.
- formatday(day, weekday, width)[source]
Return a formatted day.
Extends calendar.TextCalendar formatday method.
- formatweekday(day, width)[source]
Return formatted weekday.
Extends calendar.TextCalendar formatweekday method.
- formatyear(theyear, w=2, l=1, c=6, m=3)[source]
Return a year’s calendar as a multi-line string.
- Parameters:
- Return type:
- formatmonth(theyear, themonth, w=0, l=0)
Return a month’s calendar string (multi-line).
- formatweek(theweek, width)
Returns a single week in a string (no newline).
- formatweekheader(width)
Return a header for a week.
- itermonthdates(year, month)
Yield dates for one month.
The iterator will always iterate through complete weeks, so it will yield dates outside the specified month.
- Parameters:
- Yields:
pyluach.dates.HebrewDate
– The next Hebrew Date of the month starting with the first date of the week the first of the month falls in, and ending with the last date of the week that the last day of the month falls in.
- itermonthdays(year, month)
Like
itermonthdates()
but will yield day numbers. For days outside the specified month the day number is 0.
- itermonthdays2(year, month)
Return iterator for the days and weekdays of the month.
- itermonthdays3(year, month)
Return iterator for the year, month, and day of the month.
- itermonthdays4(year, month)
Return iterator for the year, month, day, and weekday
- iterweekdays()
Return one week of weekday numbers.
The numbers start with the configured first one.
- Yields:
int
– The next weekday with 1-7 for Sunday - Shabbos. The iterator starts with theHebrewCalendar
object’s configured first weekday ie. if configured to start with Monday it will first yield 2 and end with 1.
- monthdatescalendar(year, month)
Return matrix (list of lists) of dates for month’s calendar.
Each row represents a week; week entries are HebrewDate instances.
- Parameters:
- Returns:
List of weeks in the month containing 7
HebrewDate
instances each.- Return type:
list
of list ofpyluach.dates.HebrewDate
- monthdays2calendar(year, month)
Return a matrix representing a month’s calendar. Each row represents a week; week entries are (day number, weekday number) tuples. Day numbers outside this month are zero.
- monthdayscalendar(year, month)
Return a matrix representing a month’s calendar. Each row represents a week; days outside this month are zero.
- prmonth(theyear, themonth, w=0, l=0)
Print a month’s calendar.
- prweek(theweek, width)
Print a single week (no newline).
- pryear(theyear, w=0, l=0, c=6, m=3)
Print a year’s calendar.
- yeardatescalendar(year, width=3)
Return data of specified year ready for formatting.
- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains either 5 or 6 weeks, and each week contains 7 days. Days are
HebrewDate
objects.- Return type:
list
of list of list of list ofpyluach.dates.HebrewDate
- yeardays2calendar(year, width=3)
Return the data of the specified year ready for formatting.
This method is similar to the
yeardatescalendar
except the entries in the week lists are(day number, weekday number)
tuples.- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains between 4 and 6 weeks, and each week contains 1-7 days. Days are tuples with the form
(day number, weekday number)
.- Return type:
- yeardayscalendar(year, width=3)
Return the data of the specified year ready for formatting.
This method is similar to the
yeardatescalendar
except the entries in the week lists are day numbers.- Parameters:
- Returns:
Returns a list of month rows. Each month row contains a list of up to width months. Each month contains either 5 or 6 weeks, and each week contains 1-7 days. Each day is the day of the month as an int.
- Return type:
- pyluach.hebrewcal.fast_day(date, hebrew=False)[source]
Return name of fast day or None.
- Parameters:
- Returns:
The name of the fast day or
None
if the given date is not a fast day.- Return type:
str or None
- pyluach.hebrewcal.festival(date, israel=False, hebrew=False, include_working_days=True, prefix_day=False)[source]
Return Jewish festival of given day.
This method will return all major and minor religous Jewish holidays not including fast days.
- Parameters:
date (BaseDate) – Any subclass of
BaseDate
can be used.israel (bool, optional) –
True
if you want the festivals according to the Israel schedule. Defaults toFalse
.hebrew (bool, optional) –
True
if you want the festival name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.include_working_days (bool, optional) –
True
to include festival days on which melacha (work) is allowed; ie. Pesach Sheni, Chol Hamoed, etc. Default isTrue
.prefix_day (bool, optional) –
True
to prefix multi day festivals with the day of the festival. Default isFalse
.
- Returns:
The name of the festival or
None
if the given date is not a Jewish festival.- Return type:
str or None
Examples
>>> from pyluach.dates import HebrewDate pesach = HebrewDate(2023, 1, 15) >>> festival(pesach, prefix_day=True) '1 Pesach' >>> festival(pesach, hebrew=True, prefix_day=True) 'א׳ פסח' >>> shavuos = HebrewDate(5783, 3, 6) >>> festival(shavuos, israel=True, prefix_day=True) 'Shavuos'
- pyluach.hebrewcal.holiday(date, israel=False, hebrew=False, prefix_day=False)[source]
Return Jewish holiday of given date.
The holidays include the major and minor religious Jewish holidays including fast days.
- Parameters:
date (pyluach.dates.BaseDate) – Any subclass of
BaseDate
can be used.israel (bool, optional) –
True
if you want the holidays according to the israel schedule. Default isFalse
.hebrew (bool, optional) –
True
if you want the holiday name in Hebrew letters. Default isFalse
, which returns the name transliterated into English.prefix_day (bool, optional) –
True
to prefix multi day holidays with the day of the holiday. Default isFalse
.
- Returns:
The name of the holiday or
None
if the given date is not a Jewish holiday.- Return type:
str or None
Examples
>>> from pyluach.dates import HebrewDate >>> pesach = HebrewDate(2023, 1, 15) >>> holiday(pesach, prefix_day=True) '1 Pesach' >>> holiday(pesach, hebrew=True, prefix_day=True) 'א׳ פסח' >>> taanis_esther = HebrewDate(5783, 12, 13) >>> holiday(taanis_esther, prefix_day=True) 'Taanis Esther'
parshios module
The parshios module has functions to find the weekly parasha.
Examples
>>> from pyluach import dates, parshios
>>> date = dates.HebrewDate(5781, 10, 5)
>>> parshios.getparsha(date)
'Vayigash'
>>> parshios.getparsha_string(date, hebrew=True)
'ויגש'
>>> parshios.getparsha_string(dates.GregorianDate(2021, 3, 7), hebrew=True)
'ויקהל, פקודי'
Note
The algorithm is based on Dr. Irv Bromberg’s, University of Toronto at http://individual.utoronto.ca/kalendis/hebrew/parshah.htm
All English parsha names are transliterated into the American Ashkenazik pronunciation.
- pyluach.parshios.getparsha(date, israel=False)[source]
Return the parsha for a given date.
Returns the parsha for the Shabbos on or following the given date.
- Parameters:
- Returns:
A list of the numbers of the parshios for the Shabbos of the given date, beginning with 0 for Beraishis, or
None
if the Shabbos doesn’t have a parsha (i.e. it’s on Yom Tov).- Return type:
- pyluach.parshios.getparsha_string(date, israel=False, hebrew=False)[source]
Return the parsha as a string for the given date.
This function wraps
getparsha
returning the parsha name.- Parameters:
date (BaseDate) – Any subclass of
BaseDate
. The date does not have to be a Shabbos.israel (bool, optional) –
True
if you want the parsha according to the Israel schedule (with only one day of Yom Tov). Default isFalse
.hebrew (bool, optional) –
True
if you want the name of the parsha in Hebrew. Default isFalse
.
- Returns:
The name of the parsha separated by a comma and space if it is a double parsha or
None
if there is no parsha that Shabbos (ie. it’s yom tov).- Return type:
str or None
- pyluach.parshios.iterparshios(year, israel=False)[source]
Generate all the parshios in the year.
Changelog
This document records all notable changes to pyluach. This project adheres to Semantic Versioning.
2.2.0 (2023-02-28)
Added prefix_day param to
festival
andholiday
methods and functions.
2.1.0 (2023-02-12)
Added
add
andsubtract
methods todates.HebrewDate
.Added
replace
method toCalendarDateMixin
.Added missing documentation for %y and %Y in formatting
HebrewDate
.
2.0.2 (2022-10-24)
Fix subtracting one date from another returning
float
instead ofint
.
2.0.1 (2022-08-24)
Fix issue (#24) where Shavuos is returned in most months on day 7.
2.0.0 (2022-05-29)
Changed equality comparers to compare object identity on unmatched types.
Equal dates of different types will no longer be considered identical keys for dicts.
Added
strftime
and__format__
methods todates.GregorianDate
.Added
__format__
method todates.HebrewDate
.Added withgershayim parameter to
dates.HebrewDate.hebrew_day
anddates.HebrewDate.hebrew_year
methodsAdded
monthcount
method tohebrewcal.Year
.Removed deprecated
hebrewcal.Month.name
attribute.Implemented HebrewCalendar classes for generating calendars similar to Calendar classes in the standard library calendar module.
1.4.2 (2022-05-20)
Fixed bug in
hebrewcal.Month
comparisons when one month is before Nissan and one is not.
1.4.1 (2022-03-25)
Fixed mistakes in docstring and error message.
1.4.0 (2022-02-21)
Added parameter include_working_days to
festival
method and function.Removed support for python < 3.6
1.3.0 (2021-06-09)
Added option to get parsha in Hebrew.
Added
dates.HebrewDate
methods to get hebrew day, month, year, and date string in Hebrew.Added method to get
hebrewcal.Month
names in Hebrew.Added methods to get year and month strings in Hebrew.
Added classmethods to
hebrewcal.Year
andhebrewcal.Month
to get objects from dates and pydates.Added methods to dates classes to get holidays, fast days and festivals.
Implemented more consistent Hebrew to English transliterations for parshios.
1.2.1 (2020-11-08)
Fixed molad having weekday of
0
when it should be7
.
1.2.0 (2020-10-28)
Created
isoweekday
method for all date types in thedates
module.Created fast_day and festival functions (#11)
Added Pesach Sheni to festival.
1.1.1 (2020-08-14)
Fixed error getting parsha of Shabbos on Rosh Hashana.
1.1.0 (2020-06-03)
Redesigned documentation.
Added
molad
andmolad_announcement
methods tohebrewcal.Month
.Stopped supporting python < 3.4 and modernized code.
1.0.1 (2019-03-02)
Initial public release