
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
airports-py
Advanced tools
A comprehensive library providing easy retrieval of airport data based on IATA, ICAO, city codes, country codes, and continents. Features geographic search, distance calculation, timezone lookup, and external links integration.
A comprehensive Python library providing easy retrieval of airport data based on IATA, ICAO, city codes, country codes, and continents. Ideal for developers building applications related to aviation, travel, and geography in Python.
You can install airports-py using pip:
pip install airports-py
Each airport object contains the following fields:
{
"iata": "SIN", # 3-letter IATA code
"icao": "WSSS", # 4-letter ICAO code
"time": "Asia/Singapore", # Timezone identifier
"country_code": "SG", # 2-letter country code
"continent": "AS", # 2-letter continent code (AS, EU, NA, SA, AF, OC, AN)
"airport": "Singapore Changi Airport", # Airport name
"latitude": "1.35019", # Latitude coordinate
"longitude": "103.994003", # Longitude coordinate
"elevation": "22", # Elevation in feet
"type": "large_airport", # Airport type
"scheduled_service": "yes", # Has scheduled commercial service
"wikipedia": "https://en.wikipedia.org/wiki/Singapore_Changi_Airport",
"website": "https://www.changiairport.com",
"runway_length": "13200", # Longest runway in feet
"flightradar24_url": "https://www.flightradar24.com/airport/SIN",
"radarbox_url": "https://www.radarbox.com/airport/WSSS",
"flightaware_url": "https://www.flightaware.com/live/airport/WSSS"
}
from airports import airport_data
# Get airport by IATA code
airport_by_iata = airport_data.get_airport_by_iata("SIN")
print(airport_by_iata[0]["airport"]) # "Singapore Changi Airport"
# Get airport by ICAO code
airport_by_icao = airport_data.get_airport_by_icao("WSSS")
print(airport_by_icao[0]["country_code"]) # "SG"
# Search airports by name
airports = airport_data.search_by_name("Singapore")
print(len(airports)) # Multiple airports matching "Singapore"
# Find nearby airports (within 50km of coordinates)
nearby = airport_data.find_nearby_airports(1.35019, 103.994003, 50)
print(nearby) # Airports near Singapore Changi
get_airport_by_iata(iata_code)Finds airports by their 3-letter IATA code.
airports = airport_data.get_airport_by_iata('LHR')
# Returns list of airports with IATA code 'LHR'
get_airport_by_icao(icao_code)Finds airports by their 4-character ICAO code.
airports = airport_data.get_airport_by_icao('EGLL')
# Returns list of airports with ICAO code 'EGLL'
search_by_name(query)Searches for airports by name (case-insensitive, minimum 2 characters).
airports = airport_data.search_by_name('Heathrow')
# Returns airports with 'Heathrow' in their name
find_nearby_airports(lat, lon, radius_km=100)Finds airports within a specified radius of given coordinates.
nearby = airport_data.find_nearby_airports(51.5074, -0.1278, 100)
# Returns airports within 100km of London coordinates
calculate_distance(code1, code2)Calculates the great-circle distance between two airports using IATA or ICAO codes.
distance = airport_data.calculate_distance('LHR', 'JFK')
# Returns distance in kilometers (approximately 5540)
get_airport_by_country_code(country_code)Finds all airports in a specific country.
us_airports = airport_data.get_airport_by_country_code('US')
# Returns all airports in the United States
get_airport_by_continent(continent_code)Finds all airports on a specific continent.
asian_airports = airport_data.get_airport_by_continent('AS')
# Returns all airports in Asia
# Continent codes: AS, EU, NA, SA, AF, OC, AN
get_airports_by_type(airport_type)Finds airports by their type.
large_airports = airport_data.get_airports_by_type('large_airport')
# Available types: large_airport, medium_airport, small_airport, heliport, seaplane_base
# Convenience search for all airports
all_airports = airport_data.get_airports_by_type('airport')
# Returns large_airport, medium_airport, and small_airport
get_airports_by_timezone(timezone)Finds all airports within a specific timezone.
london_airports = airport_data.get_airports_by_timezone('Europe/London')
# Returns airports in London timezone
find_airports(filters)Finds airports matching multiple criteria.
# Find large airports in Great Britain with scheduled service
airports = airport_data.find_airports({
'country_code': 'GB',
'type': 'large_airport',
'has_scheduled_service': True
})
# Find airports with minimum runway length
long_runway_airports = airport_data.find_airports({
'min_runway_ft': 10000
})
get_autocomplete_suggestions(query, limit=10)Provides autocomplete suggestions for search interfaces (returns max 10 results by default).
suggestions = airport_data.get_autocomplete_suggestions('Lon')
# Returns up to 10 airports matching 'Lon' in name or IATA code
get_airport_links(code)Gets external links for an airport using IATA or ICAO code.
links = airport_data.get_airport_links('SIN')
# Returns:
# {
# 'website': "https://www.changiairport.com",
# 'wikipedia': "https://en.wikipedia.org/wiki/Singapore_Changi_Airport",
# 'flightradar24': "https://www.flightradar24.com/airport/SIN",
# 'radarbox': "https://www.radarbox.com/airport/WSSS",
# 'flightaware': "https://www.flightaware.com/live/airport/WSSS"
# }
get_airport_stats_by_country(country_code)Gets comprehensive statistics about airports in a specific country.
stats = airport_data.get_airport_stats_by_country('US')
# Returns:
# {
# 'total': 5432,
# 'by_type': {
# 'large_airport': 139,
# 'medium_airport': 467,
# 'small_airport': 4826,
# ...
# },
# 'with_scheduled_service': 606,
# 'average_runway_length': 5234,
# 'average_elevation': 1245,
# 'timezones': ['America/New_York', 'America/Chicago', ...]
# }
get_airport_stats_by_continent(continent_code)Gets comprehensive statistics about airports on a specific continent.
stats = airport_data.get_airport_stats_by_continent('AS')
# Returns statistics for Asian airports
get_largest_airports_by_continent(continent_code, limit=10, sort_by='runway')Gets the largest airports on a continent by runway length or elevation.
# Get top 5 airports in Asia by runway length
top_airports = airport_data.get_largest_airports_by_continent('AS', limit=5, sort_by='runway')
# Get top 10 airports by elevation
high_airports = airport_data.get_largest_airports_by_continent('SA', limit=10, sort_by='elevation')
get_multiple_airports(codes)Fetches multiple airports by their IATA or ICAO codes in one call.
airports = airport_data.get_multiple_airports(['SIN', 'LHR', 'JFK', 'WSSS'])
# Returns list of airport objects (None for codes not found)
calculate_distance_matrix(codes)Calculates distances between all pairs of airports in a list.
matrix = airport_data.calculate_distance_matrix(['SIN', 'LHR', 'JFK'])
# Returns:
# {
# 'airports': [...],
# 'distances': {
# 'SIN': { 'SIN': 0, 'LHR': 10872, 'JFK': 15344 },
# ...
# }
# }
find_nearest_airport(lat, lon, filters=None)Finds the single nearest airport to given coordinates, optionally with filters.
# Find nearest airport
nearest = airport_data.find_nearest_airport(1.35019, 103.994003)
print(f"{nearest['airport']} is {nearest['distance']} km away")
# Find nearest large airport with scheduled service
nearest_hub = airport_data.find_nearest_airport(1.35019, 103.994003, {
'type': 'large_airport',
'has_scheduled_service': True
})
validate_iata_code(code) / validate_icao_code(code)Validates if a code exists in the database.
is_valid = airport_data.validate_iata_code('SIN') # True
get_airport_count(filters)Gets the count of airports matching the given filters.
count = airport_data.get_airport_count({
'country_code': 'US',
'type': 'large_airport'
})
is_airport_operational(code)Checks if an airport has scheduled commercial service.
is_operational = airport_data.is_airport_operational('SIN') # True
All functions raise appropriate exceptions for invalid input or when no data is found.
try:
airport = airport_data.get_airport_by_iata('XYZ')
except ValueError as e:
print(e) # "No data found for IATA code: XYZ"
# Find airports within 100km of Paris
paris_airports = airport_data.find_nearby_airports(48.8566, 2.3522, 100)
print(f"Found {len(paris_airports)} airports near Paris")
# Calculate distance between Singapore and London
distance = airport_data.calculate_distance('SIN', 'LHR')
print(f"Distance: {round(distance)} km")
# Get autocomplete suggestions
suggestions = airport_data.get_autocomplete_suggestions('New York')
for airport in suggestions:
print(f"{airport['iata']} - {airport['airport']}")
# Find large airports in Asia with scheduled service
asian_hubs = airport_data.find_airports({
'continent': 'AS',
'type': 'large_airport',
'has_scheduled_service': True
})
You can also directly execute Python code from the CLI without entering the interactive shell. Navigate to the root of your project and run:
python3 -c "from airports import airport_data; result = airport_data.get_airport_by_iata('MAA'); print(result)"
Replace 'MAA' with other codes as needed.
To test the library locally:
cd path_to_airports-py
python3 -m unittest discover tests -v
This command will discover and run all test files inside the tests directory and provide a detailed output.
For Chennai International Airport:
| Field Name | Data |
|---|---|
| IATA | MAA |
| ICAO | VOMM |
| Time Zone | Asia/Kolkata |
| City Code | MAA |
| Country Code | IN |
| Name | Chennai International Airport |
| Latitude | 12.99 |
| Longitude | 80.1693 |
| Altitude (in feet) | 52 |
| State | Tamil Nadu |
| City | Pallavaram |
| County | Kancheepuram |
| State Code | Tamil Nadu |
| Airport Type | large_airport |
| Continent | AS |
| State Abbreviation | IN-TN |
| International | TRUE |
| Wikipedia Link | Wikipedia |
| Official Website | Chennai Airport |
| Location ID | 12513629 |
| Phone Number | 044-2340551 |
| Runway Length (in meters) | 10050 |
| Flightradar24 | Flightradar24 |
| Radarbox | Radarbox |
| Flightaware Link | Flightaware |
| Field Name | Data |
|---|---|
| IATA | SIN |
| ICAO | WSSS |
| Time Zone | Asia/Singapore |
| City Code | SIN |
| Country Code | SG |
| Name | Singapore Changi Airport |
| Latitude | 1.35019 |
| Longitude | 103.994 |
| Altitude (in feet) | 22 |
| State | Singapore |
| City | Singapore |
| County | Singapore |
| State Code | South East |
| Airport Type | large_airport |
| Continent | AS |
| State Abbreviation | SG-04 |
| International | TRUE |
| Wikipedia Link | Wikipedia |
| Official Website | Changi Airport |
| Location ID | 12517525 |
| Phone Number | (65) 6542 1122 |
| Runway Length (in meters) | 13200 |
| Flightradar24 | Flightradar24 |
| Radarbox | Radarbox |
| Flightaware | Flightaware |
get_airport_stats_by_country(country_code) - Comprehensive country-level airport statisticsget_airport_stats_by_continent(continent_code) - Continent-level statisticsget_largest_airports_by_continent - Find top airports by runway length or elevationget_multiple_airports(codes) - Bulk fetch by IATA/ICAO codescalculate_distance_matrix(codes) - Calculate distances between all pairs of airportsfind_nearest_airport(lat, lon, filters) - Find single nearest airport with optional filteringvalidate_iata_code / validate_icao_code - Validation utilitiesis_airport_operational(code) - Check scheduled service statusget_airport_count(filters) - Efficient filtered countingfind_airports to correctly handle boolean filters stored as strings ("TRUE"/"FALSE")get_airports_by_timezone(timezone) - Find airports by timezoneget_airport_links(code) - Get external links for airportsfind_airports(filters) - Advanced multi-criteria filteringget_autocomplete_suggestions(query) - Autocomplete functionalityget_airports_by_type(type) - Now supports convenience search for "airport" typesearch_by_name(query) - Search airports by namefind_nearby_airports(lat, lon, radius_km) - Geographic proximity searchcalculate_distance(code1, code2) - Distance calculation between airportsfind_airports function)git clone https://github.com/aashishvanand/airports-py.git
cd airports-py
python3 -m venv venv
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
pip install --upgrade pip
pip install build twine pytest pytest-cov
pip install -e .
# Generate airports.gz from airports.json
python scripts/generate_airports_gz.py
# Verify the data file
python scripts/generate_airports_gz.py --verify-only
python -m unittest discover tests -v
python -m pytest tests/ -v
python -m pytest tests/ -v --cov=airports --cov-report=term-missing
python -c "
from airports import airport_data
print('Testing IATA lookup:')
result = airport_data.get_airport_by_iata('LHR')
print(f'Found: {result[0][\"airport\"]}')
print('✅ Basic functionality working!')
"
# Clean previous builds
rm -rf build/ dist/ *.egg-info/
# Build package
python -m build
twine check dist/*
pip install dist/airports_py-*.whl --force-reinstall
The project includes utility scripts in the scripts/ directory:
# Generate airports.gz from airports.json
python scripts/generate_airports_gz.py
# Generate with custom compression level
python scripts/generate_airports_gz.py --compression 6
# Generate with custom source/output files
python scripts/generate_airports_gz.py --source custom_data.json --output custom_data.gz
# Verify existing compressed file
python scripts/generate_airports_gz.py --verify-only
For ongoing development, use this workflow:
# 1. Make your changes to the code
# 2. Regenerate data file if JSON was updated
python scripts/generate_airports_gz.py
# 3. Run tests
python -m pytest tests/ -v
# 4. Build and validate
python -m build && twine check dist/*
# 5. Test installation
pip install dist/airports_py-*.whl --force-reinstall
If you get import errors:
which python should show the venv pathpip list | grep airportspython -c "import airports.airport_data"If data file is missing:
python scripts/generate_airports_gz.pyls -la airports/data/airports.gzpython scripts/generate_airports_gz.py --verify-onlyIf tests fail:
pip install pytest pytest-covpython -m pytest tests/test_airport_data.py::TestAirportData::test_get_airport_by_iata -vIf build fails:
setup.py has correct package data configurationairports/data/airports.gz exists and is included in packageWhen you're done developing:
deactivate
The airport data is stored in airports/data/ directory:
airports.json - Source data in JSON format (4.7MB)airports.gz - Compressed data used by the library (617KB, 86.9% compression)# Edit airports/data/airports.json with new airport data
python scripts/generate_airports_gz.py
python scripts/generate_airports_gz.py --verify-only
python -c "from airports import airport_data; print(f'Loaded {len(airport_data.airports)} airports')"
python -m pytest tests/ -v
This library uses a comprehensive dataset of worldwide airports with regular updates to ensure accuracy and completeness.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
FAQs
A comprehensive library providing easy retrieval of airport data based on IATA, ICAO, city codes, country codes, and continents. Features geographic search, distance calculation, timezone lookup, and external links integration.
We found that airports-py demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.