Sunrise Sunset

Science API · Works globally · Solar position calculations · No authentication

TL;DR

This API returns precise sunrise and sunset times for any GPS location on Earth, based on astronomical calculations from the US Naval Observatory algorithms. Beyond just sunrise and sunset, it delivers civil twilight (dawn/dusk), nautical twilight, and astronomical twilight timestamps in UTC. The API takes a latitude and longitude, optionally a date (defaults to today), and returns all times in UTC standardized 12-hour format. No API key, no signup — just coordinates.

Quick start: https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400

No API key needed — just make a request!

How to Use This API

1. Get Today's Solar Times

For Málaga, Spain (lat=36.72, lng=-4.42):

https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400

2. Get Times for a Specific Date

Add the date parameter for any past or future date:

https://api.sunrise-sunset.org/json?lat=51.5074&lng=-0.1278&date=2026-12-25

3. JavaScript — Display London Golden Hour

fetch('https://api.sunrise-sunset.org/json?lat=51.5074&lng=-0.1278&date=today')
  .then(r => r.json())
  .then(d => {
    const res = d.results;
    console.log('Sunrise:', res.sunrise);
    console.log('Sunset:', res.sunset);
    console.log('Golden Hour AM:', res.civil_twilight_begin);
    console.log('Day length:', res.day_length, 'seconds');
  });

4. Python — Get Tomorrow's Data

import requests
from datetime import date, timedelta

tomorrow = date.today() + timedelta(days=1)
resp = requests.get('https://api.sunrise-sunset.org/json', params={
    'lat': 40.7128,
    'lng': -74.0060,
    'date': tomorrow.isoformat(),
    'formatted': 0
})
times = resp.json()['results']
print(f"NYC tomorrow sunrise: {times['sunrise']}")
print(f"NYC tomorrow sunset: {times['sunset']}")

API Details

API URL
https://api.sunrise-sunset.org/json
Documentation
sunrise-sunset.org/api
Category
Science
Authentication
Not Required
Geographic Coverage
Global — any GPS coordinate on Earth
Try it: https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400

Frequently Asked Questions

Do I need an API key?
Absolutely not. This is a free, open API with zero authentication required.
What exactly does the response include?
sunrise, sunset, solar_noon, day_length, civil_twilight_begin, civil_twilight_end, nautical_twilight_begin, nautical_twilight_end, astronomical_twilight_begin, and astronomical_twilight_end.
What timezone are the results in?
All times are in UTC by default. Add &formatted=0 to get ISO 8601 timestamps instead of 12-hour AM/PM strings.
Can I query dates in the past or future?
Yes, the date parameter accepts any date in YYYY-MM-DD format. It uses astronomical algorithms, not forecast data.
What is the difference between civil, nautical, and astronomical twilight?
Civil twilight (sun 0-6° below horizon) is general visibility; nautical twilight (6-12°) is maritime horizon visibility; astronomical twilight (12-18°) is when fainter stars become visible.
Is there a rate limit?
No documented rate limit. The service is lightweight and intended for reasonable personal and commercial use.

What You Can Build