A Python CLI tool to calculate the distance between any two airports. Enter IATA codes and get the distance in miles and kilometers, plus detailed airport information.
This tutorial requires an APIVerve API key. Sign up free - no credit card required.
- Calculate distance between any two airports
- Distance in miles and kilometers
- Detailed airport information
- IATA and ICAO codes
- City, state, country data
- Elevation and coordinates
- Estimated flight time
- Popular route presets
-
Clone this repository
git clone https://github.com/apiverve/airport-distance-python-tutorial.git cd airport-distance-python-tutorial -
Install dependencies
pip install -r requirements.txt
-
Set your API key
export APIVERVE_API_KEY=your-api-key-here -
Run the calculator
python distance.py
airport-distance-python-tutorial/
├── distance.py # Main Python script
├── requirements.txt # Python dependencies
├── screenshot.jpg # Preview image
├── LICENSE # MIT license
├── .gitignore # Git ignore rules
└── README.md # This file
- Enter two IATA airport codes
- API looks up both airports
- Calculates great-circle distance
- Returns full airport details
response = requests.get('https://api.apiverve.com/v1/airportdistance',
headers={'x-api-key': API_KEY},
params={
'airport1': 'JFK',
'airport2': 'LAX'
}
)Endpoint: GET https://api.apiverve.com/v1/airportdistance
Query Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
airport1 |
string | Yes | First airport IATA code |
airport2 |
string | Yes | Second airport IATA code |
Example Response:
{
"status": "ok",
"error": null,
"data": {
"distanceMiles": 2470.23,
"distanceKm": 3974.2,
"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
},
"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
}
}
}| Field | Description |
|---|---|
name |
Full airport name |
iata |
3-letter IATA code |
icao |
4-letter ICAO code |
city |
City name |
state |
State/province/region |
country |
Country code |
elevation |
Elevation in feet |
latitude |
Latitude coordinate |
longitude |
Longitude coordinate |
| Route | Distance |
|---|---|
| JFK → LAX | 2,470 miles |
| LHR → JFK | 3,451 miles |
| SFO → NRT | 5,130 miles |
| DXB → SIN | 3,637 miles |
| SYD → LAX | 7,488 miles |
| Code | Airport |
|---|---|
| JFK | New York JFK |
| LAX | Los Angeles |
| LHR | London Heathrow |
| CDG | Paris Charles de Gaulle |
| NRT | Tokyo Narita |
| DXB | Dubai |
| SIN | Singapore Changi |
| SYD | Sydney |
| ORD | Chicago O'Hare |
| ATL | Atlanta |
- Add route visualization on map
- Calculate carbon emissions
- Compare multiple routes
- Find nearest airports
- Build flight search
- Add layover calculations
Explore more APIs at APIVerve:
- Airports Lookup - Search airports
- Airline Lookup - Airline information
- Distance Calculator - General distance calc
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
- Airport Distance API - API details
