CLI Usage
CLI Usage
Section titled “CLI Usage”Al-Falak includes a command-line interface for quick terminal output. It has seven explicit subcommands:
al-falak <subcommand> [options] [--json] prayer Print prayer times. qibla Print Qibla direction. sunnah Print Sunnah night markers. hijri Convert a Gregorian date to a Hijri date (and back). moon-sighting Print crescent visibility scores. astro Print lunar position and Delta-T. cities List the frozen --city lookup table.Every subcommand accepts --json to emit the same keys as one compact
JSON object (in the same key order) instead of key=value lines.
Datetimes print as ISO-8601 with offset (UTC by default, or --timezone
where supported). Floats print with full precision in text (nan
lowercase) and as null in JSON — except qibla, which prints
direction to 6 decimals and distance_km to 3 in text (--json
carries the raw floats); booleans print lowercase in text and
as JSON booleans.
Bare invocation was removed
Section titled “Bare invocation was removed”Running al-falak without a subcommand exits with code 2. The fix is
one word — insert prayer:
# Before (no longer works)python -m alfalak --latitude 35.7750 --longitude -78.6336
# Afterpython -m alfalak prayer --latitude 35.7750 --longitude -78.6336usage: al-falak [-h] <subcommand> ...al-falak: error: a subcommand is required as the first argument (did you mean 'prayer'? try: al-falak prayer --latitude 35.7750 --longitude -78.6336)Pasting an old command with flags prints the same hint and exits with code 2 — flags before the subcommand are not parsed as options, so the fix is still the same one word:
usage: al-falak [-h] <subcommand> ...al-falak: error: a subcommand is required as the first argument (did you mean 'prayer'? try: al-falak prayer --latitude 35.7750 --longitude -78.6336)Exit codes follow the argparse convention: 0 on success, 2 on
anything user-fixable (bad flags, out-of-range coordinates/angles,
unknown timezones, polar day/night, moon-sighting evenings with no
sunset). Warnings never fail: an out-of-range astro delta-t year
prints a UserWarning to stderr but the finite value still prints with
exit 0 (an absurd year whose polynomial overflows to non-finite exits 2).
prayer
Section titled “prayer”python -m alfalak prayer --latitude 35.7750 --longitude -78.6336 --date 2015-07-12 --method NORTH_AMERICAOutput (one name=ISO-8601 line per marker, in chronological order):
imsak=2015-07-12T08:32:00+00:00fajr=2015-07-12T08:42:00+00:00sunrise=2015-07-12T10:08:00+00:00syuruk=2015-07-12T10:08:00+00:00ishraq=2015-07-12T10:23:00+00:00dhuha=2015-07-12T10:36:00+00:00dhuhr=2015-07-12T17:21:00+00:00asr=2015-07-12T21:09:00+00:00maghrib=2015-07-13T00:32:00+00:00isha=2015-07-13T01:57:00+00:00syuruk is sunrise under its MY/SG name, so it always equals sunrise.
imsak defaults to Fajr − 10 minutes; ishraq/dhuha default to
sunrise + 15/+ 28 minutes (see Calculation Methods).
Script consumers note: output is 10 lines (
imsakthroughisha, includingsyuruk, which always equalssunrise). Parse byname=key, not by line position.
Options
Section titled “Options”| Option | Required | Default | Description |
|---|---|---|---|
--latitude / --lat |
Yes, unless --city |
— | Latitude (-90 to 90) |
--longitude / --lon |
Yes, unless --city |
— | Longitude (-180 to 180) |
--city |
Yes, unless lat/lon | — | City as Name,CC (e.g. --city "Kuala Lumpur,MY"; exclusive with lat/lon; see cities) |
--date |
No | Today (UTC) | Calendar date as YYYY-MM-DD |
--method |
No | MUSLIM_WORLD_LEAGUE | Calculation method (see below) |
--madhab |
No | SHAFI | SHAFI or HANAFI |
--high-latitude-rule |
No | MIDDLE_OF_THE_NIGHT | MIDDLE_OF_THE_NIGHT, SEVENTH_OF_THE_NIGHT, or TWILIGHT_ANGLE |
--polar-rule |
No | NEAREST_LATITUDE | NONE, NEAREST_LATITUDE, NEAREST_DAY, or MAKKAH |
--fajr-angle |
No | From method | Override the method’s Fajr angle |
--isha-angle |
No | From method | Override the method’s Isha angle |
--isha-interval |
No | From method | Override the method’s Isha interval (minutes) |
--imsak-offset |
No | 10 |
Minutes before Fajr for Imsak |
--ishraq-offset |
No | 15 |
Minutes after sunrise for Ishraq |
--dhuha-offset |
No | 28 |
Minutes after sunrise for start of Dhuha window |
--elevation |
No | 0.0 |
Observer eye height in metres (dip correction) |
--ramadan |
No | Off | Umm al-Qura Ramadan mode (120 min Isha total; preset only) |
--timezone |
No | UTC | IANA timezone name for display (e.g. Asia/Kuala_Lumpur) |
--adjust NAME=MIN |
No | — | Repeatable per-prayer minute offset; NAME in imsak,fajr,sunrise,dhuhr,asr,maghrib,isha,ishraq,dhuha (no syuruk slot by design — sunrise flows through). Negatives need the = form: --adjust isha=-1 (a leading + is also accepted, e.g. --adjust fajr=+2); magnitude must be ≤ 1000000 minutes |
--json |
No | Off | Emit one compact JSON object instead of key=value lines |
Explicit --fajr-angle/--isha-angle/--isha-interval override the
--method preset exactly like CalculationParameters(method=...) then
attribute assignment.
--city "Name,CC" (e.g. --city "Kuala Lumpur,MY") is exclusive with
--latitude/--longitude; provide one or the other. Bare --city
defaults the display timezone to the city’s IANA zone (explicit
--timezone wins, else UTC). The table is frozen at 300 entries —
see cities. Canonical spelling is Makkah,SA; Mecca,SA is
intentionally unknown.
Available methods
Section titled “Available methods”MUSLIM_WORLD_LEAGUENONENORTH_AMERICAEGYPTIANKARACHIUMM_AL_QURADUBAIMOON_SIGHTING_COMMITTEEKUWAITQATARSINGAPOREUOIFJAKIMpython -m alfalak qibla --latitude 35.7750 --longitude -78.6336 --method ellipsoidaldirection=55.739247distance_km=10961.846method=ellipsoidalText prints the direction to 6 decimals and the distance to 3;
--json carries the raw floats. With --declination, a fourth
magnetic= line (compass heading) is added.
Options
Section titled “Options”| Option | Required | Default | Description |
|---|---|---|---|
--latitude / --lat |
Yes, unless --city |
— | Latitude (-90 to 90) |
--longitude / --lon |
Yes, unless --city |
— | Longitude (-180 to 180) |
--city |
Yes, unless lat/lon | — | City as Name,CC (exclusive with lat/lon; supplies coords only, no timezone) |
--method |
No | spherical |
Earth model: spherical or ellipsoidal (WGS84 geodesic) |
--declination |
No | — | Local magnetic declination in degrees, positive east (negative west); also prints magnetic= |
--json |
No | Off | Emit one compact JSON object instead of key=value lines |
See Qibla Direction for the spherical/ellipsoidal error budget and the declination sign convention.
sunnah
Section titled “sunnah”python -m alfalak sunnah --latitude 35.7750 --longitude -78.6336 --date 2015-07-12 --method NORTH_AMERICAmiddle_of_the_night=2015-07-13T04:38:00+00:00first_third_of_the_night=2015-07-13T03:16:00+00:00last_third_of_the_night=2015-07-13T05:59:00+00:00tahajjud_start=2015-07-13T05:59:00+00:00tahajjud_end=2015-07-13T08:43:00+00:00With --fraction F (in the open interval 0–1), the block collapses to a
single line:
python -m alfalak sunnah --latitude 35.7750 --longitude -78.6336 --date 2015-07-12 --method NORTH_AMERICA --fraction 0.5night_fraction=2015-07-13T04:38:00+00:00Options
Section titled “Options”sunnah accepts all prayer location and parameter flags
(--latitude/--longitude, --city, --date, --method, --madhab,
--high-latitude-rule, --polar-rule, --fajr-angle, --isha-angle,
--isha-interval, --imsak-offset, --ishraq-offset, --dhuha-offset,
--elevation, --ramadan, --timezone, --adjust), plus:
| Option | Required | Default | Description |
|---|---|---|---|
--fraction |
No | — | Night fraction in (0, 1); prints a single night_fraction= line |
--start |
No | Maghrib | Custom night-start anchor as an ISO datetime with timezone offset (requires --fraction) |
--end |
No | Next-day Fajr | Custom night-end anchor as an ISO datetime with timezone offset (requires --fraction) |
--json |
No | Off | Emit one compact JSON object instead of key=value lines |
--start/--end must be timezone-aware (2025-03-01T19:00:00+08:00);
naive values exit with code 2, as does any --start/--end without
--fraction. Bare --city defaults the display timezone like prayer
(explicit --timezone wins). See Sunnah Times for the
Maghrib-to-next-day-Fajr night definition and anchor alternatives.
Forward conversion (unchanged):
python -m alfalak hijri --date 2025-03-01 --calendar tabularhijri=1446-09-01calendar=tabularReverse conversion (Hijri → Gregorian):
python -m alfalak hijri --reverse 1446-09-01 --calendar tabulargregorian=2025-03-01calendar=tabularMonth length:
python -m alfalak hijri --month-length 1446-09 --calendar tabulardays=30calendar=tabularOptions
Section titled “Options”| Option | Required | Default | Description |
|---|---|---|---|
--date |
No | Today (UTC) | Gregorian date as YYYY-MM-DD (forward mode) |
--calendar |
Yes | — | Hijri calendar rule: tabular, uqu, or mabims |
--country |
With mabims only |
— | MABIMS country: MY, ID, BN, SG (case-insensitive; required with --calendar mabims, rejected otherwise) |
--adjustment-days |
No | 0 |
Tabular day shift in [-2, 2] (only with --calendar tabular) |
--sunset-transition |
No | Off | Roll the Hijri day over at Maghrib (requires --city or --lat, --lon, --time) |
--city |
With --sunset-transition |
— | City as Name,CC for sunset rollover (exclusive with --lat/--lon; supplies coords only, never a timezone) |
--lat / --lon |
With --sunset-transition |
— | Observer coordinates for sunset rollover (rejected without it) |
--time |
With --sunset-transition |
— | Wall-clock time as HH:MM[:SS] on --date; naive, treated as UTC (rejected without it; --city does not change this) |
--offsets |
No | — | JSON offset file ({"YYYY-MM": shift}) applied last (forward mode only) |
--reverse |
No | — | Hijri date as YYYY-MM-DD; convert back to a Gregorian date (mutually exclusive with --date/--sunset-transition/--offsets; --adjustment-days allowed with --calendar tabular) |
--month-length |
No | — | Hijri year-month as YYYY-MM; print the month length (29 or 30; mutually exclusive with --date/--sunset-transition/--offsets/--adjustment-days) |
--json |
No | Off | Emit one compact JSON object instead of key=value lines |
Per-country conversion prints a suffixed label:
python -m alfalak hijri --date 2025-03-02 --calendar mabims --country MYhijri=1446-09-01calendar=mabims-MYSunset rollover switches the Hijri day at Maghrib (default prayer
parameters); --offsets applies official-correction shifts after the
rule. --date/--time are naive wall-clock values treated as UTC —
a local wall-clock time misplaces sunset rollover by the UTC offset
(--city supplies coordinates only; hijri --time stays UTC).
The
uqucalendar (1423H month-start rule at Makkah) is not theUMM_AL_QURAprayer preset.tabularis arithmetic and routinely differs from observed months by 1–2 days — never present it as an observed date. See Hijri Converter.
moon-sighting
Section titled “moon-sighting”python -m alfalak moon-sighting --latitude 3.1390 --longitude 101.6869 --date 2025-02-28arcl_deg=6.173972051753964arcv_geo_deg=6.088018222865059arcv_topo_deg=5.086970505414731sun_alt_deg=-0.8325033650264293moon_alt_topo_deg=4.254467140388302daz_deg=1.0278791375318406width_arcmin=0.09531389154651401illumination=0.002900038687049744lag_hours=0.4120943493906335moon_age_days=0.4166666666666667moon_age_at_moonset_days=0.4338372645579431used_delta_t_s=74.56305038786272sunset_jd_utc=2460734.977337402yallop_q=-0.5153011137332268odeh_v=-1.4820588547825952yallop_zone=Fodeh_class=Dneo_mabims=falsemabims_1992=trueGeometry first (elongation, arcs of vision, altitudes, width,
illumination, lag, moon ages, delta-T used, sunset instant), then the
three scores: Yallop zone (F here — not visible), Odeh class (D),
and the two MABIMS booleans. In JSON, non-finite floats (e.g. NaN
lag when no moonset occurs) become null.
Options
Section titled “Options”| Option | Required | Default | Description |
|---|---|---|---|
--latitude / --lat |
Yes, unless --city |
— | Latitude (-90 to 90) |
--longitude / --lon |
Yes, unless --city |
— | Longitude (-180 to 180) |
--city |
Yes, unless lat/lon | — | City as Name,CC (exclusive with lat/lon; supplies coords only) |
--date |
Yes | — | Crescent evening as YYYY-MM-DD (no default — an explicit evening is required) |
--delta-t-override |
No | Built-in polynomial | Delta-T override in seconds for the TT conversion |
--json |
No | Off | Emit one compact JSON object instead of key=value lines |
Evenings with no sunset (polar day/night) exit with code 2. See
Moon Sighting for how to read the scores — check
lag_hours first, then the criteria, and only trust the 1992 age
branch after conjunction.
cities
Section titled “cities”python -m alfalak cities --country MYcity=Kuala Lumpur,MYcountry=MYlatitude=3.1390longitude=101.6869timezone=Asia/Kuala_LumpurOne 5-line block per city, sorted by (country, name) in byte order,
blocks separated by one blank line (no trailing blank). --json emits
one array of the same objects. --country filters case-insensitively
(my == MY); a well-formed but unmatched --country is empty
success (no text lines / [], exit 0); a malformed --country exits 2.
Two low-level lookups behind one nested subcommand:
python -m alfalak astro delta-t --year 2025.5delta_t=74.76958225python -m alfalak astro lunar-position --julian-day 2460000.5longitude=38.63857432412311latitude=0.24775270051666204distance_km=381923.9281840365right_ascension=36.175451124156034declination=14.615404753403455Options
Section titled “Options”| Subcommand | Option | Required | Default | Description |
|---|---|---|---|---|
lunar-position |
--julian-day |
Yes | — | Julian Day in Terrestrial Time (e.g. 2460000.5) |
lunar-position |
--json |
No | Off | Emit one compact JSON object instead of key=value lines |
delta-t |
--year |
Yes | — | Decimal year (e.g. 2025.5) |
delta-t |
--override |
No | — | Delta-T override in seconds (e.g. an IERS observed value) |
delta-t |
--json |
No | Off | Emit one compact JSON object instead of key=value lines |
Years outside 2005–2050 emit a UserWarning to stderr and
extrapolate — the finite value still prints with exit 0 (an absurd year
whose polynomial overflows to non-finite exits 2). See
API Reference for LunarCoordinates and delta_t.
Error handling
Section titled “Error handling”All subcommands exit with code 2 for invalid input:
$ python -m alfalak prayer --latitude 35 --longitude -78 --method BOGUSal-falak prayer: error: argument --method: invalid choice: 'BOGUS' (choose from ...)Unknown methods, bad dates/times, --latitude/--longitude/--city
(use --lat/--lon or --city with hijri --sunset-transition),
unknown --city (try cities --country CC) vs malformed --city
(expected NAME,CC), gate misuse (missing
--country with mabims, --country without it, --adjustment-days
outside tabular or with hijri --month-length, --time/--lat/--lon without
--sunset-transition, --start/--end without --fraction,
--reverse/--month-length clashes, unreadable --offsets files, out-of-range
coordinates, absurd --adjust magnitudes, pre-floor dates, naive --start/--end anchors), and
polar day/night all exit with code 2 via an argparse error.
See also
Section titled “See also”- Getting Started — Python API usage
- Calculation Methods — method details
- Qibla Direction — Qibla models and accuracy budget
- Sunnah Times — night divisions and anchors
- Hijri Converter — Gregorian↔Hijri conversion rules
- Moon Sighting — crescent geometry and visibility criteria
- API Reference — full API documentation