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_day())
###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.

Source Distribution

hebcal-0.0.1a0.dev4.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

hebcal-0.0.1a0.dev4-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file hebcal-0.0.1a0.dev4.tar.gz.

File metadata

  • Download URL: hebcal-0.0.1a0.dev4.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.4

File hashes

Hashes for hebcal-0.0.1a0.dev4.tar.gz
Algorithm Hash digest
SHA256 28755c3d38bb9d595ca6220b60afeedc2256b53c9d16a970afcc1d63b138b86f
MD5 96db3b5a05dba17888f1787c5e2e64be
BLAKE2b-256 6c1788a77d5867cc6fdf14d6800d408a898c3e6573dba4cd6597d92da6c317e9

See more details on using hashes here.

File details

Details for the file hebcal-0.0.1a0.dev4-py3-none-any.whl.

File metadata

  • Download URL: hebcal-0.0.1a0.dev4-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.4

File hashes

Hashes for hebcal-0.0.1a0.dev4-py3-none-any.whl
Algorithm Hash digest
SHA256 2c5e74d5305428a607ef3844c0008dd6b0872deab7a87f736953e7de61cbc9ca
MD5 8078311d7ce0da02a712ecf47f914ef6
BLAKE2b-256 361fb9d2946084c11ee85c79e1a138281470853fc52b6d935e4364ee91b2b0ca

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