A Go client library for NASA's open APIs, covering APOD, NeoWs, DONKI, the Image Library, SSD/CNEOS, and EONET.
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
go get github.com/peteretelej/nasaGet a free API key at api.nasa.gov, then export it:
export NASA_API_KEY=your_key_hereOr 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)
}| API | Description | Service |
|---|---|---|
| APOD | Astronomy Picture of the Day | client.APOD |
| NeoWs | Near-Earth Object Web Service | client.NEO |
| DONKI | Space Weather Database and Notification System | client.DONKI |
| NASA Image Library | Image and video search across NASA media | client.Images |
| SSD/CNEOS | Close approaches, fireballs, small bodies | client.SSD |
| EONET | Earth Observatory Natural Event Tracker | client.EONET |
The client automatically respects NASA API rate limits. With a registered key, the default is 1000 requests/hour.
client := nasa.NewClient()go install github.com/peteretelej/nasa/cmd/nasa@latestnasa 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 datago install github.com/peteretelej/nasa/cmd/nasa-mcp@latestAdd 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.
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.
go run ./examples/apod-galleryTracks near-Earth objects for the current week, with details on close approaches and potentially hazardous asteroids.
go run ./examples/neo-watchQueries DONKI for recent coronal mass ejections, solar flares, geomagnetic storms, and other space weather events.
go run ./examples/space-weatherSearches the NASA Image and Video Library for media, with metadata and download links.
go run ./examples/image-searchQueries SSD/CNEOS for recent fireballs, upcoming close approaches, and small body lookups.
go run ./examples/close-approachesLists active natural events from EONET - wildfires, storms, volcanic activity, and more.
go run ./examples/earth-eventsSee CONTRIBUTING.md.