Skip to main content

MAWAQIT Python library

CI PyPI Python License

The official Python library for the MAWAQIT API: search mosques, read their prayer times, iqama times, Hijri date and screen settings, and draw a random hadith. It also calculates prayer times for a position, without the API.

  • Async and sync clients, with the same methods.
  • Fully typed: every argument, response and field, documented in your editor.
  • Robust: retries with backoff, timeouts, and one exception per kind of error.
  • Helpers for the prayers of a day, the next prayer and the Hijri date, which handle iqama offsets, Imsak, Jumu'a and daylight saving time.
  • Prayer times for a position, calculated offline, with the methods and country defaults of MAWAQIT.
  • Generated from the OpenAPI description of the API, so the methods and models follow it exactly.

Installation

pip install mawaqit

Python 3.10 or newer.

Usage

import asyncio

from mawaqit import AsyncMawaqitClient


async def main() -> None:
    async with AsyncMawaqitClient(token="...") as client:
        mosques = await client.mosques.search(lat=48.8414, lon=2.3557)
        prayer_times = await client.mosques.prayer_times(mosques[0].uuid)
        # Fajr, Shuruq, Dhuhr, Asr, Maghrib and Isha of 1 January.
        print(prayer_times.calendar[0]["1"])


asyncio.run(main())

The sync client has the same methods, without await:

from mawaqit import MawaqitClient

with MawaqitClient(token="...") as client:
    mosques = client.mosques.search(word="grande mosquée de paris")
Method Returns
client.mosques.search(word=...) or (lat=..., lon=...) A list of Mosque
client.mosques.get(mosque_id) The MosqueSummary of a mosque or a home, with its UUID
client.mosques.prayer_times(uuid) The PrayerTimes of the year, with iqama
client.mosques.hijri_settings(uuid) The HijriSettings of the mosque
client.mosques.config(uuid) The MosqueConfig: the settings of the mosque screens
client.mosques.flash_message(uuid) The FlashMessage of the mosque screens, or None
client.hadiths.random(lang=...) A random Hadith in a language, or None

Responses are Pydantic models, from mawaqit.types, with snake_case attributes: mosque.women_space, prayer_times.iqama_calendar. model_dump(by_alias=True) gives back the JSON of the API, and fields the API adds later are kept in model_extra.

Authentication

Every method but auth.login() and hadiths.random() needs an API token, passed as token= or set in the MAWAQIT_TOKEN environment variable.

Prayer times of a day

client.mosques.prayer_times() returns the times of the whole year, as the mosque entered them. mawaqit.prayer_times reads them for a day, as datetimes in the time zone of the mosque, with the iqama resolved, Imsak, and Jumu'a on Fridays:

from mawaqit.prayer_times import next_prayer, night, prayer_day

times = await client.mosques.prayer_times(uuid)

today = prayer_day(times)  # Or prayer_day(times, date(2026, 10, 5)).
today.fajr.time  # "06:12"
today.fajr.at  # datetime(2026, 10, 5, 6, 12, tzinfo=ZoneInfo("Europe/Paris"))
today.fajr.iqama  # 06:30, even when the mosque entered "+18"
today.jumua  # The Jumu'a prayers on Fridays, or ()

upcoming = next_prayer(times)  # Jumu'a instead of Dhuhr on Fridays.
iftar = next_prayer(times, prayer="maghrib")  # The next Maghrib, today or tomorrow.
night(times).last_third_start  # The thirds of the night, from Maghrib to Fajr.

They handle what the raw calendar leaves to you:

  • Mosques that display Imsak have 7 times a day, with Sabah as Fajr.
  • Iqama times are HH:MM or minutes after the adhan, like +10.
  • An Isha after midnight, in summer far from the equator, belongs to the day before.
  • Times are converted in the time zone of the mosque, through daylight saving time changes.
  • A time entered by hand that is invalid gives a None prayer, rather than a wrong one.

next_prayer() takes shuruq, jumua, iqama and prayer keywords: iqama=True gives the next iqama rather than the next adhan, and prayer the next time of one prayer, like "maghrib" for iftar or "jumua" for the next Friday. Every function takes a timezone=, to avoid loading the time zone of the mosque, like in Home Assistant.

Prayer times for a position

For a place without a mosque, calculate_prayer_times() calculates the prayer times of a year from a position. It calls no API: it works offline. The result has the shape of client.mosques.prayer_times(), so prayer_day(), next_prayer(), night() and hijri.today() read it like the times of a mosque:

from dataclasses import replace

from mawaqit.prayer_times import (
    CalculationPosition,
    calculate_prayer_times,
    calculation_method_name,
    default_calculation_settings,
    next_prayer,
    prayer_day,
)

settings = default_calculation_settings("FR")  # The method of the country, Shafi'i Asr.
times = calculate_prayer_times(
    CalculationPosition(48.85, 2.35, "Europe/Paris"),
    replace(settings, madhab="hanafi"),
)

prayer_day(times).fajr.time  # "06:42" on 26 November, in the time zone of the position
next_prayer(times)
calculation_method_name(settings.method, "fr")  # "Fajr et Isha à 15°"
Setting Values
method A method of CALCULATION_METHODS, like angle_15, or custom with fajr_angle and isha_angle
madhab shafi or hanafi, for Asr
high_latitude_rule twilight_angle, middle_of_the_night or seventh_of_the_night, for high latitudes
adjustments Whole minutes added to fajr, shuruq, dhuhr, asr, maghrib or isha

default_calculation_settings(country_code) gives the method of a country, 15° in France for example, the Hanafi Asr in Pakistan, India, Bangladesh and Afghanistan, and the twilight_angle rule. The astronomy is a port of adhan-js, with Dhuhr a minute after the solar transit and every time rounded to the nearest minute: the same minutes as calculatePrayerTimes() of the TypeScript library. The third argument, CalculationOptions(year=..., hijri_adjustment=..., jumua_at_dhuhr=..., imsak_minutes_before_fajr=...), is optional.

Hijri date

mawaqit.hijri computes the Hijri date of a mosque from its settings, like the mosque screens and the app do:

from mawaqit import hijri
from mawaqit.hijri import HijriMonth

settings = await client.mosques.hijri_settings(uuid)
today = hijri.today(settings, "Europe/Paris")  # The time zone of the mosque.
print(today)  # 9 Ramadan 1448
if today.month is HijriMonth.RAMADAN:
    ...

The date changes at midnight in the time zone of the mosque. Only today's date is reliable: mosques change their settings after the moon sighting. hijri.from_gregorian(day, settings) gives the date of another day.

hijri.month_name(today.month, "fr") names the month in Arabic, English, French, German or Turkish, and in English for the other languages. hijri.upcoming_events() gives the next day of the Islamic new year, Ashura, Ramadan, Eid al-Fitr, Arafah and Eid al-Adha, an estimate after today, and hijri.event_name(event, "fr") names them in the same languages:

events = hijri.upcoming_events(settings, "Europe/Paris")
ramadan = next(event for event in events if event.event == "ramadan")
print(ramadan.date, ramadan.days_until)  # 2027-02-07 111

Errors

Every error inherits from MawaqitError:

Error When
AuthenticationError The token is wrong (HTTP 401)
PermissionDeniedError The account used all its API calls, or the request was blocked (HTTP 403)
NotFoundError No mosque has this UUID (HTTP 404)
RateLimitError, BadRequestError, InternalServerError HTTP 429, 400, 500 and above
APIStatusError Any other error status, and base class of the ones above
APIConnectionError, APITimeoutError MAWAQIT could not be reached, or did not answer in time
APIResponseValidationError The response does not match the expected model

APIError, their base class, has the failed request and the response body. APIStatusError adds the response and its status_code.

from mawaqit import AuthenticationError, MawaqitError

try:
    prayer_times = await client.mosques.prayer_times(uuid)
except AuthenticationError:
    ...  # Ask for a new token.
except MawaqitError as err:
    print(err)  # Invalid token. (HTTP 401)

Retries and timeouts

Network errors, timeouts and HTTP 408, 429, 500, 502, 503 and 504 are retried twice, after about 0.5 then 1 second, or after the delay of Retry-After when it is one minute or less. Requests time out after 30 seconds.

client = AsyncMawaqitClient(token="...", max_retries=5, timeout=10)
fast = client.with_options(max_retries=0)

Logging

Responses are logged at the DEBUG level of the mawaqit logger, and retries at the INFO level. The token is never logged.

Home Assistant

  • Pass the HTTPX client of Home Assistant to share its connection pool. It stays open when the MAWAQIT client is closed:

    client = AsyncMawaqitClient(token=token, http_client=get_async_client(hass))
    
  • Pass a tzinfo rather than a name to hijri.today(), and as timezone= to the functions of mawaqit.prayer_times, to avoid loading a time zone in the event loop: hijri.today(settings, dt_util.get_time_zone(name)).

Versioning

This library follows Semantic Versioning. See the changelog, with the migration guide from 1.x.

Contributing

See CONTRIBUTING.md.

License

Apache 2.0. The license covers the code of this library, not access to the MAWAQIT API, which requires an authorization from MAWAQIT. Questions: support@mawaqit.net.

Metadata

Release files for mawaqit 2.6.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 mawaqit 2.6.0
File Size Uploaded Provenance Actions
mawaqit-2.6.0.tar.gz 186.2 kB With provenance Details for mawaqit-2.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 239.9 kB

Release files / mawaqit-2.6.0.tar.gz

Download URL mawaqit-2.6.0.tar.gz
Size 186.2 kB
Tags Source
SHA-256 checksum
How to use checksums
89cde1da3c9d9d15241adc43df589dc5f65e67d4afa261330a8ff1741a97e0c6
BLAKE2b-256 checksum
How to use checksums
2a689d9b991e9a23282a494272bec6abd52f7217f43881e1bb153ac4015bbcd7
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 Nov 14, 2026.

Transparency log

Release files / mawaqit-2.6.0-py3-none-any.whl

Download URL mawaqit-2.6.0-py3-none-any.whl
Size 53.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ae73165e08770172a02fed83f3b620b0765b8f3093494b3f91f2c9abb8eb2df
BLAKE2b-256 checksum
How to use checksums
ee7e86d6a262a41e641ee66ee9006a26db2ba91236db8e0f92290a62f5f93fb5
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 Nov 14, 2026.

Transparency log

Security for mawaqit 2.6.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mawaqit-2.6.0.tar.gz

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 Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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