A Python CLI tool to track the moon's position in the sky. Get altitude, azimuth, and distance from any location on Earth.
This tutorial requires an APIVerve API key. Sign up free - no credit card required.
- Track moon position from any coordinates
- Altitude above/below horizon
- Azimuth with compass direction
- Distance to the moon
- Support for custom date/time
- Pre-configured example locations
- Interactive CLI interface
-
Clone this repository
git clone https://github.com/apiverve/moon-tracker-python-tutorial.git cd moon-tracker-python-tutorial -
Install dependencies
pip install -r requirements.txt
-
Set your API key
export APIVERVE_API_KEY=your-api-key-here -
Run the tracker
python tracker.py
moon-tracker-python-tutorial/
├── tracker.py # Main Python script
├── requirements.txt # Python dependencies
├── screenshot.jpg # Preview image
├── LICENSE # MIT license
├── .gitignore # Git ignore rules
└── README.md # This file
- Select a location or enter coordinates
- Optionally specify date and time
- API calculates moon's position
- Display altitude, azimuth, and distance
response = requests.get('https://api.apiverve.com/v1/moonposition',
headers={'x-api-key': API_KEY},
params={
'lat': 37.7749,
'lon': -122.4194,
'date': '01-22-2026',
'time': '14:30'
}
)Endpoint: GET https://api.apiverve.com/v1/moonposition
Query Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
lat |
number | Yes | Latitude (-90 to 90) |
lon |
number | Yes | Longitude (-180 to 180) |
date |
string | No | Date (MM-DD-YYYY format) |
time |
string | No | Time (HH:MM format) |
Example Response:
{
"status": "ok",
"error": null,
"data": {
"date": "01-22-2026",
"time": "14:30",
"coordinates": {
"latitude": 37.7749,
"longitude": -122.4194
},
"moon": {
"altitude": -0.407908976399288,
"azimuth": 1.4720499058762104,
"distance": 404332.68340679689
}
}
}| Field | Description |
|---|---|
altitude |
Angle above/below horizon (radians). Positive = visible |
azimuth |
Compass direction (radians from north) |
distance |
Distance to moon in kilometers |
degrees = radians * (180 / 3.14159)| Location | Latitude | Longitude |
|---|---|---|
| San Francisco | 37.7749 | -122.4194 |
| New York | 40.7128 | -74.0060 |
| London | 51.5074 | -0.1278 |
| Tokyo | 35.6762 | 139.6503 |
- Add moon phase data
- Create visualization graph
- Add sunrise/sunset comparison
- Build web interface
- Track multiple celestial bodies
- Add notification for moonrise
Explore more APIs at APIVerve:
- Moon Phases - Current moon phase
- Sun Position - Track the sun
- Sunrise Sunset - Daily sun times
This tutorial works with the free APIVerve plan. Some APIs may have:
- Locked fields: Premium response fields return
nullon free plans - Ignored parameters: Some optional parameters require a paid plan
The API response includes a premium object when limitations apply. Upgrade anytime to unlock all features.
MIT - see LICENSE
- Get API Key - Sign up free
- APIVerve Marketplace - Browse 300+ APIs
- Moon Position API - API details