Flight status
Runnable examples for live flight tracking using the Flight Status endpoint. Each script answers a practical dispatch or monitoring question — from checking a single flight to building a live departure board.
| # | Question | Data used |
|---|---|---|
| 1 | What is the current status of flight BA123? | Flight Status |
| 2 | Is flight AA100 delayed, and by how much? | Flight Status |
| 3 | Poll multiple flights for a departure board | Flight Status |
Requirements
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 rich1. Current flight status summary
Question: What is the current status of flight BA123?
GET /flight_status/BA123 returns live departure and arrival info. Gate, terminal, and baggage fields are often empty strings — the script treats those as unknown.
import os
import requests
from rich.console import Console
from rich.panel import Panel
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"
STATUS_STYLE: dict[str, str] = {
"En Route": "green",
"Arrived": "green",
"Departed": "green",
"Delayed": "yellow",
"Cancelled": "red",
"Scheduled": "white",
"Unknown": "white",
}
def fetch_flight_status(flight_number: str) -> dict | None:
r = requests.get(
f"{BASE}/flight_status/{flight_number}",
headers=HEADERS,
timeout=(10, 15),
)
if r.status_code == 404:
return None
r.raise_for_status()
return r.json()
def fmt_time(scheduled: str | None, actual: str | None) -> str:
if not scheduled:
return "—"
if actual and actual != scheduled:
return f"{scheduled} (actual {actual})"
return scheduled
def main() -> None:
data = fetch_flight_status("BA123")
if not data:
console.print("[yellow]Flight BA123 not found.[/]")
return
status = data.get("status", "Unknown")
style = STATUS_STYLE.get(status, "white")
dep = data.get("departure", {})
arr = data.get("arrival", {})
table = Table(title=f"Flight {data.get('flight_number', 'BA123')}")
table.add_column("Field", style="cyan", min_width=20)
table.add_column("Value")
table.add_row("Airline", data.get("airline", "—"))
table.add_row("Status", f"[{style}]{status}[/]")
table.add_row("Departure airport", f"{dep.get('airport_full', '—')} ({dep.get('airport', '—')})")
table.add_row("Departure time", fmt_time(dep.get("scheduled_time"), dep.get("actual_time")))
table.add_row("Arrival airport", f"{arr.get('airport_full', '—')} ({arr.get('airport', '—')})")
table.add_row("Arrival time", fmt_time(arr.get("scheduled_time"), arr.get("estimated_time")))
if "delayed" in status.lower():
table.add_row("Delay", "[yellow]See status label[/]")
console.print(table)
if __name__ == "__main__":
main()Output: A table with airline, status (color-coded), departure and arrival airports with scheduled times. Actual or estimated time shown when it differs from scheduled.
2. Delay check for a specific flight
Question: Is flight AA100 delayed, and by how much?
import os
import requests
from rich.console import Console
from rich.panel import Panel
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 fetch_flight_status(flight_number: str) -> dict | None:
r = requests.get(
f"{BASE}/flight_status/{flight_number}",
headers=HEADERS,
timeout=(10, 15),
)
if r.status_code == 404:
return None
r.raise_for_status()
return r.json()
def main() -> None:
data = fetch_flight_status("AA100")
if not data:
console.print("[yellow]Flight AA100 not found.[/]")
return
status = data.get("status", "Unknown")
dep = data.get("departure", {})
gate = dep.get("gate", "") or ""
terminal = dep.get("terminal", "") or ""
gate_info = f"Gate {gate}" if gate else "Gate unknown"
terminal_info = f"Terminal {terminal}" if terminal else "Terminal unknown"
is_delayed = "delayed" in status.lower()
if is_delayed:
body = (
f"Flight {data.get('flight_number', 'AA100')} appears delayed.\n"
f"Current status: {status}\n"
f"Departure: {terminal_info}, {gate_info}"
)
console.print(Panel(body, title="[yellow]Delay Warning[/]", style="yellow"))
elif "cancel" in status.lower():
body = (
f"Flight {data.get('flight_number', 'AA100')} is cancelled.\n"
f"Current status: {status}"
)
console.print(Panel(body, title="[red]Cancelled[/]", style="red"))
else:
body = (
f"Flight {data.get('flight_number', 'AA100')} is on time.\n"
f"Current status: {status}\n"
f"Departure: {terminal_info}, {gate_info}"
)
console.print(Panel(body, title="[green]On Time[/]", style="green"))
if __name__ == "__main__":
main()Output: A colored panel — yellow when status indicates delay, red when cancelled, green when on time. Includes current status and departure gate/terminal when available.
3. Live departure board (multiple flights)
Question: Poll multiple flights and display a compact departure board.
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"
FLIGHTS = ["BA123", "AA100", "UA1"]
STATUS_STYLE: dict[str, str] = {
"En Route": "green",
"Arrived": "green",
"Departed": "green",
"Delayed": "yellow",
"Cancelled": "red",
"Scheduled": "white",
"Unknown": "dim",
}
def fetch_flight_status(flight_number: str) -> dict | None:
r = requests.get(
f"{BASE}/flight_status/{flight_number}",
headers=HEADERS,
timeout=(10, 15),
)
if r.status_code == 404:
return None
r.raise_for_status()
return r.json()
def main() -> None:
table = Table(title="Departure Board")
table.add_column("Flight", style="cyan")
table.add_column("Airline")
table.add_column("Status")
table.add_column("Dep", min_width=5)
table.add_column("Arr", min_width=5)
table.add_column("Gate")
for flight_number in FLIGHTS:
try:
data = fetch_flight_status(flight_number)
except requests.HTTPError as exc:
table.add_row(flight_number, "—", f"[red]Error {exc.response.status_code}[/]", "—", "—", "—")
continue
if not data:
table.add_row(flight_number, "—", "[dim]Not found[/]", "—", "—", "—")
continue
status = data.get("status", "Unknown")
style = STATUS_STYLE.get(status, "white")
dep = data.get("departure", {})
arr = data.get("arrival", {})
gate = dep.get("gate", "") or "—"
dep_time = dep.get("actual_time") or dep.get("scheduled_time") or "—"
arr_time = arr.get("estimated_time") or arr.get("scheduled_time") or "—"
table.add_row(
data.get("flight_number", flight_number),
data.get("airline", "—"),
f"[{style}]{status}[/]",
dep_time,
arr_time,
gate,
)
console.print(table)
if __name__ == "__main__":
main()Output: A compact table with one row per flight showing flight number, airline, color-coded status, departure time, arrival time, and gate. Flights returning 404 are shown as "Not found" without crashing the board.