Skip to main content

Various calculations for Islamic purposes

Project description

islamic_times

islamic_times is a Python package with an integrated C-extension designed to calculate Islamic astronomical parameters and prayer times. It provides functions for converting Gregorian dates to Hijri, computing sun and moon positions, estimating new moon crescent visibilities, determining Qibla direction, and calculating all major Islamic prayer times according to several methodologies and even allowing for customization of them.

Features

  • Prayer Times Calculation:
    Computes Fajr, Sunrise, Ẓuhr, ʿAṣr (Standard & Ḥanafī), Maghrib, ʿIshāʾ, and Islamic midnight (both types).

  • Astronomical Calculations:
    Determines solar and lunar positions, including right ascension, declination, altitude, and azimuth.

  • Hijri Calendar Conversion:
    Converts Gregorian dates to Hijri (Islamic) dates.

  • Qibla Direction:
    Calculates the distance and bearing (cardinal direction) to Mecca.

  • Customizable Methods:
    Supports several prayer time calculation methods (e.g., Muslim World League, ISNA, Egypt, Makkah, Karachi, Tehran, Jaʿfarī).

  • New Moon Crescent Visibility Calculations Computes the visibility of the nearest new moon for the observer according to either Yallop, 1997 or Odeh, 2006.

  • Heavy Computations Done in C For blazing fast performace, all the astronomical calculations are done in an integrated C-extension.

  • Extensive Documentation:
    Includes detailed API documentation and inline comments for clarity.

Installation

You can install the package from PyPI using pip:

pip install islamic_times

API Overview

ITLocation Class

The core of the package is the ITLocation class, which encapsulates both the observer’s parameters and the associated calculations. Key aspects include:

  • Initialization:

    • latitude, longitude, elevation: Geographic position (i.e. specifically, geodetic). Default is the Greenwich Observatory.
    • temperature, pressure: Environmental details. Default is 10°C and 101.325 kPA.
    • date: Datetime information. Default is current UTC.
    • method: Standard Prayer calculation method (e.g., 'JAFARI', 'ISNA', etc.).
    • find_local_tz: Automatically find the local timezone. Default is False (computationally expensive).
    • auto_calculate: Determines if astronomical calculations run immediately. Default is True.
    • asr_type: Defines the method for ʿAṣr calculation (0 for standard, 1 for Ḥanafī). Default is 0.
    • midnight_type: Defines the method for Islamic midnight calculation (0 for middle of sunset → sunrise, 1 for middle of sunset → fajr). Default is 0.
  • Methods:

    • update_time(new_date: datetime): Updates the observer’s date and time.
    • calculate_astro(): Computes astronomical parameters (sun & moon positions, Julian date, etc.). Used if auto_calculate is disabled.
    • calculate_prayer_times(): Determines prayer times based on the current settings. Used if auto_calculate is disabled.
    • set_prayer_method(method: str, asr_type: int): Selects and applies one of the predefined prayer calculation methods.
    • set_custom_prayer_angles(fajr_angle, maghrib_angle, isha_angle): Allows custom adjustment of solar angles.
    • set_asr_type(asr_type: int): Switch between standard and Ḥanafī ʿAṣr calculations.
    • set_midnight_type(midnight_type: int): Customize Islamic midnight calculation.
    • observer(): Returns the observer’s geographical/environmental parameters.
    • dates_times(): Provides all date and time details, including Hijri conversion.
    • prayer_times(): Retrieves the computed prayer times.
    • mecca(): Provides distance and Qibla direction to Mecca.
    • sun(): Returns information about the Sun’s position and properties.
    • moon(): Returns information about the Moon’s position, illumination, and phase.
    • moonphases(): Provides details on the nearest moon phases.
    • visibilities(days: int, criterion: int): Computes the visibilities of the nearest new moon crescent for the given amount of days and according to a given criterion.

For a full list of methods and usage details, please refer to the inline documentation within each module.

Usage

Below is a basic example on how to calculate prayer times for a given location and time:

from datetime import datetime
from islamic_times.islamic_times import ITLocation
from islamic_times.dataclasses import PrayerTimes, Visibilities

location: ITLocation = ITLocation(
    latitude=43.651070,    # Toronto latitude
    longitude=-79.347015,  # Toronto longitude
    elevation=10,          # Elevation in meters
    temperature=15,        # Temperature in °C
    pressure=101.325,      # Atmospheric pressure in kPa
    date=datetime(2005, 6, 1, 12, 0, 0, 0),
    method='ISNA',         # Prayer calculation method
	find_local_tz=True	   # Automatically find the local timezone of the observer
)

# Calculate prayer times and diplay them
prayers: PrayerTimes = location.prayer_times()
print(prayers)

# Calculate the visibilities of the nearest new moon crescent and display them
# (By default, it will compute visibilities for three days from conjunction and according to Yallop, 1997)
vis: Visibilities = location.visibilities()
print(vis)

Output:

Prayer Times at Observer Timezone
        Method:                 Islamic Society of North America (ISNA)
        Fajr:                   03:52:38 01-06-2005
        Sunrise:                05:38:38 01-06-2005
        Ẓuhr:                   13:15:06 01-06-2005
        ʿAṣr:                   17:19:57 01-06-2005
        Sunset:                 20:52:17 01-06-2005
        Maghrib:                20:52:17 01-06-2005
        ʿIshāʾ:                 22:38:41 01-06-2005
        Midnight:               01:15:13 02-06-2005
Visibility of New Moon Crescent:
        Criterion:              Yallop
        21:05:37 06-06-2005:    -0.753  F: Not visible; below the Danjon limit.
        21:32:17 07-06-2005:    +0.309  A: Easily visible.
        21:54:55 08-06-2005:    +1.517  A: Easily visible.

Also included is test.py which provides a simple example to showcase the package's functionality.

Modules

The package is organized into several modules:

  • islamic_times.py:
    Contains the ITLocation class and functions to integrate astronomical calculations with Islamic timings.

  • dataclasses.py:
    Defines core data structures (e.g., Angle, RightAscension, Distance, ObserverInfo, IslamicDateInfo, and PrayerMethod) used across the package.

  • moon_equations.py:
    Implements lunar calculations including the Moon’s position, phase, and new moon visibility.

  • prayer_times.py:
    Implements the logic for calculating prayer times using different methodologies and handling extreme latitude cases.

  • sun_equations.py:
    Contains routines for solar position calculations (declination, right ascension, altitude, azimuth) and the equation of time.

  • time_equations.py:
    Provides functions for date conversion (Gregorian ⇄ Julian & Hijri), time fractions, sidereal time, and related time equations.

  • calculation_equations.py:
    Implements various mathematical routines for angle normalization, trigonometric functions in degrees, and other custom calculations.

Dependencies

The package requires the following external libraries:

  • numpy – for numerical operations.
  • pytz – for timezone management.
  • timezonefinder – (optional) to auto-determine local timezone based on coordinates.
  • dataclasses – used if running on Python versions earlier than 3.7.

Default Prayer Calculation Methods

The library supports the following predefined methods:

  • ISNA: Islamic Society of North America
  • MWL: Muslim World League
  • Umm al-Qura: Umm al-Qura University, Makkah
  • Egyptian: Egyptian General Authority of Survey
  • Karachi: University of Islamic Sciences, Karachi
  • Tehran: Institute of Geophysics, University of Tehran
  • Jafari: Shia Ithna Ashari, Leva Research Institute, Qom

You can also define custom solar angles for Fajr, Maghrib, and ʿIshāʾ prayers.


Project Structure

islamic_times/
├── include/                # Header files for C extensions
│   ├── c_moon_equations.h
│   ├── c_sun_equations.h
│   └── ...
├── src/                    # Source files for C extensions
│   ├── c_moon_equations.c
│   ├── c_sun_equations.c
│   └── ...
├── islamic_times/          # Python modules
│   ├── islamic_times.py    # Main library file
│   ├── prayer_times.py     # Prayer time calculations
│   ├── sun_equations.py    # Sun-related calculations
│   ├── moon_equations.py   # Moon-related calculations
│   └── ...
├── mapper.py               # Mapping script for new moon crescent visibilities
├── test.py                 # Example/testing script
├── setup.py                # Build and installation script
└── README.md               # Project documentation

Mapping New Moon Crescent Visibilities

Included in this package is an efficient mapping tool to map the new moon crescent visibilities for the observer. The mapping is done using the mapper.py script, which takes the visibility data and generates a visual representation of the crescent visibility across different locations.

The more readily available parameters are found in the if __name__ == '__main__': of the script and are as follows:

if __name__ == "__main__":
    # Vars
    today = datetime(2025, 4, 11)
    master_path: str = ""
    total_months: int = 1
    map_region: str = "WORLD" # 'NORTH_AMERICA' 'EUROPE' 'MIDDLE_EAST' 'IRAN' 'WORLD'
    map_mode: str = "category" # "raw" "category"
    resolution: int = 300
    days_to_generate: int = 3
    criterion: int = 1 # Either 0 (Odeh, 2006), or 1 (Yallop, 1997)

    map_region = map_region.upper()
    main()

Below is an example of a generated visibility map for the new moon crescent on 2025-04-27 (Dhū al-Qaʿdah 1446) using the Yallop criterion:

2025-04-27 Dhū al-Qaʿdah 1446—Yallop

Contributing

All contributions are welcome!

License

This project is licensed under the MIT License.

References

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

islamic_times-2.0.0.tar.gz (23.8 MB view details)

Uploaded Source

Built Distributions

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

islamic_times-2.0.0-cp311-cp311-win_amd64.whl (220.5 kB view details)

Uploaded CPython 3.11Windows x86-64

islamic_times-2.0.0-cp311-cp311-win32.whl (218.6 kB view details)

Uploaded CPython 3.11Windows x86

islamic_times-2.0.0-cp311-cp311-musllinux_1_1_x86_64.whl (165.6 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

islamic_times-2.0.0-cp311-cp311-musllinux_1_1_i686.whl (153.8 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ i686

islamic_times-2.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (150.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

islamic_times-2.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (140.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

islamic_times-2.0.0-cp311-cp311-macosx_11_0_arm64.whl (72.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

islamic_times-2.0.0-cp311-cp311-macosx_10_9_x86_64.whl (73.7 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

islamic_times-2.0.0-cp310-cp310-win_amd64.whl (219.0 kB view details)

Uploaded CPython 3.10Windows x86-64

islamic_times-2.0.0-cp310-cp310-win32.whl (216.4 kB view details)

Uploaded CPython 3.10Windows x86

islamic_times-2.0.0-cp310-cp310-musllinux_1_1_x86_64.whl (161.6 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

islamic_times-2.0.0-cp310-cp310-musllinux_1_1_i686.whl (149.6 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ i686

islamic_times-2.0.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (148.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

islamic_times-2.0.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (139.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

islamic_times-2.0.0-cp310-cp310-macosx_11_0_arm64.whl (72.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

islamic_times-2.0.0-cp310-cp310-macosx_10_9_x86_64.whl (73.7 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file islamic_times-2.0.0.tar.gz.

File metadata

  • Download URL: islamic_times-2.0.0.tar.gz
  • Upload date:
  • Size: 23.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for islamic_times-2.0.0.tar.gz
Algorithm Hash digest
SHA256 deb918168cd66da6884de7f9edb9cecfb5237bc073ff20995af47a614b10f8f4
MD5 366928526070d4734fa0cd9acb98456e
BLAKE2b-256 34e0372cb4b00f19b05313d239dcfb7f59951440a1dc33c094eab2071788fe31

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bb8e54d209623f24457535f0cc5b201664f24960aee976ce6be90917311d8bee
MD5 4c7c2eea0cc6c1db6ade56166d917196
BLAKE2b-256 f9522af0bfe2831a340cf6ca500c9155f77868051e62433b6cf35f7e852b6585

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp311-cp311-win32.whl.

File metadata

  • Download URL: islamic_times-2.0.0-cp311-cp311-win32.whl
  • Upload date:
  • Size: 218.6 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for islamic_times-2.0.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 f01116c3a9ed267e8921d0172933eaebe1b2bdae4ef408d1d81349552b32d325
MD5 1deb239efdaa8c9fff3305827013917b
BLAKE2b-256 2eb1ce997532b99c31b0b1e40022797073c1a4781ad307d99b5d11ed3e80bd4e

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 36ba6519c2fea3d365445b9202ee1258e2cc04f7026c9a388b5bdd360f5d9838
MD5 07a9c0f27ccdae8e7a91914110191049
BLAKE2b-256 66951f836bb78c74142d58238136d799c04773a811b74681f7a16baf1e507b21

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 88ec4943e5990264daaeae1d57edc620e247e7969406fb7d2f73ef4e4ce4ed14
MD5 e2e6d3e2295844dee625e4374943cf0f
BLAKE2b-256 c9d1b0f8538fdaaef5c554883b57e98236ec3f3243a85a9218cd0f7437a28727

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5897aa7ab948628dce03ad140c2d2e5a12a549b57e2ffa25c20da71cefee2494
MD5 50b5073bce95a25396cfd7710e5d088a
BLAKE2b-256 fcb4c63874f99db009e93a4326752f02684555d6251fa4d675af83cbdf89bdaa

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 43ef8292e9b4f280c4b6ac61aba4c748495b49c1e2fc4fe117d5063f48c5bf2c
MD5 6eefbd1a0c5d60b4faae92001c3f6749
BLAKE2b-256 5f34c80e9f0648fcd43d3f0349567cf2c4a6365b2bea732a0886f9ed86e4a5aa

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9222e298cadb3c74f55209b2309d8cd42151bc1d7eede51ba1119de53a002fc7
MD5 50a38c9a7d4be07793b7f36366619375
BLAKE2b-256 d4704172b77ab2150f4d632c631c94480eaef142a1e5d40bd98588c906be22c0

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f080a2879a299c2fb652ccc749891e5425b623e23cbb8e9ea29aadd9ddce748f
MD5 cae3b6183cdea0c222bf653ce4ed01c7
BLAKE2b-256 1eae13876ba5b388b5644a5ccd2dd73e3cc97d42f3c288470862b26a7f4fc8b8

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ff232ea0ff09961dc81b4534f455d1ff2464d2265e176ed397456a4bf958eeae
MD5 a6d54d8a7121be6d1aa16665610cf224
BLAKE2b-256 d4d6db79f6bd3a66a9c0ef6a8cf6401156bd81e231aa0050a90c30c31ff80d43

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp310-cp310-win32.whl.

File metadata

  • Download URL: islamic_times-2.0.0-cp310-cp310-win32.whl
  • Upload date:
  • Size: 216.4 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for islamic_times-2.0.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 cf37c88b2dd9db4aa33177b783cb0af0e80f29ea5b59e29face456bf3328b437
MD5 13492a80f9181cbda89c837a9cd5a7ad
BLAKE2b-256 2f1a38450fc5ae060aca9ec674c951f53d773fe296b84ed37bc4e1e5f5b1e542

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 25c1e44a219eb50c409092cf596936d384485583a3885157269404d57f38bee9
MD5 eec38090d472a135ed19ae5f9978bd1e
BLAKE2b-256 39b8358184ce78ad57c8b95b250a706b4e6acf6de643a480655f79e9cda379cb

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp310-cp310-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp310-cp310-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 c80afa280adbcb5976fcf3ee2d18f43206f672bc81ea4a461020467f5c140a74
MD5 379b6a0ea321c31be8b4aaa595d4dbb1
BLAKE2b-256 14de39c477afa5b2f4ac6863bec893c02aaad0f0001ccacafb590d31a57ab551

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca873013354ba5eff6295b2e6fe14873afde552b2b7d89070ff315a131319992
MD5 def182f7547d2a7ff6346533e1962d60
BLAKE2b-256 a517d43fc99eb4ed3a05a158af5f431040b9726e0bf97b0e89ed84e494eaa118

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3f9810db6056040c0e5b7ad00ec9c420c67a2453624fb44f9f83f2fc67e660ac
MD5 f4bb8fd4b3f89c5ecf5b7b8bf3c979df
BLAKE2b-256 f198dc0495278b2c6bf3c79355ddde0adf0d44060e1aeeb4899d0da181ae40e3

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f25e0a87b5814b4193e89b8551445d5b11a27e1d3c5653611f1bbf8c6892506a
MD5 f75c09d889820aff01e3dca682997e0a
BLAKE2b-256 2633958a85374cac789f2f5f9640b9cd94c8952fb1d25fef2e68229241d68613

See more details on using hashes here.

File details

Details for the file islamic_times-2.0.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for islamic_times-2.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e10a755f024df831bb95366a8e6b314101a13236780f7fb25e99ed9c71a2df94
MD5 e91aba252406131a7f24784542c3c29a
BLAKE2b-256 e3592b4e0c04caa5f60450060d048fb0f8c417d669bc2bd7767df2896c68d2e9

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