Skip to content

nasa

A Go client library for NASA’s open APIs, covering APOD, NeoWs, DONKI, the Image Library, SSD/CNEOS, and EONET.

Go Reference CI Go Report Card License: MIT Docs Demo

Query NASA’s public data APIs from Go - astronomy photos, near-Earth objects, space weather events, satellite imagery, and more. Responses are returned as typed Go structs with rate limiting handled automatically. A CLI and an MCP server are also included for terminal and AI assistant usage.

  • 6 NASA APIs - APOD, NeoWs, DONKI, NASA Image Library, SSD/CNEOS, EONET
  • Built-in rate limiting - automatic 429 retry with header-based dynamic adjustment
  • Typed responses - strongly typed Go structs, no raw JSON
  • Context-aware - supports cancellation and timeouts
  • CLI - access all APIs from the terminal
  • MCP server - expose NASA APIs as tools for AI assistants
Terminal window
go get github.com/peteretelej/nasa

Get a free API key at api.nasa.gov, then export it:

Terminal window
export NASA_API_KEY=your_key_here

Or specify it directly when creating the client:

client := nasa.NewClient(nasa.WithAPIKey("your_key_here"))

The SDK works without a key using NASA’s DEMO_KEY, but it is heavily rate-limited.

package main
import (
"context"
"fmt"
"log"
"github.com/peteretelej/nasa"
)
func main() {
client := nasa.NewClient()
apod, err := client.APOD.Today(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s: %s\n", apod.Title, apod.URL)
}
APIDescriptionService
APODAstronomy Picture of the Dayclient.APOD
NeoWsNear-Earth Object Web Serviceclient.NEO
DONKISpace Weather Database and Notification Systemclient.DONKI
NASA Image LibraryImage and video search across NASA mediaclient.Images
SSD/CNEOSClose approaches, fireballs, small bodiesclient.SSD
EONETEarth Observatory Natural Event Trackerclient.EONET

The client automatically respects NASA API rate limits. With a registered key, the default is 1000 requests/hour.

client := nasa.NewClient()
Terminal window
go install github.com/peteretelej/nasa/cmd/nasa@latest
Terminal window
nasa apod # today's Astronomy Picture of the Day
nasa apod -date 2024-01-01 # APOD for a specific date
nasa neo feed # near-Earth objects for today
nasa donki cme # coronal mass ejections
nasa images search "apollo 11" # search NASA image library
nasa ssd cad # close approach data
Terminal window
go install github.com/peteretelej/nasa/cmd/nasa-mcp@latest

Add to your MCP client config:

{
"mcpServers": {
"nasa": {
"command": "nasa-mcp",
"env": { "NASA_API_KEY": "your-key" }
}
}
}

The MCP server exposes 13 tools covering all 6 APIs. See the documentation for details.

Full documentation at peteretelej.github.io/nasa.

Runnable programs covering every API are in examples/. Each is a single main.go with no external dependencies beyond the SDK.

Combines all six APIs into one summary - APOD, near-Earth objects, space weather, and active Earth events.

Terminal window
go run ./examples/daily-briefing
=== Today's APOD ===
Title: Hello World
URL: https://apod.nasa.gov/apod/image/2604/art002e000192_1050.jpg
=== Near-Earth Objects This Week ===
105 objects tracked, 1 potentially hazardous
=== Solar Activity (7 days) ===
Coronal mass ejections: 43
Solar flares: 13
=== Active Earth Events ===
[Wildfires] rx-12_ 13_ 14 Prescribed Fire, Burnett, Wisconsin
[Wildfires] Rx Houston 3041 Prescribed Fire, Houston, Texas
[Severe Storms] Tropical Cyclone Indusa
[Wildfires] RX PCS Beauchamp North Prescribed Fire, Scott, Arkansas
[Wildfires] Julie Pond Wildfire, Dorchester, Maryland

Fetches today’s Astronomy Picture of the Day plus a recent gallery.

Terminal window
go run ./examples/apod-gallery

Tracks near-Earth objects for the current week, with details on close approaches and potentially hazardous asteroids.

Terminal window
go run ./examples/neo-watch

Queries DONKI for recent coronal mass ejections, solar flares, geomagnetic storms, and other space weather events.

Terminal window
go run ./examples/space-weather

Searches the NASA Image and Video Library for media, with metadata and download links.

Terminal window
go run ./examples/image-search

Queries SSD/CNEOS for recent fireballs, upcoming close approaches, and small body lookups.

Terminal window
go run ./examples/close-approaches

Lists active natural events from EONET - wildfires, storms, volcanic activity, and more.

Terminal window
go run ./examples/earth-events

See CONTRIBUTING.md.

MIT