DEV Community

Alex Spinov
Alex Spinov

Posted on

I Built a SpaceX Launch Tracker in 50 Lines of Python (No API Key Needed)

Last month my kid asked me: "When is the next SpaceX rocket launching?"

I checked 3 websites. Different dates. Different payload names. Confusing countdown timers.

So I did what any developer would do — I built my own tracker. 50 lines. No API key. Free forever.

The API Nobody Talks About

The SpaceX REST API is completely free, requires no authentication, and returns beautifully structured JSON about every launch since 2006.

No rate limits published (be reasonable). No signup. Just requests.get() and go.

The Code

import requests
from datetime import datetime

def get_next_launch():
    r = requests.get("https://api.spacexdata.com/v5/launches/next")
    launch = r.json()

    name = launch["name"]
    date = datetime.fromisoformat(launch["date_utc"].replace("Z", "+00:00"))
    days_until = (date - datetime.now(date.tzinfo)).days

    print(f"Next Launch: {name}")
    print(f"Date: {date.strftime("%B %d, %Y at %H:%M UTC")}")
    print(f"{days_until} days from now")
    return launch

def get_launch_stats():
    r = requests.get("https://api.spacexdata.com/v5/launches")
    launches = r.json()

    total = len(launches)
    successes = sum(1 for l in launches if l["success"] is True)
    failures = sum(1 for l in launches if l["success"] is False)

    print(f"SpaceX Launch History:")
    print(f"   Total launches: {total}")
    print(f"   Successes: {successes} ({successes/total*100:.1f}%)")
    print(f"   Failures: {failures}")
    return launches

def get_crew_missions():
    r = requests.get("https://api.spacexdata.com/v4/crew")
    crew = r.json()

    agencies = {}
    for member in crew:
        agency = member.get("agency", "Unknown")
        agencies[agency] = agencies.get(agency, 0) + 1

    print(f"Crew Members: {len(crew)}")
    for agency, count in sorted(agencies.items(), key=lambda x: -x[1])[:5]:
        print(f"   {agency}: {count}")

if __name__ == "__main__":
    get_next_launch()
    get_launch_stats()
    get_crew_missions()
Enter fullscreen mode Exit fullscreen mode

What You Get

Next Launch: Starlink Group 12-7
Date: April 02, 2026 at 14:30 UTC
8 days from now

SpaceX Launch History:
   Total launches: 267
   Successes: 261 (97.8%)
   Failures: 4

Crew Members: 30
   NASA: 18
   SpaceX: 4
   JAXA: 3
Enter fullscreen mode Exit fullscreen mode

5 Things I Learned

  1. SpaceX has a 97.8% success rate — I had no idea it was that high
  2. The API has data from 2006 — Falcon 1 first (failed) launch is in there
  3. You can track Starlink satellites/starlink endpoint with orbital data
  4. Crew data includes Wikipedia links — great for building info cards
  5. Rocket reuse data is available — how many times each booster has flown

Other Endpoints Worth Exploring

Endpoint What You Get
/v4/rockets Specs for every rocket (height, mass, thrust)
/v4/starlink 4,000+ satellite positions
/v4/landpads Landing pad locations and stats
/v5/launches/past Every historical launch
/v4/crew Astronaut profiles

Build Ideas

  • Launch notification bot — check /launches/next daily, send Telegram/Discord alert
  • Success rate dashboard — chart success rates by year
  • Starlink coverage map — plot satellite positions on a map
  • Rocket comparison tool — Falcon 9 vs Starship specs side by side

I maintain a collection of 25+ Python API clients for free APIs (weather, finance, space, news): github.com/spinov001-art

What free APIs do you use in your projects? Drop a comment — I am always looking for new ones to add to the collection.

Top comments (0)