Airport search

Runnable examples for discovering airports by name or location using the Airport Search endpoints: text autocomplete and nearest-by-coordinates.

#QuestionData used
1Autocomplete: user types "heathrow" — what airports match?/airports/search/text
2Find the three nearest airports to given GPS coordinates/airports/search/location

Requirements

Auth
x-api-key on every request (direct subscription). Learn more →

Install

The scripts below use requests for API calls and rich for terminal output. Install once:

pip install requests rich

1. Text autocomplete for airport names

Question: Autocomplete: a user types "heathrow" — what airports match?

The /airports/search/text endpoint returns ranked results by relevance. Use the ident from the first result to call /airports/search?icao= for full runway, frequency, and navaid data.

import os

import requests
from rich.console import Console
from rich.table import Table

console = Console()

HEADERS = {
    "X-RapidAPI-Key": os.getenv("RAPIDAPI_KEY", "YOUR_RAPIDAPI_KEY"),
    "X-RapidAPI-Host": "skylink-api.p.rapidapi.com",
}
BASE = "https://skylink-api.p.rapidapi.com"


def search_text(query: str, limit: int = 5) -> dict | None:
    r = requests.get(
        f"{BASE}/airports/search/text",
        headers=HEADERS,
        params={"q": query, "limit": limit},
        timeout=(10, 15),
    )
    if r.status_code == 404:
        return None
    r.raise_for_status()
    return r.json()


def main() -> None:
    query = "heathrow"
    result = search_text(query, limit=5)
    if not result:
        console.print("[yellow]No results found.[/]")
        return

    airports = result.get("airports") or []
    found = result.get("airports_found", len(airports))

    table = Table(title=f'Text Search: "{query}" — {found} result(s)')
    table.add_column("ICAO", style="cyan", no_wrap=True)
    table.add_column("IATA")
    table.add_column("Name")
    table.add_column("City")
    table.add_column("Country")
    table.add_column("Relevance", justify="right")

    for apt in airports:
        table.add_row(
            apt.get("ident", "—"),
            apt.get("iata_code", "—"),
            apt.get("name", "—"),
            apt.get("municipality", "—"),
            apt.get("iso_country", "—"),
            f"{apt.get('relevance_score', 0):.2f}",
        )

    console.print(table)

    if airports:
        top_icao = airports[0].get("ident", "")
        console.print(
            f"\n[dim]Top match: [bold]{top_icao}[/bold] — fetch full details with "
            f"[bold]/airports/search?icao={top_icao}[/bold][/]"
        )


if __name__ == "__main__":
    main()

Output: A ranked table of up to 5 airports matching "heathrow" with ICAO, IATA, name, city, country, and relevance score. Prints the ICAO lookup command for the top result.


2. Nearest airports to GPS coordinates

Question: Find the three nearest airports to given GPS coordinates (lat/lon).

The /airports/search/location endpoint returns airports within a radius sorted by distance. Chain any ident to /airports/search?icao= to retrieve full runway and frequency data.

import os

import requests
from rich.console import Console
from rich.table import Table

console = Console()

HEADERS = {
    "X-RapidAPI-Key": os.getenv("RAPIDAPI_KEY", "YOUR_RAPIDAPI_KEY"),
    "X-RapidAPI-Host": "skylink-api.p.rapidapi.com",
}
BASE = "https://skylink-api.p.rapidapi.com"


def search_location(lat: float, lon: float, radius_km: int = 80) -> dict | None:
    r = requests.get(
        f"{BASE}/airports/search/location",
        headers=HEADERS,
        params={"lat": lat, "lon": lon, "radius_km": radius_km},
        timeout=(10, 15),
    )
    if r.status_code == 404:
        return None
    r.raise_for_status()
    return r.json()


def main() -> None:
    # Central London
    lat, lon = 51.5074, -0.1278
    result = search_location(lat, lon, radius_km=80)
    if not result:
        console.print("[yellow]No airports found in radius.[/]")
        return

    airports = result.get("airports") or []
    airports.sort(key=lambda a: a.get("distance_km") or 9999)
    nearest_three = airports[:3]

    table = Table(title=f"Nearest Airports to {lat}°N, {abs(lon)}°W (radius 80 km)")
    table.add_column("ICAO", style="cyan", no_wrap=True)
    table.add_column("Name")
    table.add_column("City")
    table.add_column("Country")
    table.add_column("Distance (km)", justify="right")

    for apt in nearest_three:
        dist = apt.get("distance_km")
        table.add_row(
            apt.get("ident", "—"),
            apt.get("name", "—"),
            apt.get("municipality", "—"),
            apt.get("iso_country", "—"),
            f"{dist:.1f}" if dist is not None else "—",
        )

    console.print(table)
    console.print(
        "\n[dim]Chain any ICAO to [bold]/airports/search?icao={ident}[/bold] "
        "for runway lengths and frequencies.[/]"
    )


if __name__ == "__main__":
    main()

Output: The three closest airports to central London sorted by distance, with ICAO, name, city, country, and distance in km.