### Install Make and Maven Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/README.md Install essential build tools like make and maven using apt-get if they are not already present on your system. ```bash apt-get install build-essential maven ``` -------------------------------- ### Install Sphinx Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/README.md Install Sphinx using apt-get for Ubuntu systems. Ensure you have root privileges. ```bash apt-get install python-sphinx ``` -------------------------------- ### Install OpenSky API Client via Pip Source: https://github.com/openskynetwork/opensky-api/blob/master/python/README.md Install the client directly from GitHub using pip. This is the recommended installation method. ```bash pip install "git+https://github.com/openskynetwork/opensky-api.git#subdirectory=python" ``` -------------------------------- ### Install OpenSky API with Maven Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/java.md Install the OpenSky API locally using Maven. This command cleans and installs the project. ```bash mvn clean install ``` -------------------------------- ### Java API - Get States Source: https://github.com/openskynetwork/opensky-api/blob/master/README.md Example of how to retrieve state vectors using the Java client. ```APIDOC ## getStates ### Description Retrieves the current state vectors for all aircraft using the Java API. ### Method ```java new OpenSkyApi().getStates(0); ``` ### Parameters - **0** (int) - Represents the timestamp for which to retrieve states. Using 0 typically fetches the latest available data. ### Request Example ```java import org.opensky.api.OpenSkyApi; import org.opensky.api.model.OpenSkyStates; // ... inside a method or main function OpenSkyStates states = new OpenSkyApi().getStates(0); System.out.println("Number of states: " + states.getStates().size()); ``` ### Response #### Success Response Returns an `OpenSkyStates` object containing a list of state vectors. ```java // Example of accessing data from OpenSkyStates object // System.out.println("Number of states: " + states.getStates().size()); // For each state in states.getStates(), you can access its properties like: // state.getIcao24(), state.getCallsign(), state.getLatitude(), etc. ``` ``` -------------------------------- ### Install OpenSky API Client Locally Source: https://github.com/openskynetwork/opensky-api/blob/master/python/README.md Clone the repository and install the client locally. This is useful for development or if you need to modify the client code. ```bash git clone https://github.com/openskynetwork/opensky-api.git pip install -e opensky-api/python ``` -------------------------------- ### Install Read the Docs Theme Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/README.md Install the Read the Docs Sphinx theme using pip. This theme is commonly used for documentation. ```bash pip install sphinx_rtd_theme ``` -------------------------------- ### Python API - Get States (Authenticated) Source: https://github.com/openskynetwork/opensky-api/blob/master/README.md Example of how to retrieve state vectors using the Python client with OAuth2 authentication via a credentials file. ```APIDOC ## get_states (Authenticated) ### Description Retrieves the current state vectors for all aircraft using OAuth2 authentication. ### Method ```python api.get_states() ``` ### Parameters Requires a `TokenManager` initialized with credentials. ### Request Example ```python from opensky_api import OpenSkyApi, TokenManager api = OpenSkyApi(token_manager=TokenManager.from_json_file("credentials.json")) s = api.get_states() print(s) ``` ### Response #### Success Response (200) Returns a dictionary containing a list of state vectors and the time of the data. The token is automatically refreshed. ```json { "states": [ StateVector(dict_values(['c04049', '', 'Canada', 1507203246, 1507203249, -81.126, 37.774, 10980.42, False, 245.93, 186.49, 0.33, None, 10972.8, None, False, 0])), StateVector(dict_values(['4240eb', 'UTA716 ', 'United Kingdom', 1507202967, 1507202981, 37.4429, 55.6265, 609.6, True, 92.52, 281.87, -3.25, None, None, '4325', False, 0])), StateVector(dict_values(['aa8c39', 'UAL534 ', 'United States', 1507203250, 1507203250, -118.0869, 33.8656, 1760.22, False, 111.31, 343.07, -5.2, None, 1752.6, '2643', False, 0])), StateVector(dict_values(['7800ed', 'CES5124 ', 'China', 1507203250, 1507203250, 116.8199, 40.2763, 3459.48, False, 181.88, 84.64, 11.7, None, 3566.16, '5632', False, 0])), ], "time": 1507203250 } ``` ``` -------------------------------- ### Python API - Get States (Anonymous) Source: https://github.com/openskynetwork/opensky-api/blob/master/README.md Example of how to retrieve state vectors anonymously using the Python client. This method has reduced rate limits. ```APIDOC ## get_states ### Description Retrieves the current state vectors for all aircraft. ### Method ```python api.get_states() ``` ### Parameters None ### Request Example ```python from opensky_api import OpenSkyApi api = OpenSkyApi() s = api.get_states() print(s) ``` ### Response #### Success Response (200) Returns a dictionary containing a list of state vectors and the time of the data. ```json { "states": [ StateVector(dict_values(['c04049', '', 'Canada', 1507203246, 1507203249, -81.126, 37.774, 10980.42, False, 245.93, 186.49, 0.33, None, 10972.8, None, False, 0])), StateVector(dict_values(['4240eb', 'UTA716 ', 'United Kingdom', 1507202967, 1507202981, 37.4429, 55.6265, 609.6, True, 92.52, 281.87, -3.25, None, None, '4325', False, 0])), StateVector(dict_values(['aa8c39', 'UAL534 ', 'United States', 1507203250, 1507203250, -118.0869, 33.8656, 1760.22, False, 111.31, 343.07, -5.2, None, 1752.6, '2643', False, 0])), StateVector(dict_values(['7800ed', 'CES5124 ', 'China', 1507203250, 1507203250, 116.8199, 40.2763, 3459.48, False, 181.88, 84.64, 11.7, None, 3566.16, '5632', False, 0])), ], "time": 1507203250 } ``` ``` -------------------------------- ### Java API Usage Example Source: https://github.com/openskynetwork/opensky-api/blob/master/README.md Retrieve and print the number of available flight states using the OpenSky API. This example assumes the API client is properly initialized. ```java OpenSkyStates states = new OpenSkyApi().getStates(0); System.out.println("Number of states: " + states.getStates().size()); ``` -------------------------------- ### Retrieve Own Sensor State Vectors Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/java.md Retrieve state vectors from your own sensors in real-time. This example retrieves all states without filtering by aircraft or sensor. ```java OpenSkyApi api = new OpenSkyApi(USERNAME, PASSWORD); // no filter on icao24 or sensor serial number OpenSkyStates os = api.getMyStates(0, null, null); ``` -------------------------------- ### Get Flights Arriving at an Airport Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Retrieve all flights arriving at a specific airport within a given time range. Ensure the Authorization header is set. ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/flights/arrival?airport=EDDF&begin=1517227200&end=1517230800" | python -m json.tool ``` -------------------------------- ### Get Arrivals by Airport Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Retrieves flights that arrived at a specific airport within a given time interval. Only arrivals from the previous day or earlier are available. The interval must not exceed two days. Returns 404 if no flights are found. ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/flights/arrival?airport=EDDF&begin=1517184000&end=1517270400" | python -m json.tool ``` -------------------------------- ### Query All-Call Replies Data Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/trino.md Example SQL query to retrieve data from the allcall_replies_data4 table for a specific hour. ```sql SELECT * FROM allcall_replies_data4 WHERE hour = 1478293200 LIMIT 1; ``` -------------------------------- ### Get Live Aircraft Track Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Use this endpoint to retrieve the live track for a specific aircraft using its ICAO24 address and a timestamp. Ensure you include your authorization token. ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/tracks/all?icao24=3c4b26&time=0" ``` -------------------------------- ### Retrieve All States (Anonymous) Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Fetches all current flight state vectors for anonymous users. This is a basic GET request to the /states/all endpoint. ```APIDOC ## GET /states/all ### Description Retrieves all current flight state vectors for anonymous users. ### Method GET ### Endpoint https://opensky-network.org/api/states/all ### Request Example ```bash curl -s "https://opensky-network.org/api/states/all" | python -m json.tool ``` ### Response #### Success Response (200) Returns a JSON object containing flight state vectors. #### Response Example ```json { "states": [ [ "3c6444", "44c3d0", 1604660000, 1604660000, 48.1374, 11.5755, 123.45, 10000.0, false, 0.0, 0.0, 0.0, 0.0, " கருப்பு " ] ] } ``` ``` -------------------------------- ### Get Flights in Time Interval Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Retrieves all flights that departed or arrived within a specified time interval. The interval must not exceed two hours. Returns 404 if no flights are found. ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/flights/all?begin=1517227200&end=1517230800" | python -m json.tool ``` -------------------------------- ### Build Sphinx and Javadoc Documentation Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/README.md Generate the Sphinx documentation and Javadoc using the make command. The output will be in the free/_build/html directory. ```bash make ``` -------------------------------- ### Obtain and Use Access Token (Bash) Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Use this bash script to export your client credentials, obtain an access token via a POST request to the token endpoint, and then use that token to make an API call. Tokens expire after 30 minutes. ```bash export CLIENT_ID=your_client_id export CLIENT_SECRET=your_client_secret export TOKEN=$(curl -X POST "https://auth.opensky-network.org/auth/realms/opensky-network/protocol/openid-connect/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials" \ -d "client_id=$CLIENT_ID" \ -d "client_secret=$CLIENT_SECRET" | jq -r .access_token) curl -H "Authorization: Bearer $TOKEN" https://opensky-network.org/api/states/all | jq . ``` -------------------------------- ### List All Available Tables in Trino Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/trino.md Use this command to see all the tables available in the database. The `_data4` suffix indicates the current version of the batch layer. ```sql SHOW TABLES; ``` -------------------------------- ### Retrieve All States (Authenticated) Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Fetch all flight state data using an API token for authentication. Replace `$TOKEN` with your actual API bearer token. The output is pretty-printed. ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/states/all" | python -m json.tool ``` -------------------------------- ### Get All States Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest-states-all-request.md Retrieves state vectors for all aircraft. You can optionally filter by time, ICAO24 address, and geographic bounding box. ```APIDOC ## GET /states/all ### Description Retrieves state vectors for all aircraft. This endpoint can be filtered by time, ICAO24 address, and a bounding box defined by latitude and longitude. ### Method GET ### Endpoint /states/all ### Parameters #### Query Parameters - **time** (integer) - Optional - The time in seconds since epoch (Unix time stamp) to retrieve states for. Current time will be used if omitted. - **icao24** (string) - Optional - One or more ICAO24 transponder addresses represented by a hex string (e.g. abc9f3). To filter multiple ICAO24 append the property once for each address. If omitted, the state vectors of all aircraft are returned. - **lamin** (float) - Optional - Lower bound for the latitude in decimal degrees. - **lomin** (float) - Optional - Lower bound for the longitude in decimal degrees. - **lamax** (float) - Optional - Upper bound for the latitude in decimal degrees. - **lomax** (float) - Optional - Upper bound for the longitude in decimal degrees. - **extended** (integer) - Optional - Set to 1 if the extended category is required. ### Response #### Success Response (200) - **time** (integer) - Timestamp of the state vectors. - **states** (array) - Array of state vectors for each aircraft. - Each state vector is an array containing: - **icao24** (string) - Unique ICAO 24-bit address of the transponder. - **callsign** (string) - Callsign of the aircraft. - **origin_country** (string) - Country of the aircraft's registration. - **time_position** (float) - Timestamp of the last received position update. - **last_contact** (float) - Timestamp of the last received contact. - **longitude** (float) - Current longitude in decimal degrees. - **latitude** (float) - Current latitude in decimal degrees. - **baro_altitude** (float) - Barometric altitude in meters. - **on_ground** (boolean) - Indicates if the aircraft is on the ground. - **velocity** (float) - Velocity over ground in m/s. - **true_track** (float) - True track in degrees (0-360). - **vertical_rate** (float) - Vertical rate in m/s. - **sensors** (integer) - Bitmask of sensors that contributed to this state. - **geo_altitude** (float) - Geometric altitude in meters. - **squawk** (string) - Squawk code. - **spi** (boolean) - Special position indicator. - **position_source** (integer) - Origin of the position. - **category** (integer) - Aircraft category. ### Request Example ``` GET /states/all?time=1678886400&icao24=a00001&lamin=40&lomin=-105&lamax=50&lomax=-95 ``` ### Response Example ```json { "time": 1678886400, "states": [ ["a00001", "CALLSIGN", "United States", 1678886399.0, 1678886399.0, -100.0, 45.0, 10000.0, false, 200.0, 90.0, 5.0, 10000.0, "7700", false, 0, 1] ] } ``` ``` -------------------------------- ### Connect to OpenSky Trino via CLI Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/trino.md Connect to the OpenSky Trino server using the Trino CLI. Ensure your OpenSky username is in lowercase. The --external-authentication flag initiates a browser-based login. ```bash trino --user=$USER --password \ --server=https://trino.opensky-network.org \ --external-authentication \ --catalog "minio" \ --schema "osky" ``` -------------------------------- ### Retrieve Flights from Time Interval Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/python.md Fetches FlightData for a specific time interval, defined by start and end timestamps. The interval must not exceed 2 hours. ```python from opensky_api import OpenSkyApi api = OpenSkyApi() data = api.get_flights_from_interval(1517227200, 1517230800) for flight in data: print(flight) ``` -------------------------------- ### Retrieve Arrivals by Airport Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/python.md Fetches arrival flight data for a specific airport within a given time interval. The interval must be smaller than 7 days. ```APIDOC ## Retrieve Arrivals by Airport ### Description Fetches arrival flight data for a specific airport within a given time interval. The interval must be smaller than 7 days. ### Method `api.get_arrivals_by_airport(airport_icao, begin, end)` ### Parameters * **airport_icao** (str) - Required - The ICAO identifier of the airport. * **begin** (int) - Required - The start of the time period as a Unix timestamp. * **end** (int) - Required - The end of the time period as a Unix timestamp. Must be less than 7 days after `begin`. ### Request Example ```python from opensky_api import OpenSkyApi api = OpenSkyApi() arrivals = api.get_arrivals_by_airport("EDDF", 1517227200, 1517230800) print("Arrivals:") for flight in arrivals: print(flight) ``` ### Response #### Success Response (200) Returns a list of `Flight` objects representing arrivals at the specified airport. #### Response Example ```json [ { "flight_id": 98765, "callsign": "UAE123", "number": "UAE123", "icao24": "89abcd", "est_departure_airport": "DXB", "est_arrival_airport": "EDDF", "departure_date": "2018-01-29T12:30:00Z", "arrival_date": "2018-01-29T13:00:00Z", "departure_airport_ts": 1517229000, "arrival_airport_ts": 1517230800, "states": [ // ... state vectors for the flight ... ] } ] ``` ``` -------------------------------- ### Get Flights Departing from an Airport Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Retrieve all flights departing from a specific airport within a given time range. The time interval must cover more than two days (UTC). ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/flights/departure?airport=EDDF&begin=1517227200&end=1517230800" | python -m json.tool ``` -------------------------------- ### Arrivals by Airport Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Retrieve flights arriving at a specific airport within a given time interval. ```APIDOC ## GET /flights/arrival ### Description Retrieve flights arriving at a specific airport within a given time interval. ### Method GET ### Endpoint /flights/arrival ### Parameters #### Query Parameters - **airport** (string) - Required - ICAO identifier for the airport. - **begin** (integer) - Required - Start of time interval as Unix time (seconds since epoch). - **end** (integer) - Required - End of time interval as Unix time (seconds since epoch). ### Request Example ```bash curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/flights/arrival?airport=EDDF&begin=1517227200&end=1517230800" ``` ### Response #### Success Response (200) - Flights are returned as a JSON array of flight objects. ``` -------------------------------- ### Get Flight Tracks Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md This endpoint retrieves the trajectory of a specific aircraft. It is experimental and may be out of order. The response includes waypoints with time, position, altitude, track, and on-ground status. ```APIDOC ## GET /tracks/all ### Description Retrieves the trajectory of a specific aircraft. This endpoint is experimental and may be out of order. ### Method GET ### Endpoint https://opensky-network.org/api/tracks/all ### Parameters #### Query Parameters - **icao24** (string) - Required - The ICAO 24-bit address of the transponder. - **time** (integer) - Required - The time in seconds since epoch (Unix time) to retrieve tracks for. Use 0 for live tracks. ### Request Example ```bash curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/tracks/all?icao24=3c4b26&time=0" ``` ### Response #### Success Response (200) - **icao24** (string) - Unique ICAO 24-bit address of the transponder. - **startTime** (integer) - Time of the first waypoint in seconds since epoch. - **endTime** (integer) - Time of the last waypoint in seconds since epoch. - **callsign** (string) - Callsign that holds for the whole track. Can be null. - **path** (array) - An array of waypoints representing the trajectory. - Each waypoint is an array with the following structure: - **time** (integer) - Time in seconds since epoch. - **latitude** (float) - WGS-84 latitude in decimal degrees. Can be null. - **longitude** (float) - WGS-84 longitude in decimal degrees. Can be null. - **baro_altitude** (float) - Barometric altitude in meters. Can be null. - **true_track** (float) - True track in decimal degrees clockwise from north. Can be null. - **on_ground** (boolean) - Indicates if the position was from a surface report. #### Response Example { "icao24": "3c4b26", "startTime": 1678886400, "endTime": 1678890000, "callsign": "D-ABYF", "path": [ [1678886400, 48.3756, 14.5244, 10000.0, 270.0, false], [1678886460, 48.3800, 14.5300, 10050.0, 271.0, false] ] } ### Limitations It is not possible to access flight tracks from more than 30 days in the past. ``` -------------------------------- ### Java Application Proxy Configuration Source: https://github.com/openskynetwork/opensky-api/blob/master/README.md Configure Java system properties to route HTTP traffic through a proxy server. This is necessary when running applications behind a proxy. ```bash java -Dhttp.proxyHost=10.0.0.10 -Dhttp.proxyPort=9090 ... ``` -------------------------------- ### Retrieve All States (Anonymous) Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Use this command to fetch all available flight state data without authentication. The output is piped to `json.tool` for pretty-printing. ```bash $ curl -s "https://opensky-network.org/api/states/all" | python -m json.tool ``` -------------------------------- ### Get Latest Position per Aircraft Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/trino.md Retrieves the most recent state vector for each aircraft within a given hour. This query is useful for tracking the latest known position of all aircraft active during a specific time. ```sql SELECT v.* FROM state_vectors_data4 v JOIN ( SELECT FLOOR(time / 60) AS minute, MAX(time) AS recent, icao24 FROM state_vectors_data4 WHERE hour = 1480762800 GROUP BY icao24, FLOOR(time / 60) ) m ON v.icao24 = m.icao24 AND v.time = m.recent WHERE v.hour = 1480762800; ``` -------------------------------- ### Get Flights by Aircraft Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Retrieves flights for a specific aircraft (identified by its ICAO24 address) within a given time interval. Only flights from the previous day or earlier are available. The interval must not exceed two days. ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/flights/aircraft?icao24=3c675a&begin=1517184000&end=1517270400" | python -m json.tool ``` -------------------------------- ### Retrieve All State Vectors (No Auth) Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/python.md Fetches all current state vectors without authentication. Rate limits apply, so queries should not exceed one every 10 seconds. ```python from opensky_api import OpenSkyApi api = OpenSkyApi() states = api.get_states() for s in states.states: print("(%r, %r, %r, %r)" % (s.longitude, s.latitude, s.baro_altitude, s.velocity)) ``` -------------------------------- ### Arrivals by Airport Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Retrieves flights for a specific airport that arrived within a given time interval. Only arrivals from the previous day or earlier are available. ```APIDOC ## GET /flights/arrival ### Description Retrieve flights for a certain airport which arrived within a given time interval [begin, end]. If no flights are found for the given period, HTTP stats 404 - Not found is returned with an empty response body. NOTE: Similar to flights, arrivals are updated by a batch process at night, i.e., only arrivals from the previous day or earlier are available using this endpoint. ### Method GET ### Endpoint /flights/arrival ### Parameters #### Query Parameters - **airport** (string) - Required - ICAO identifier for the airport - **begin** (integer) - Required - Start of time interval to retrieve flights for as Unix time (seconds since epoch) - **end** (integer) - Required - End of time interval to retrieve flights for as Unix time (seconds since epoch) ### Response #### Success Response (200) - The response is a JSON array of flights where each flight is an object with the following properties: ``` -------------------------------- ### Get Last Position Seen by a Specific Receiver Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/trino.md Finds the last known position of aircraft that were observed by a particular receiver. The query includes a filter to reduce noise from erroneous receiver associations and can be further refined with geographical constraints. ```sql SELECT v.* FROM state_vectors_data4 v JOIN ( SELECT MAX(t.time) AS recent, COUNT(*) AS cnt, t.icao24 FROM state_vectors_data4 t CROSS JOIN UNNEST(t.serials) AS s(item) WHERE t.hour = 1480762800 AND s.item = 1344390019 GROUP BY t.icao24 HAVING COUNT(*) > 30 ) m ON v.icao24 = m.icao24 AND v.time = m.recent WHERE v.hour = 1480762800; ``` -------------------------------- ### API Access as Context Manager Source: https://github.com/openskynetwork/opensky-api/blob/master/python/README.md Utilize the OpenSkyApi client as a context manager. This ensures proper resource management, especially when making multiple requests. ```python with OpenSkyApi(token_manager=TokenManager.from_json_file("credentials.json")) as api: states = api.get_states(bbox=(47.2, 55.1, 5.9, 15.1)) ``` -------------------------------- ### Retrieve Live Aircraft Track Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/python.md Fetches the trajectory of a specific aircraft using its ICAO 24-bit address. Optionally accepts a timestamp for tracking between start and end times. Default timestamp (0) is for live tracking. Cannot access tracks older than 30 days. ```python from opensky_api import OpenSkyApi api = OpenSkyApi() track = api.get_track_by_aircraft("3c4b26") print(track) ``` -------------------------------- ### Retrieve My State Vectors (With Auth) Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/python.md Fetches state vectors from your own receivers using provided username and password. This method bypasses the standard rate limit. ```python from opensky_api import OpenSkyApi api = OpenSkyApi(USERNAME, PASSWORD) states = api.get_my_states() print(states) for s in states.states: print(s.sensors) ``` -------------------------------- ### Retrieve States for Own Sensors Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Fetches the current state information for all sensors registered to your account. Requires an authorization token. ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/states/own" | python -m json.tool ``` -------------------------------- ### Android App Gradle Configuration Source: https://github.com/openskynetwork/opensky-api/blob/master/README.md Configure your Android app's build.gradle file to include the OpenSky API library and specify local repository access. ```gradle dependencies { /* do not delete the other entries, just add this one */ compile 'org.opensky:opensky-api:1.3.0' } repositories { mavenLocal() mavenCentral() } ``` -------------------------------- ### Retrieve States for Multiple Sensors Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Fetches the current state information for multiple sensors by providing their serial numbers. Requires an authorization token. ```bash $ curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/states/own?serials=123456&serials=98765" | python -m json.tool ``` -------------------------------- ### Token Manager for Automatic Refresh (Python) Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md This Python class automatically manages access token retrieval and refresh. Instantiate it once and use its headers() method for authenticated requests. It refreshes tokens proactively before they expire. ```python import requests from datetime import datetime, timedelta TOKEN_URL = "https://auth.opensky-network.org/auth/realms/opensky-network/protocol/openid-connect/token" CLIENT_ID = "your_client_id" CLIENT_SECRET = "your_client_secret" # How many seconds before expiry to proactively refresh the token. TOKEN_REFRESH_MARGIN = 30 class TokenManager: def __init__(self): self.token = None self.expires_at = None def get_token(self): """Return a valid access token, refreshing automatically if needed.""" if self.token and self.expires_at and datetime.now() < self.expires_at: return self.token return self._refresh() def _refresh(self): """Fetch a new access token from the OpenSky authentication server.""" r = requests.post( TOKEN_URL, data={ "grant_type": "client_credentials", "client_id": CLIENT_ID, "client_secret": CLIENT_SECRET, }, ) r.raise_for_status() data = r.json() self.token = data["access_token"] expires_in = data.get("expires_in", 1800) self.expires_at = datetime.now() + timedelta(seconds=expires_in - TOKEN_REFRESH_MARGIN) return self.token def headers(self): """Return request headers with a valid Bearer token.""" return {"Authorization": f"Bearer {self.get_token()}"} # Create a single shared instance for your script. tokens = TokenManager() # Use it for any API call - the token is refreshed automatically. response = requests.get( "https://opensky-network.org/api/states/all", headers=tokens.headers(), ) print(response.json()) ``` -------------------------------- ### Retrieve Airport Arrivals and Departures Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/python.md Fetches arrivals and departures for a specific airport within a given time interval. Requires the airport's ICAO code and timestamps. The interval must be smaller than 7 days. ```python from opensky_api import OpenSkyApi api = OpenSkyApi() arrivals = api.get_arrivals_by_airport("EDDF", 1517227200, 1517230800) departures = api.get_departures_by_airport("EDDF", 1517227200, 1517230800) print("Arrivals:") for flight in arrivals: print(flight) print("Departures:") for flight in departures: print(flight) ``` -------------------------------- ### Retrieve Departures by Airport Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/python.md Fetches departure flight data for a specific airport within a given time interval. The interval must be smaller than 7 days. ```APIDOC ## Retrieve Departures by Airport ### Description Fetches departure flight data for a specific airport within a given time interval. The interval must be smaller than 7 days. ### Method `api.get_departures_by_airport(airport_icao, begin, end)` ### Parameters * **airport_icao** (str) - Required - The ICAO identifier of the airport. * **begin** (int) - Required - The start of the time period as a Unix timestamp. * **end** (int) - Required - The end of the time period as a Unix timestamp. Must be less than 7 days after `begin`. ### Request Example ```python from opensky_api import OpenSkyApi api = OpenSkyApi() departures = api.get_departures_by_airport("EDDF", 1517227200, 1517230800) print("Departures:") for flight in departures: print(flight) ``` ### Response #### Success Response (200) Returns a list of `Flight` objects representing departures from the specified airport. #### Response Example ```json [ { "flight_id": 54321, "callsign": "DLH456", "number": "DLH456", "icao24": "401a2b", "est_departure_airport": "EDDF", "est_arrival_airport": "CDG", "departure_date": "2018-01-29T12:00:00Z", "arrival_date": "2018-01-29T13:30:00Z", "departure_airport_ts": 1517227200, "arrival_airport_ts": 1517232600, "states": [ // ... state vectors for the flight ... ] } ] ``` ``` -------------------------------- ### Own State Vectors Source: https://github.com/openskynetwork/opensky-api/blob/master/docs/free/rest.md Retrieves state vectors for your own sensors without rate limitations. Authentication is required. ```APIDOC ## GET /states/own ### Description Retrieves state vectors for your own sensors without rate limitations. Authentication is required. ### Method GET ### Endpoint https://opensky-network.org/api/states/own ### Parameters #### Query Parameters - **time** (integer) - Optional - The time in seconds since epoch (Unix timestamp) to retrieve states for. Current time will be used if omitted. - **icao24** (string) - Optional - One or more ICAO24 transponder addresses represented by a hex string (e.g. abc9f3). To filter multiple ICAO24 append the property once for each address. If omitted, the state vectors of all aircraft are returned. - **serials** (integer) - Optional - Retrieve only states of a subset of your receivers. You can pass this argument several times to filter state of more than one of your receivers. In this case, the API returns all states of aircraft that are visible to at least one of the given receivers. ### Request Example ```bash curl -H "Authorization: Bearer $TOKEN" -s "https://opensky-network.org/api/states/own?time=1604660000&icao24=3c6444" | python -m json.tool ``` ### Response #### Success Response (200) Returns a JSON object containing state vectors for your own sensors. #### Response Example ```json { "states": [ [ "3c6444", "44c3d0", 1604660000, 1604660000, 48.1374, 11.5755, 123.45, 10000.0, false, 0.0, 0.0, 0.0, 0.0, " கருப்பு " ] ] } ``` ```