Moon Tracker Template

  • Python
  • Flask

Where the moon is in the sky right now, from any place on Earth.

A Python and Flask app that tells you whether the moon is up. Pick a city, enter coordinates or use your location, and see if the moon is above or below the horizon and how high it is. On paid plans it adds the compass direction to look and the moon’s distance. Use it for a stargazing or photography planner, or from the command line.

The moon tracker app running

What it does

Up or down
Says plainly whether the moon is above the horizon, and how many degrees.
Any location
Cities to try, any latitude and longitude, or the visitor’s own location.
Which way to look
On paid plans, the compass direction and the moon’s distance in km and miles.
Keeps your key private
The page calls a server route that holds the key, checks the input and limits each visitor to 10 lookups a minute.
A web app and a CLI
python app.py runs the page and its route locally. The same lookups work from the terminal, sharing one small API helper.

How it works

The Flask route: it checks the coordinates and time, then calls Moon Position.

app.py
TIME = re.compile(r'^([01]\d|2[0-3]):[0-5]\d$')


def coordinate(name, limit):
    try:
        value = float(request.args.get(name, ''))
    except ValueError:
        return None
    return value if -limit <= value <= limit else None


@app.get('/api/moon')
def moon():
    """GET /api/moon?lat=40.71&lon=-74.01&time=21:30: where the moon is in the sky (time is UTC, today)."""
    lat, lon = coordinate('lat', 90), coordinate('lon', 180)
    if lat is None or lon is None:
        return fail('Enter a latitude from -90 to 90 and a longitude from -180 to 180.')
    params = {'lat': round(lat, 4), 'lon': round(lon, 4)}
    time = request.args.get('time', '').strip()
    if time:
        if not TIME.match(time):
            return fail('Use a 24-hour time, like 21:30.')
        params['time'] = time
    return jsonify(call_api('moonposition', params))

See the whole file on GitHub

Deploy it

  1. Get a free API key

    The free plan includes 200 credits a month, no card needed. Create your key.

  2. Deploy it

    Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for APIVERVE_API_KEY: paste your key there.

  3. Open your app

    Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.

Try the Moon Position API — the call this template makes

Request
GETapi.apiverve.com/v1/moonposition?lat=37.7749&lon=-122.4194
Query parameters
Verification
Format

No key required to try it. Get a key to use it in your app.

Example
{
  "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.6834067969
    }
  }
}

Build your own with Moon Position. Start with 200 free credits. One key unlocks all 300+ APIs.

Explore the catalog

300+ APIs on the same key and the same response shape.

Browse all APIs