Skip to main content

adhanpy

License: MIT pytest

This is a port of batoulapps/adhan-java, a prayer times program, from Java to Python. As it stands the project reuses most of the structure of the original project but may differ through refactoring and in an effort to rewrite in a more pythonic way where it makes sense. Like the original project there are no external dependencies except in development where pytest and other development tools are made use of.

Requirements

  • Python >= 3.9

Installation

pip install adhanpy

Usage

Create a PrayerTimes object by passing geo coodinates, datetime and either passing a calculation method:

prayer_times = PrayerTimes(coordinates, today, CalculationMethod.MOON_SIGHTING_COMMITTEE)

or a calculation parameters object allowing to choose from different parameters such as angles:

parameters = CalculationParameters(fajr_angle=18, isha_angle=18)
prayer_times = PrayerTimes(coordinates, today, calculation_parameters=parameters)

If passing a calculation method to the calculation parameters object, the calculation method will have precedence and will overwrite other parameters you may have also passed.

For instance the MOON_SIGHTING_COMMITTEE method uses a fajr angle of 18 and if for instance the calculation parameters object is created by passing a different fajr angle the latter will be ignored:

parameters = CalculationParameters(fajr_angle=12, method=CalculationMethod.MOON_SIGHTING_COMMITTEE)
prayer_times = PrayerTimes(coordinates, today, calculation_parameters=parameters)
print(parameters.fajr_angle)
# 18.0 (the fajr_angle argument has been ignored)

Times are returned in UTC time via datetime objects, for convenience it is possible to directly pass a ZoneInfo object to PrayerTimes:

london_zone = ZoneInfo("Europe/London")
prayer_times = PrayerTimes(
    coordinates,
    today,
    CalculationMethod.MOON_SIGHTING_COMMITTEE,
    time_zone=london_zone,
)

# this will display the time in the chosen time zone
print(f"Fajr: {prayer_times.fajr.strftime('%H:%M')}")

or convert to a different timezone later, each prayer time object is in fact a datetime object:

prayer_times = PrayerTimes(
    coordinates,
    today,
    CalculationMethod.MOON_SIGHTING_COMMITTEE,
)

# the following will be in UTC
print(f"Fajr: {prayer_times.fajr.strftime('%H:%M')}")

# and to use a different timezone on the datetime object itself:
london_zone = ZoneInfo("Europe/London")
print(f"Fajr: {prayer_times.fajr.astimezone(london_zone).strftime('%H:%M')}")

A full example is located in src/example of the project directory.

Development

To install adhanpy for development purposes, run the following:

python3 -m virtualenv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install -e .

Licence

MIT

Acknowledgments

Credits go to the author of the original implementation in Java and other languages, especially the very complex astronomy formulas.

Release files for adhanpy 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adhanpy 1.0.5
File Size Uploaded
adhanpy-1.0.5.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for adhanpy 1.0.5
File Interpreter ABI Platform
adhanpy-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 kB

Release files / adhanpy-1.0.5.tar.gz

Download URL adhanpy-1.0.5.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9b6670f8d563d61d4f9fde581165cbe692c917710b694cb6b5e2130ffc902680
BLAKE2b-256 checksum
How to use checksums
82771111dd754493146e14d4a28ac4df114cc5c74b4317055a300dd5df3df1bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / adhanpy-1.0.5-py3-none-any.whl

Download URL adhanpy-1.0.5-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79d765e6b91d3b29448988691957b51109faaca10f498eb3656e7c87b56b6066
BLAKE2b-256 checksum
How to use checksums
365b89b9705b95aca620409574ce4bd4e013c33d3fd1f27edf7ab9b9ca40a18c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page