nasa
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
Install
Section titled “Install”go get github.com/peteretelej/nasaAPI Key
Section titled “API Key”Get 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.
Quick Start
Section titled “Quick Start”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 Coverage
Section titled “API Coverage”| 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 |
Rate Limiting
Section titled “Rate Limiting”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 Daynasa apod -date 2024-01-01 # APOD for a specific datenasa neo feed # near-Earth objects for todaynasa donki cme # coronal mass ejectionsnasa images search "apollo 11" # search NASA image librarynasa ssd cad # close approach dataMCP Server
Section titled “MCP Server”go 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.
Documentation
Section titled “Documentation”Full documentation at peteretelej.github.io/nasa.
Examples
Section titled “Examples”Runnable programs covering every API are in examples/. Each is a single main.go with no external dependencies beyond the SDK.
Daily Briefing
Section titled “Daily Briefing”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, MarylandAPOD Gallery
Section titled “APOD Gallery”Fetches today’s Astronomy Picture of the Day plus a recent gallery.
go run ./examples/apod-galleryNEO Watch
Section titled “NEO Watch”Tracks near-Earth objects for the current week, with details on close approaches and potentially hazardous asteroids.
go run ./examples/neo-watchSpace Weather
Section titled “Space Weather”Queries DONKI for recent coronal mass ejections, solar flares, geomagnetic storms, and other space weather events.
go run ./examples/space-weatherImage Search
Section titled “Image Search”Searches the NASA Image and Video Library for media, with metadata and download links.
go run ./examples/image-searchClose Approaches
Section titled “Close Approaches”Queries SSD/CNEOS for recent fireballs, upcoming close approaches, and small body lookups.
go run ./examples/close-approachesEarth Events
Section titled “Earth Events”Lists active natural events from EONET - wildfires, storms, volcanic activity, and more.
go run ./examples/earth-eventsContributing
Section titled “Contributing”See CONTRIBUTING.md.