API Directory › 🚀 Science & Space › Sunrise-Sunset
No authHTTPSCORS

Sunrise-Sunset API

Free, no-key sunrise and sunset times for any latitude/longitude.

Auth
No auth needed
HTTPS
Yes
CORS
Yes
Open Sunrise-Sunset docs ↗

What it does

The Sunrise-Sunset API returns solar event times for a given latitude, longitude and date: sunrise, sunset, solar noon, day length, and the start/end of civil, nautical and astronomical twilight.

Base URL

https://api.sunrise-sunset.org/json

Authentication

None. Pass lat, lng, an optional date (YYYY-MM-DD or today/tomorrow), and formatted=0 to get ISO 8601 UTC timestamps instead of pretty strings.

Code examples

curl
curl -s "https://api.sunrise-sunset.org/json?lat=36.72&lng=-4.42&date=2026-06-21&formatted=0"
Python
import requests

r = requests.get("https://api.sunrise-sunset.org/json", params={
    "lat": 51.48, "lng": 0.0, "formatted": 0}, timeout=10)
res = r.json()["results"]
print("sunrise (UTC):", res["sunrise"])
print("day length (s):", res["day_length"])

Rate limits & quotas

No published hard limit, but the maintainers ask you to stay under roughly 1 request per second. Results are purely astronomical and deterministic, so cache them — a location’s sun times for a given date never change.

Key response fields

results.sunrise / sunsetEvent times (UTC when formatted=0)
results.solar_noonSun at its highest
results.day_lengthSeconds of daylight (integer when formatted=0)
results.civil_twilight_begin / endAlso nautical and astronomical variants
statusOK, INVALID_REQUEST, INVALID_DATE…

Common errors

status INVALID_REQUESTMissing or non-numeric lat/lng.
status INVALID_DATEUnparseable date value.
status UNKNOWN_ERRORServer-side issue — retry.
(local time confusion)Times are UTC with formatted=0; convert to the location’s zone yourself.

When to use it (and alternatives)

Ideal for ‘golden hour’ features, solar-aware theming (dark mode at dusk), photography planners and agriculture apps. Pair with a timezone source like TimeZoneDB to show local times, or with Open-Meteo which also returns sunrise/sunset in its daily block.

FAQ

Why are the times a few hours off?

With formatted=0 the API returns UTC. Convert to the location’s local timezone (accounting for DST) for display. formatted=1 returns 12-hour strings, also in UTC.

Does it handle polar day/night?

For high latitudes where the sun does not rise or set, some fields come back empty or as 1970-01-01 sentinels. Guard for that above ~66° latitude near the solstices.

Is the data accurate enough for navigation?

It is good to within a minute for typical use, but it is a general-purpose service. Safety-critical navigation should use an almanac-grade library.

New to APIs?

Short guides for working with this API — and any other.

🛠️ Handy LarzOS tools

Free tools to help you work with this API.

JSON Formatter

Related Science & Space APIs

← Back

More Science & Space APIs · All 196 APIs