Free public REST API serving prayer times for 28 Libyan cities. No authentication required.
REST / JSONCORS EnabledPublic Read28 Cities
Overview
Access daily prayer times (Fajr, Sunrise, Dhuhr, Asr, Maghrib, Isha) for 28 Libyan cities. Some cities also include Imsak and Keroob (pre-sunset) times.
⚡
No API key needed. Simply append .json to any path for a JSON response. Works from any domain.
Key Features
366 days of prayer times per city (full year)
Times in HH:MM format (24-hour, Libya UTC+2)
Arabic and English city names in metadata
Optional Imsak / Keroob fields for supported cities
CORS enabled — works from any domain
Base URL
https://api.prayertimes.ly
All endpoints are relative to this base URL.
Endpoints
GET/metadata.json
Returns global metadata: version, last updated date, city count, and all city keys.
emsak and keroob fields are only present for cities where has_emsak / has_keroob is true.
GET/cities/{city}/days.json
Returns all prayer times for a city (366 days). Response is ~30-40 KB per city.
Parameter
Type
Description
{city}
string
City key (lowercase)
⚠
Large response. Use the single-day endpoint if you only need one day. Best for caching all data locally.
Available Cities
28 Libyan cities are available. Use the lowercase key in API paths:
aljaghbubAl Jaghbub
alkomsAl Khoms
almaragAl Marj
alzaweyaAzzawya
banywaleadBani Walid
bedaAl Bayda
benghaziBenghazi
benjuwadBin Jawad
breakaBrega
dernaDerna
ejdabyaAjdabiya
ekdamesGhadames
emsaedMusaid
hoonHun
jaloJalu
koufraAl Kufra
mawaMawa
mosrataMisrata
nalutNalut
ojalaAwjila
raslanofRas Lanuf
sabhaSabha
sertSirte
shahatShahhat
tobrekTobruk
tripoliTripoli
ubariUbari
zaleatenZliten
Response Format
Prayer Time Fields
Field
Format
Description
Required
fajer
HH:MM
Fajr (dawn prayer)
Yes
shorok
HH:MM
Sunrise
Yes
dohor
HH:MM
Dhuhr (noon prayer)
Yes
aser
HH:MM
Asr (afternoon prayer)
Yes
magrib
HH:MM
Maghrib (sunset prayer)
Yes
esha
HH:MM
Isha (night prayer)
Yes
emsak
HH:MM
Imsak (fasting start)
Optional*
keroob
HH:MM
Keroob (pre-sunset)
Optional*
*Check has_emsak / has_keroob in city metadata. Cities without: Benghazi, Mawa, Al Jaghbub, Al Khoms, Nalut.
Time Zone
All times are in Libya time (UTC+2). Libya does not observe daylight saving time.
Date Key Format
Day keys use DD-MM format (day-month), zero-padded. Examples: 01-01 (Jan 1), 31-12 (Dec 31), 29-02 (Feb 29).
Error Handling
Non-existent paths return an HTTP 404. Always verify the city key and date format before making requests.
Code Examples
Get Today's Prayer Times
# Get prayer times for Tripoli on April 4th
curl "https://api.prayertimes.ly/cities/tripoli/days/04-04.json"# Get city metadata
curl "https://api.prayertimes.ly/cities/tripoli/metadata.json"# List all cities
curl "https://api.prayertimes.ly/metadata.json"
const BASE = 'https://api.prayertimes.ly';
// Get today's prayer times for a cityasync functiongetPrayerTimes(city, date = new Date()) {
const dd = String(date.getDate()).padStart(2, '0');
const mm = String(date.getMonth() + 1).padStart(2, '0');
const res = awaitfetch(`${BASE}/cities/${city}/days/${dd}-${mm}.json`);
return res.json();
}
// Usageconst times = awaitgetPrayerTimes('tripoli');
console.log('Fajr:', times.fajer); // "05:25"
console.log('Maghrib:', times.magrib); // "19:32"// Get all citiesconst meta = awaitfetch(`${BASE}/metadata.json`).then(r => r.json());
console.log(meta.city_list); // ["aljaghbub", "alkoms", ...]
import requests
from datetime import datetime
BASE = "https://api.prayertimes.ly"defget_prayer_times(city: str, date: datetime = None) -> dict:
if date is None:
date = datetime.now()
key = date.strftime("%d-%m")
resp = requests.get(f"{BASE}/cities/{city}/days/{key}.json")
return resp.json()
# Usage
times = get_prayer_times("tripoli")
print(f"Fajr: {times['fajer']}") # Fajr: 05:25print(f"Maghrib: {times['magrib']}") # Maghrib: 19:32# Get all city names
meta = requests.get(f"{BASE}/metadata.json").json()
for city in meta["city_list"]:
info = requests.get(f"{BASE}/cities/{city}/metadata.json").json()
print(f"{info['name_en']} ({info['name_ar']})")
import Foundation
let base = "https://api.prayertimes.ly"structPrayerTimes: Codable {
let fajer, shorok, dohor, aser, magrib, esha: String
let emsak, keroob: String?
}
funcgetPrayerTimes(city: String, date: Date = Date()) async throws -> PrayerTimes {
let fmt = DateFormatter()
fmt.dateFormat = "dd-MM"let key = fmt.string(from: date)
let url = URL(string: "\(base)/cities/\(city)/days/\(key).json")!
let (data, _) = try await URLSession.shared.data(from: url)
return try JSONDecoder().decode(PrayerTimes.self, from: data)
}
// Usagelet times = try awaitgetPrayerTimes(city: "tripoli")
print("Fajr: \(times.fajer)")
import java.net.URL
import org.json.JSONObject
import java.text.SimpleDateFormat
import java.util.Date
val BASE = "https://api.prayertimes.ly"fungetPrayerTimes(city: String, date: Date = Date()): JSONObject {
val key = SimpleDateFormat("dd-MM").format(date)
val json = URL("$BASE/cities/$city/days/$key.json").readText()
return JSONObject(json)
}
// Usageval times = getPrayerTimes("tripoli")
println("Fajr: ${times.getString("fajer")}") // Fajr: 05:25
println("Maghrib: ${times.getString("magrib")}") // Maghrib: 19:32
import'dart:convert';
import'package:http/http.dart'as http;
const base = 'https://api.prayertimes.ly';
Future<Map<String, dynamic>> getPrayerTimes(String city, {DateTime? date}) async {
date ??= DateTime.now();
final key = '${date.day.toString().padLeft(2, "0")}-${date.month.toString().padLeft(2, "0")}';
final res = await http.get(Uri.parse('$base/cities/$city/days/$key.json'));
return jsonDecode(res.body);
}
// Usagefinal times = awaitgetPrayerTimes('tripoli');
print('Fajr: ${times["fajer"]}'); // Fajr: 05:25
print('Maghrib: ${times["magrib"]}'); // Maghrib: 19:32
Embeddable Widget
<!-- Embed prayer times in your website -->
<divid="prayer-widget"></div>
<script>
(async () => {
const city = 'tripoli';
const d = new Date();
const key = String(d.getDate()).padStart(2,'0') + '-' + String(d.getMonth()+1).padStart(2,'0');
const base = 'https://api.prayertimes.ly';
const [times, meta] = await Promise.all([
fetch(`${base}/cities/${city}/days/${key}.json`).then(r => r.json()),
fetch(`${base}/cities/${city}/metadata.json`).then(r => r.json()),
]);
const prayers = [
['Fajr', times.fajer], ['Dhuhr', times.dohor],
['Asr', times.aser], ['Maghrib', times.magrib],
['Isha', times.esha],
];
const el = document.getElementById('prayer-widget');
const h = document.createElement('h3');
h.textContent = meta.name_en + ' Prayer Times';
el.appendChild(h);
prayers.forEach(([n,t]) => {
const row = document.createElement('div');
row.textContent = n + ': ' + t;
el.appendChild(row);
});
})();
</script>
Try It Live
Enter a city key and date to fetch prayer times directly from the API.
GET /cities/{city}/days/{DD-MM}.json
Usage Notes
⚡
Best practice: Cache responses locally. Prayer times don't change during the day — a single fetch per city per day is sufficient. Use /days.json to fetch all days at once.
CORS
The API supports CORS. You can call it directly from browser JavaScript on any domain.
Caching
Responses include a Cache-Control: max-age=3600 header. Prayer data is static and updated yearly.