Airport Distance Calculator Template
- Python
- Flask
The distance and flight time between any two airports, from their 3-letter codes.
A Python and Flask app that works out how far apart two airports are. Enter two airport codes, or pick a popular route, and get the distance in miles and kilometers and the flight time. On paid plans it adds the time difference, heading, both airports’ details and a CO₂ estimate. Use it on a travel or booking site, or from the command line.

What it does
- Distance and flight time
- Miles, kilometers and an estimated flight time for any pair of airports.
- Popular routes
- One-click routes like JFK to LAX, and a swap button to go the other way.
- More on paid plans
- Time difference, heading, international or domestic, and each airport’s name and city.
- 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 both codes and calls Airport Distance.
IATA = re.compile(r'^[A-Z]{3}$')
@app.get('/api/distance')
def distance():
"""GET /api/distance?from=JFK&to=LAX: the distance and flight details between two airports."""
origin = request.args.get('from', '').strip().upper()
dest = request.args.get('to', '').strip().upper()
if not IATA.match(origin) or not IATA.match(dest):
return fail('Use 3-letter airport codes, like JFK or LHR.')
if origin == dest:
return fail('Pick two different airports.')
return jsonify(call_api('airportdistance', {'iata1': origin, 'iata2': dest}))Deploy it
- Get a free API key
The free plan includes 200 credits a month, no card needed. Create your key.
- Deploy it
Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for
APIVERVE_API_KEY: paste your key there. - 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 Airport Distance API — the call this template makes
No key required to try it. Get a key to use it in your app.
{
"status": "ok",
"error": null,
"data": {
"distanceMiles": 2470.23,
"distanceKm": 3974.2,
"distanceNauticalMiles": 2145.9,
"estimatedFlightTime": "5h 26m",
"timezoneDiffHours": -3,
"bearing": 274,
"direction": "West",
"isInternational": false,
"carbonEstimateKg": 469,
"airport1": {
"name": "John F Kennedy International Airport",
"iata": "JFK",
"icao": "KJFK",
"city": "New York",
"state": "New York",
"country": "US",
"elevation": 13,
"latitude": 40.63980103,
"longitude": -73.77890015,
"timezone": "America/New_York"
},
"airport2": {
"name": "Los Angeles International Airport",
"iata": "LAX",
"icao": "KLAX",
"city": "Los Angeles",
"state": "California",
"country": "US",
"elevation": 125,
"latitude": 33.94250107,
"longitude": -118.4079971,
"timezone": "America/Los_Angeles"
}
}
}