Last month, a friend texted me: "Hey, there's an asteroid heading toward Earth today — should I worry?"
Instead of Googling, I wrote 3 lines of Python. Turns out NASA gives you completely free access to their asteroid tracking database. No API key signup, no rate limits worth worrying about, no paywall.
Here are 5 NASA APIs every developer should know — with working code.
1. Astronomy Picture of the Day (APOD)
NASA has published a stunning space photo every single day since June 16, 1995. That's 11,000+ images — all accessible via API.
import requests
response = requests.get("https://api.nasa.gov/planetary/apod",
params={"api_key": "DEMO_KEY"})
data = response.json()
print(f"Today: {data['title']}")
print(f"Image: {data.get('hdurl', data['url'])}")
print(f"Explanation: {data['explanation'][:200]}...")
Use case: Build a daily Slack bot that posts space photos. Or create a "This Day in Space" calendar.
2. Near-Earth Object (NEO) Tracker
This is the asteroid API. It tracks every object that comes close to Earth.
import requests
from datetime import date
today = date.today().isoformat()
response = requests.get("https://api.nasa.gov/neo/rest/v1/feed",
params={"start_date": today, "end_date": today, "api_key": "DEMO_KEY"})
data = response.json()
for neo in data["near_earth_objects"][today]:
name = neo["name"]
hazardous = neo["is_potentially_hazardous_asteroid"]
speed = neo["close_approach_data"][0]["relative_velocity"]["kilometers_per_hour"]
distance = neo["close_approach_data"][0]["miss_distance"]["kilometers"]
emoji = "Warning" if hazardous else "Safe"
print(f"{emoji} {name}: {float(speed):,.0f} km/h, {float(distance):,.0f} km away")
Today there are 10 asteroids approaching Earth. Most are harmless. But the API flags "potentially hazardous" ones automatically.
Use case: Asteroid alert dashboard. Science education app. Or just impress people at parties.
3. Mars Rover Photos
Curiosity and Perseverance are still taking photos on Mars right now. Every photo is free via API.
import requests
response = requests.get(
"https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/latest_photos",
params={"api_key": "DEMO_KEY"})
photos = response.json()["latest_photos"][:5]
for photo in photos:
cam = photo['camera']['full_name']
print(f"Camera: {cam}, Date: {photo['earth_date']}")
print(f" URL: {photo['img_src']}")
Use case: Mars photo gallery. Compare rover positions over time. Train CV models on alien terrain.
4. Earth Imagery (Landsat/Sentinel)
Get satellite photos of any location on Earth by latitude/longitude.
import requests
response = requests.get("https://api.nasa.gov/planetary/earth/imagery",
params={"lat": 48.8566, "lon": 2.3522, "dim": 0.1, "api_key": "DEMO_KEY"})
if response.status_code == 200:
with open("paris_from_space.png", "wb") as f:
f.write(response.content)
print("Saved satellite image of Paris")
Use case: Environmental monitoring. Urban growth analysis. Before/after disaster imagery.
5. DONKI — Space Weather
Track solar flares, geomagnetic storms, and coronal mass ejections.
import requests
response = requests.get("https://api.nasa.gov/DONKI/FLR",
params={"startDate": "2026-03-01", "endDate": "2026-03-25", "api_key": "DEMO_KEY"})
flares = response.json()
print(f"Solar flares in March 2026: {len(flares)}")
for flare in flares[:3]:
print(f" Class: {flare.get('classType', '?')}, Peak: {flare.get('peakTime', '?')}")
Use case: Aurora prediction. Satellite operators need this for orbit planning. Radio operators track it for signal interference.
Getting a Real API Key (Free, 30 Seconds)
DEMO_KEY works but has low rate limits (30 req/hour). Get a real key:
- Go to api.nasa.gov
- Enter your email
- Get your key instantly — no credit card, no OAuth, no approval process
Real key: 1,000 requests per hour. Enough for any project.
Why This Matters
Most developers pay for data APIs. NASA gives you:
- Asteroid tracking in real-time
- Mars photos from active rovers
- Satellite imagery of any place on Earth
- Space weather data
- 11,000+ astronomy photos with explanations
All free. All JSON. All no-auth (with DEMO_KEY) or instant-key.
What would you build with NASA data? I'm thinking of combining the asteroid API with a Telegram bot that alerts when something big comes close. Drop your ideas in the comments.
I write about free APIs that most developers don't know about. Follow for more.
My other API guides:
Need a custom data pipeline or API integration? Hire me
Also: Neon Free Postgres | Vercel Free API | Hetzner 4x More Server
NEW: I Ran an AI Agent for 16 Days — What Actually Works
You might also like:
- arXiv API: Search 2M+ Research Papers Programmatically
- Have I Been Pwned Has a Free API
- 150+ Free APIs Without an API Key
Need web scraping or data extraction? I've built 77+ production scrapers. Email spinov001@gmail.com — quote in 2 hours. Or try my ready-made Apify actors — no code needed.
Top comments (0)