Skip to main content

al-falak

License: MIT pytest

Al-Falak is an offline library for Islamic astronomy, starting with precise prayer times and expanding into broader temporal calculations. It follows a pipeline architecture: input coordinates and date flow through astronomical models to produce accurate timekeeping outputs. It originates from the same batoulapps/adhan port lineage as alphahm/adhanpy (via that Python port) and is developed and released as an independent library, from a detached fork of the original adhanpy repository.

Features

  • Offline — no network calls, no API keys
  • Timezone-aware — returns UTC datetime objects, with optional ZoneInfo conversion
  • Multiple calculation methods — Muslim World League, ISNA, Egyptian, Karachi, Umm al-Qura, Dubai, Moonsighting Committee, and more
  • Polar region support — configurable strategies for locations above the Arctic/Antarctic circles
  • High latitude rules — middle of the night, seventh of the night, twilight angle
  • Madhab selection — Shafi (default) and Hanafi for Asr calculation
  • Qibla direction — degrees clockwise from north
  • Sunnah times — middle and last third of the night
  • CLI — python -m alfalak for quick terminal output
  • Fully typed — PEP 561 py.typed marker, mypy --disallow-untyped-defs clean

Requirements

  • Python >= 3.11

Installation

pip install al-falak

Quick Start

from datetime import datetime
from alfalak import PrayerTimes, CalculationMethod, Prayer

# Coordinates for Raleigh, NC
coordinates = (35.7750, -78.6336)
today = datetime.now()

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

print(f"Fajr:    {prayer_times.fajr.strftime('%H:%M')}")
print(f"Sunrise: {prayer_times.sunrise.strftime('%H:%M')}")
print(f"Dhuhr:   {prayer_times.dhuhr.strftime('%H:%M')}")
print(f"Asr:     {prayer_times.asr.strftime('%H:%M')}")
print(f"Maghrib: {prayer_times.maghrib.strftime('%H:%M')}")
print(f"Isha:    {prayer_times.isha.strftime('%H:%M')}")

Usage

Timezone Conversion

Pass a ZoneInfo object to get times in that timezone:

from zoneinfo import ZoneInfo
from alfalak import PrayerTimes, CalculationMethod

london_zone = ZoneInfo("Europe/London")
prayer_times = PrayerTimes(
    (51.5074, -0.1278),
    datetime.now(),
    CalculationMethod.MOON_SIGHTING_COMMITTEE,
    time_zone=london_zone,
)

Custom Calculation Parameters

from alfalak import PrayerTimes, CalculationParameters

params = CalculationParameters(
    fajr_angle=18,
    isha_angle=18,
    isha_interval=90,  # Isha = Maghrib + 90 minutes
)
prayer_times = PrayerTimes(
    coordinates,
    today,
    calculation_parameters=params,
)

Qibla Direction

from alfalak import Qibla

direction = Qibla((35.7750, -78.6336)).direction
print(f"Qibla: {direction:.1f}° clockwise from north")

Sunnah Times

from alfalak import PrayerTimes, SunnahTimes, CalculationMethod

prayer_times = PrayerTimes(coordinates, today, CalculationMethod.MUSLIM_WORLD_LEAGUE)
sunnah = SunnahTimes(prayer_times)

print(f"Middle of the night: {sunnah.middle_of_the_night}")
print(f"Last third:         {sunnah.last_third_of_the_night}")

Polar Regions

from alfalak import PrayerTimes, CalculationParameters, PolarCircleRule

params = CalculationParameters(
    polar_circle_rule=PolarCircleRule.NEAREST_LATITUDE,  # default
)
prayer_times = PrayerTimes(
    (78.2232, 15.6267),  # Longyearbyen, Svalbard
    datetime.now(),
    calculation_parameters=params,
)

Command Line

python -m alfalak --latitude 35.7750 --longitude -78.6336 --date 2015-07-12 --method NORTH_AMERICA

Output:

fajr=2015-07-12T08:42:00+00:00
sunrise=2015-07-12T10:08:00+00:00
dhuhr=2015-07-12T17:21:00+00:00
asr=2015-07-12T21:09:00+00:00
maghrib=2015-07-13T00:32:00+00:00
isha=2015-07-13T01:57:00+00:00

API Reference

See docs/user/api-reference.md for the full API reference (rendered site).

Migrating from adhanpy

Al-Falak is developed as an independent library, but it originates from the same batoulapps/adhan port lineage as adhanpy, so the public surface keeps the same class and method names — switching packages is typically a matter of changing the install (adhanpy → al-falak) and the import (adhanpy → alfalak). The move exists to track currently supported Python versions, keep development dependencies and tooling current, and leave room for the milestones of this project to evolve on their own. In return you get a hardened AlFalakError hierarchy, fully typed APIs, and ongoing maintenance. See the migration guide for details.

Examples

See src/example/ for comprehensive examples covering:

  • Basic usage
  • Calculation methods comparison
  • Qibla direction
  • Sunnah times
  • Polar region strategies
  • High latitude rules
  • Madhab selection
  • CLI usage

Development

See CONTRIBUTING.md for setup and contribution guidelines.

Architecture

See ARCHITECTURE.md for a high-level overview of the codebase.

Attribution & References

Original Authors & Projects

  • batoulapps — Original adhan library in Java, JavaScript, Swift, and Kotlin. The astronomical calculation methods, formulas, and overall architecture are derived from these implementations.
  • alphahm — Original adhanpy Python port. This fork continues from that work.

Astronomical Calculation Sources

The prayer time calculation methods, mathematical formulas, and computational steps are derived from:

  • Jean Meeus — Astronomical Algorithms (2nd ed., Willmann-Bell, 1998). The core astronomical formulas for solar position, equation of time, and hour angle calculations.
  • US Naval Observatory (USNO) — Solar position algorithms and twilight calculations. Reference: aa.usno.navy.mil
  • PrayTimes.org — Standard prayer time calculation methods and Fajr/Isha angle conventions. Reference: praytimes.org
  • Muslim World League — Fajr angle 18°, Isha angle 17°
  • ISNA (Islamic Society of North America) — Fajr angle 15°, Isha angle 15°
  • Egyptian General Authority of Survey — Fajr angle 19.5°, Isha angle 17.5°
  • University of Islamic Sciences, Karachi — Fajr angle 18°, Isha angle 18°
  • Umm al-Qura University, Makkah — Fajr angle 18.5°, Isha interval 90 minutes
  • Moonsighting Committee — Fajr angle 18°, Isha angle 18°, with seasonal adjustments

License

This project is licensed under the MIT License — see LICENSE for details.

Credits

  • batoulapps — original adhan implementation and calculation methods
  • alphahm — original adhanpy Python port
  • Azahari Zaman — community maintenance of al-falak

Metadata

Release files for al-falak 1.1.0

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

Source distribution (sdist)

Source distribution for al-falak 1.1.0
File Size Uploaded
al_falak-1.1.0.tar.gz 207.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for al-falak 1.1.0
File Interpreter ABI Platform
al_falak-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 247.5 kB

Release files / al_falak-1.1.0.tar.gz

Download URL al_falak-1.1.0.tar.gz
Size 207.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9b4c9328a94614d5ff756bc300a6a0318b461292587679f8efd33a06cae47e0b
BLAKE2b-256 checksum
How to use checksums
8806f3b1f30792cbdfde008205dfdc7452729a3fadbf57c702c30fe8c8a19e94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / al_falak-1.1.0-py3-none-any.whl

Download URL al_falak-1.1.0-py3-none-any.whl
Size 40.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
611e08f7195482c80c4e6e3013e1f418492f1ce21a9f7973faa745107e1daeac
BLAKE2b-256 checksum
How to use checksums
706ed9ac90a1aa3ac1292713c8e88f78bee185de65ba6ac0c71efd95872e7301
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

1.2.1

2 release files

1.2.0

2 release files

This release

1.1.0 This release

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