The Trino database
- class pyopensky.trino.Trino(*, session_properties=None)
Bases:
OpenSkyDBAPIWrapper to OpenSky Trino database
Credentials are fetched from the configuration file.
All methods return standard structures. When calls are made from the traffic library, they return advanced structures.
- Parameters:
session_properties (
Optional[Mapping[str,str]]) – optional Trino session property names and values, applied to every connection opened by this client. For example,{"join_distribution_type": "BROADCAST"}. By default, use the server’s session settings.
- flightlist(start, stop=None, *args, departure_airport=None, arrival_airport=None, airport=None, routes=None, callsign=None, icao24=None, cached=True, compress=False, limit=None, extra_columns=None, Table=<class 'pyopensky.schema.FlightsData4'>, **kwargs)
Lists flights departing or arriving at a given airport.
You may pass requests based on time ranges, callsigns, aircraft, areas, serial numbers for receivers, or airports of departure or arrival.
The method builds appropriate SQL requests, caches results and formats data into a proper pandas DataFrame. Each call submits one query for the requested time window.
- Parameters:
start (timelike) – a string (default to UTC), epoch or datetime (native Python or pandas)
stop (timelike | None) – a string (default to UTC), epoch or datetime (native Python or pandas), by default, one day after start
- Return type:
pd.DataFrame | None
More arguments to filter resulting data:
- Parameters:
departure_airport (str | list[str] | None) – a string for the ICAO identifier of the airport. Selects flights departing from the airport between the two timestamps;
arrival_airport (str | list[str] | None) – a string for the ICAO identifier of the airport. Selects flights arriving at the airport between the two timestamps;
airport (str | list[str] | None) – a string for the ICAO identifier of the airport. Selects flights departing from or arriving at the airport between the two timestamps;
routes (list[tuple[str, str]] | None) – exact directed (departure, arrival) ICAO airport pairs. Selects any of these pairs, combined with other filters using AND. An empty list selects no flights. Wildcards are not expanded;
callsign (str | list[str] | None) – a string or a list of strings (wildcards accepted, _ for any character, % for any sequence of characters);
icao24 (str | list[str] | None) – a string or a list of strings identifying the transponder code of the aircraft;
Warning
If departure_airport is set, timestamps constrain firstseen. Otherwise, including routes alone, they constrain lastseen;
If airport is set,
departure_airportandarrival_airportcannot be specified (a RuntimeException is raised).
Useful options for debug
- Parameters:
cached (bool) – (default: True) switch to False to force a new request to the database regardless of the cached files. This option also deletes previous cache files;
compress (bool) – (default: False) compress cache files. Reduces disk space occupied at the expense of slightly increased time to load.
limit (int | None) – maximum number of records requested, LIMIT keyword in SQL.
- history(start, stop=None, *args, callsign=None, icao24=None, serials=None, bounds=None, departure_airport=None, arrival_airport=None, airport=None, routes=None, time_buffer=None, cached=True, compress=False, limit=None, selected_columns=(), **kwargs)
Get Traffic from the OpenSky Trino database.
You may pass requests based on time ranges, callsigns, aircraft, areas, serial numbers for receivers, or airports of departure or arrival.
The method builds appropriate SQL requests, caches results and formats data into a proper pandas DataFrame. Each call submits one query for the requested time window.
- Parameters:
start (timelike) – a string (default to UTC), epoch or datetime (native Python or pandas)
stop (timelike | None) – a string (default to UTC), epoch or datetime (native Python or pandas), by default, one day after start
- Return type:
pd.DataFrame | None
More arguments to filter resulting data:
- Parameters:
callsign (str | list[str] | None) – a string or a list of strings (wildcards accepted, _ for any character, % for any sequence of characters);
icao24 (str | list[str] | None) – a string or a list of strings identifying the transponder code of the aircraft;
serials (int | Iterable[int] | None) – an integer or a list of integers identifying the sensors receiving the data;
bounds (str | HasBounds | tuple[float, float, float, float] | None) – sets a geographical footprint. Either an airspace or shapely shape (requires the bounds attribute); or a tuple of float (west, south, east, north);
selected_columns (tuple[InstrumentedAttribute[Any] | str, …]) – specify the columns you want to retrieve. When empty, use all columns of the StateVectorsData4 table. You may specify column names as strings or schema attributes, including columns from the FlightsData4 table when a flight join is used.
Airports
The following options build more complicated requests by merging information from two tables in the Trino database, resp.
state_vectors_data4andflights_data4.- Parameters:
departure_airport (str | list[str] | None) – an ICAO airport identifier or a list of identifiers. Filters the estimated departure airport;
arrival_airport (str | list[str] | None) – an ICAO airport identifier or a list of identifiers. Filters the estimated arrival airport;
airport (str | list[str] | None) – an ICAO airport identifier or a list of identifiers. Filters either estimated departure or arrival airport;
routes (list[tuple[str, str]] | None) – exact directed (departure, arrival) ICAO airport pairs. Selects any of these pairs, combined with other filters using AND. An empty list selects no flights. Wildcards are not expanded. Unlike separate airport lists, only the listed pairs are selected;
time_buffer (str | pd.Timedelta | None) – (default: None) time buffer used to extend time bounds around each flight’s firstseen and lastseen. State vectors are still clipped to start and stop. Ignored without a flight join;
Warning
See
pyopensky.trino.flightlist()if you do not need any trajectory information.start and stop constrain state-vector timestamps, not flight departure or arrival times. Overnight flights can be partial;
If airport is set, departure_airport and arrival_airport cannot be specified (a RuntimeException is raised).
Useful options for debug
- Parameters:
cached (bool) – (default: True) switch to False to force a new request to the database regardless of the cached files. This option also deletes previous cache files;
compress (bool) – (default: False) compress cache files. Reduces disk space occupied at the expense of slightly increased time to load.
limit (int | None) – maximum number of records requested, LIMIT keyword in SQL.
- rawdata(start, stop=None, *args, icao24=None, serials=None, bounds=None, callsign=None, departure_airport=None, arrival_airport=None, airport=None, routes=None, cached=True, compress=False, limit=None, Table=<class 'pyopensky.schema.RollcallRepliesData4'>, extra_columns=(), **kwargs)
Get raw message from the OpenSky Trino database.
You may pass requests based on time ranges, callsigns, aircraft, areas, serial numbers for receivers, or airports of departure or arrival.
The method builds appropriate SQL requests, caches results and formats data into a proper pandas DataFrame. Each call submits one query for the requested time window.
- Parameters:
start (timelike) – a string (default to UTC), epoch or datetime (native Python or pandas)
stop (timelike | None) – a string (default to UTC), epoch or datetime (native Python or pandas), by default, one day after start
- Return type:
pd.DataFrame | None
More arguments to filter resulting data:
- Parameters:
callsign (str | list[str] | None) – a string or a list of strings (wildcards accepted, _ for any character, % for any sequence of characters);
icao24 (str | list[str] | None) – a string or a list of strings identifying the transponder code of the aircraft;
serials (int | Iterable[int] | None) – an integer or a list of integers identifying the sensors receiving the data;
bounds (HasBounds | tuple[float, float, float, float] | None) – sets a geographical footprint. Either an airspace or shapely shape (requires the bounds attribute); or a tuple of float (west, south, east, north);
Airports
The following options build more complicated requests by merging information from two tables in the Trino database, resp.
rollcall_replies_data4andflights_data4.- Parameters:
departure_airport (str | list[str] | None) – an ICAO airport identifier or a list of identifiers. Filters the estimated departure airport;
arrival_airport (str | list[str] | None) – an ICAO airport identifier or a list of identifiers. Filters the estimated arrival airport;
airport (str | list[str] | None) – an ICAO airport identifier or a list of identifiers. Filters either estimated departure or arrival airport;
routes (list[tuple[str, str]] | None) – exact directed (departure, arrival) ICAO airport pairs. Selects any of these pairs, combined with other airport and icao24 filters using AND. An empty list selects no flights. Wildcards are not expanded;
extra_columns (tuple[InstrumentedAttribute[Any], …]) – additional raw table columns, or FlightsData4 columns from the joined flight table;
Warning
start and stop constrain raw-message timestamps, not flight departure or arrival times;
If airport is set, departure_airport and arrival_airport cannot be specified (a RuntimeException is raised).
Select only one of flight metadata (airports, routes or flight conditions/columns), geographical bounds, or callsign.
Useful options for debug
- Parameters:
cached (bool) – (default: True) switch to False to force a new request to the database regardless of the cached files. This option also deletes previous cache files;
compress (bool) – (default: False) compress cache files. Reduces disk space occupied at the expense of slightly increased time to load.
limit (int | None) – maximum number of records requested, LIMIT keyword in SQL.