Skip to content

Sun

What this does

Tells you when the sun rises and sets, how many hours of daylight you get, and whether it is currently day or night at a UK location. Use a postcode for convenience or latitude and longitude for precision. You can also ask for a specific date and time.

Who it is for

  • Runners and cyclists planning routes before dark
  • Facilities teams managing outdoor lighting
  • Travel and hospitality apps showing “sunset tonight”
  • Schools and clubs scheduling pitch time

Try it

Default: Edinburgh city centre, today.

https://fetch.li/v1/sun?postcode=EH11AA

Other examples:

https://fetch.li/v1/sun?lat=51.5074&lon=-0.1278
https://fetch.li/v1/sun?postcode=CF101AA&at=2026-06-21T12:00:00Z

HTTP example

GET /v1/sun?postcode=EH11AA HTTP/1.1
Host: fetch.li
Accept: application/json

curl

curl -sS "https://fetch.li/v1/sun?postcode=EH11AA"

JavaScript fetch

const response = await fetch(
  "https://fetch.li/v1/sun?postcode=EH11AA"
);
const sun = await response.json();
console.log(`Sunrise ${sun.sunrise}, sunset ${sun.sunset}`);

Python requests

import requests

response = requests.get(
    "https://fetch.li/v1/sun",
    params={"postcode": "EH11AA"},
)
response.raise_for_status()
sun = response.json()
print(sun["sunrise"], sun["sunset"], sun["daylight_hours"])

Example JSON response

{
  "sunrise": "05:48",
  "sunset": "20:31",
  "solar_noon": "13:09",
  "daylight_hours": 14.72,
  "is_daylight": true,
  "location": {
    "postcode": "EH1 1AA",
    "lat": 55.9533,
    "lon": -3.1883,
    "label": "Edinburgh"
  },
  "at": "2026-08-25T12:00:00.000Z",
  "date_local": "2026-08-25",
  "timezone": "Europe/London"
}

Parameters

Parameter Required Type Description
postcode One of postcode or lat/lon string UK postcode
lat With lon if no postcode number Latitude (decimal degrees)
lon With lat if no postcode number Longitude (decimal degrees)
at No string (ISO 8601) Instant for calculation (UTC). Defaults to now

Provide either postcode or both lat and lon.

Errors that can happen

HTTP error.code When
400 invalid_body Missing location or invalid at
404 not_found Postcode not recognised
429 rate_limited Demo limit exceeded
500 internal Unexpected server error

Demo

GET endpoints work without an API key on the public demo tier (60 calls per hour per IP). POST /v1/vibe/classify needs a key.