Skip to main content

A Python package to manipulate location aware, Hebrew dates, times, and holidays.

Project description

Hebcal

A python package for working with Hebrew dates, times, and holidays

Note: This is still in development and not ready for production. There will still be lots of breaking changes.

There are several python packages that deal with Hebrew dates, Z'manim and Jewish holidays. However, since the Hebrew calendar considers nightfall the beginning of the new day, I've found it very inconvenient to work with other packages. Just converting a Gregorian date to a Hebrew date doesn't give you the proper conversion, as it could be past nightfall, which needs to manually accommodated.

The same goes for any Jewish holiday package. You first need to figure out what the real Hebrew date is before you can determine if it's currently a holiday.

I wanted something that I can just ask "is today a rest holiday?" and I should get a True or False.

I wrote Hebcal to solve these problems. It takes in a latitude and longitude to calculate the location. It can be installed through pip: pip install hebcal.

Here's a quick example:

import hebcal

time_info = hebcal.TimeInfo.now(latitude=40.089909, longitude=-74.216270)
print(time_info.today_sunrise().strftime('%-I:%M:%S %p'))
###6:48:58 AM
print(time_info.hebrew_date)
###(5779, 7, 19)

You can input a specific date and time with a string:

time_info = hebcal.TimeInfo('2018, 9, 27 10:07 pm', latitude=40.089909, longitude=-74.216270)
print(time_info.today_sunrise().strftime('%-I:%M:%S %p'))
###6:48:58 AM
print(time_info.hebrew_date)
###(5779, 7, 19)

The Hebrew date that is returned takes into account sunrise/sunset. If it's after sunset it will automatically return the correct Hebrew date.

You can also query directly if its night, or day

print(time_info.is_night())
###True
print(time_info.is_yom())
###False
Note: Calculating the timezone from the lat/lon slows down the calculations. It is best to pass the timezone as an argument:
time_info = hebcal.TimeInfo.now(timezone='America/New_York', latitude=40.089909, longitude=-74.216270)

You can manually get the timezone using Hebcal:

from hebcal.util.location import get_location
timezone = get_location(latitude==40.089909, longitude=-74.216270)
print(timezone)
###America/New_York

Hebcal zmanim.Zmanim

note: All times are datetime.datetime objects. They can be formated using .strftime().

Here's an example of the hebcal.zmanim

time_info = hebcal.TimeInfo.now(latitude=40.089909, longitude=-74.216270)

# pass a hbcal.TimeInfo object into Zmanim
zmanim = hebcal.Zmanim(time_info)
print(zmanim.last_shema_ma)
###2018-09-27 09:12:12.895624-04:00
print(zmanim.last_shema_ma.strftime("%-I:%M:%S %p"))
###9:12:12 AM

Other than accessing individual zmanim, You can just print the Zmanim object, which returns formated times (i.e. 9:12:12 AM).

Another option is to get all the zmanim configures as json:

zmanim_json = hebcal.Zmanim.json(time_info)
print(zmanim_json['earliest mincha'])
###2018-09-27 13:17:19.756457-04:00

Add calandar README here.

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
hebcal-0.0.1a0.dev2-py3-none-any.whl (18.7 kB) Copy SHA256 hash SHA256 Wheel py3 Oct 5, 2018
hebcal-0.0.1a0.dev2.tar.gz (11.9 kB) Copy SHA256 hash SHA256 Source None Oct 5, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page