ADS-B data – OpenSky REST API

The first thing to do is to put your credentials in you configuration file. Add the following lines to the [global] section of your configuration file.

opensky_username =
opensky_password =

You can check the path to your configuration file here. The path is different according to OS versions so do not assume anything and check the contents of the variable.

>>> import traffic
>>> traffic.config_file
PosixPath('/home/xo/.config/traffic/traffic.conf')

Warning

Some functionalities of the REST API are currently unavailable due to issues on the server side. Documentation will be updated if the API changes when things are fixed.

The most basic usage for the OpenSky REST API is to get the instant position for all aircraft. This part actually does not require authentication.

%matplotlib inline
import matplotlib.pyplot as plt

from traffic.data import opensky
from traffic.drawing import EuroPP, countries

sv = opensky.api_states()

with plt.style.context('traffic'):
    fig, ax = plt.subplots(subplot_kw=dict(projection=EuroPP()))
    ax.add_feature(countries())
    ax.gridlines()
    ax.set_extent((-7, 15, 40, 55))

    sv.plot(ax, s=10)
Traffic over Western Europe

You may access all callsigns in the state vector (or select few of them), then select the trajectory associated to a callsign (a Flight):

>>> import random
>>> random.sample(sv.callsigns, 6)
['RYR925Y', 'SKW5223', 'SWA1587', 'SWA2476', 'GTI8876', 'AAL2498']
flight = sv['AAL2498']
flight
Flight AAL2498
  • aircraft: a0b8fb / N146AA (A321)
  • origin: 2018-10-26 13:53:10
  • destination: 2018-10-26 15:11:31
# The same functionality is accessible based on the transponder code (icao24)
opensky.api_tracks(flight.icao24)
Flight AAL2498
  • aircraft: a0b8fb / N146AA (A321)
  • origin: 2018-10-26 13:53:10
  • destination: 2018-10-26 15:11:31

The API gives access to other functionalities, like an attempt to map a callsign to a route:

>>> opensky.api_routes('AFR291')
(RJBB/KIX    Osaka Kansai International Airport (Japan)
  34.427299 135.244003 altitude: 26,
 LFPG/CDG    Paris Charles de Gaulle Airport (France)
  49.012516 2.555752 altitude: 392)

You may get the serial numbers associated to your account and also plot the polygon of their range (by default on the current day).

>>> opensky.api_sensors
{'1433801924', '1549047001'}
with plt.style.context('traffic'):
    fig, ax = plt.subplots(subplot_kw=dict(projection=EuroPP()))
    ax.add_feature(countries())

    ax.gridlines()
    ax.set_extent((-7, 15, 40, 55))

    # get only the positions detected by your sensors
    sv = opensky.api_states(True)
    sv.plot(ax, s=20)

    for sensor in opensky.api_sensors:
        c = opensky.api_range(sensor)
        c.plot(ax, linewidth=2, edgecolor='grey', linestyle='dashed')
        c.point.plot(ax, marker='x', text_kw=dict(s=c.point.name))
OpenSky Coverage

The API also offers an attempt to map an airport with aircraft departing or arriving at an airport:

opensky.api_departure('LFBO', '2018-10-25 11:11', '2018-10-25 13:42')
firstSeen lastSeen icao24 callsign estDepartureAirport estArrivalAirport
17 2018-10-25 13:36:49 2018-10-25 14:39:53 406a93 EZY178A LFBO LFPO
16 2018-10-25 13:44:04 2018-10-25 14:47:58 0a0027 DAH1077 LFBO None
15 2018-10-25 13:49:11 2018-10-25 15:11:59 3c6744 DLH97F LFBO EDDM
14 2018-10-25 13:56:41 2018-10-25 15:11:27 4ca5f2 RYR87ZE LFBO EBCI
13 2018-10-25 14:01:00 2018-10-25 14:36:57 3944ef HOP13ZI LFBO LFLL
12 2018-10-25 14:03:25 2018-10-25 14:48:29 3815da FWWEZ LFBO None
11 2018-10-25 14:15:30 2018-10-25 15:51:29 485814 KLM96H LFBO EHAM
10 2018-10-25 14:18:05 2018-10-25 17:58:05 389b9b AIB01HF LFBO LFBO
9 2018-10-25 14:28:35 2018-10-25 15:48:59 440833 EZY71TU LFBO EGGD
8 2018-10-25 14:36:42 2018-10-25 15:42:28 44056d EZY987K LFBO EBTY
7 2018-10-25 14:52:19 2018-10-25 15:37:44 39b9f9 HOP14YI LFBO LFML
6 2018-10-25 15:07:45 2018-10-25 16:06:28 3985aa AFR48FC LFBO LFPO
5 2018-10-25 15:08:56 2018-10-25 16:27:17 38161a FWWEB LFBO LFBO
4 2018-10-25 15:10:30 2018-10-25 18:49:32 151d42 RSD076 LFBO UUWW
3 2018-10-25 15:28:45 2018-10-25 16:41:41 c074fb CGSHU LFBO LFPB
2 2018-10-25 15:31:13 2018-10-25 17:00:38 382aba AIB04YX LFBO LFBO
1 2018-10-25 15:32:47 2018-10-25 17:00:36 02a0ad TAR283 LFBO DTTA
0 2018-10-25 15:37:16 2018-10-25 16:33:58 393324 AFR61FJ LFBO LFPO