Python SDK for the Flightradar24 API
Project description
Flightradar24 Python SDK
Official Python SDK for the Flightradar24 API.
Features
- Access to all Flightradar24 API v1 endpoints.
- Intuitive client interface:
client.airports.get_full("WAW") - Typed responses.
- Robust error handling with custom exceptions.
- Synchronous client (async coming soon).
- Lightweight input validation for common parameters.
Installation
Release Version
Using uv:
uv pip install fr24sdk
Using pip:
pip install fr24sdk
SDK Usage Guide
This guide provides a comprehensive overview of how to use the fr24sdk to interact with the Flightradar24 API.
1. Client Initialization
The Client is your main entry point to the API.
Using Environment Variable:
Ensure your API token is set as an environment variable FR24_API_TOKEN.
export FR24_API_TOKEN="your_actual_token_here" # On Linux/macOS
# set FR24_API_TOKEN=your_actual_token_here # On Windows Command Prompt
# $Env:FR24_API_TOKEN="your_actual_token_here" # On Windows PowerShell
Then, initialize the client:
from fr24sdk.client import Client
client = Client()
Passing Token Directly: You can also pass the API token directly during client initialization.
client = Client(api_token="your_actual_token_here")
Using as a Context Manager: This ensures the underlying HTTP client is closed properly.
from fr24sdk.client import Client
with Client() as client:
client.flight_summary(flight_ids="")
pass
2. Accessing API Resources
The client provides access to different API resources as attributes. For example:
client.airlines: Fetch airline details.client.airports: Fetch airport details.client.live: Get live flight data, including flights within specific geographical bounds.client.historic: Query historic flight information.client.flight_summary: Retrieve summaries for specific flights.client.flight_tracks: Access flight track data.client.usage: Check your API usage statistics.
Each resource object then has methods to fetch data related to that resource.
3. Resource Examples
The SDK provides intuitive access to various API resources. Here's how you can typically interact with them:
a. Fetching Airport Details
This example demonstrates fetching detailed information for an airport (e.g., Warsaw Chopin Airport - WAW) and accessing its attributes.
from fr24sdk.client import Client
from fr24sdk.exceptions import ApiError
# Initialize client (ensure FR24_API_TOKEN is set or pass api_token="your_token")
client = Client()
airport_iata = "WAW"
print(f"Fetching full details for airport: {airport_iata}")
airport_details = client.airports.get_full(airport_iata)
if airport_details:
print(f" Name: {airport_details.name}")
print(f" ICAO: {airport_details.icao}")
print(f" City: {airport_details.city}")
print(f" Country: {airport_details.country_name}")
print(f" Latitude: {airport_details.lat}")
print(f" Longitude: {airport_details.lon}")
b. Other Available Resources
The client provides access to a comprehensive set of Flightradar24 API resources, including but not limited to:
client.airlines: Fetch airline details.client.live: Get live flight data, including flights within specific geographical bounds.client.flight_summary: Retrieve summaries for specific flights.client.flight_tracks: Access flight track data.client.historic: Query historic flight information.client.usage: Check your API usage statistics.
Each of these resources offers methods to interact with the corresponding API endpoints. For example, you might use client.live.get_flights(...) or client.airlines.get_by_iata(...). Please refer to the SDK's source code or future detailed documentation for specific method signatures and parameters.
4. Handling Responses
API methods return Python objects that represent the JSON response from the API. You can access data using dot notation, as shown in the examples.
# Example with AirportFull object
# waw_full = client.airports.get_full("WAW")
# print(waw_full.name)
# print(waw_full.timezone_name)
5. Error Handling
The SDK uses custom exceptions to indicate errors. The base exception is Fr24SdkError. More specific errors like ApiError, AuthenticationError, RateLimitError, etc., inherit from it.
import os
from fr24sdk.client import Client
from fr24sdk.exceptions import ApiError, AuthenticationError, Fr24SdkError # Import relevant exceptions
# Assumes FR24_API_TOKEN is set, or pass it to Client()
try:
with Client() as client:
# Example: Intentionally try to get a non-existent airport
airport = client.airports.get_full("INVALID_IATA")
if airport:
print(airport.name)
except AuthenticationError:
print("Authentication failed. Please check your API token.")
except ApiError as e:
print(f"API Error occurred: Status {e.status}, Message: {e.message}")
print(f"Request URL: {e.request_url}")
if e.body:
print(f"Response body: {e.body}")
except Fr24SdkError as e:
print(f"An SDK-specific error occurred: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
6. Closing the Client
If you are not using the client as a context manager (with Client() as client:), you should explicitly close it to release resources:
client = Client()
# ... use client ...
client.close()
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fr24sdk-0.3.0.tar.gz.
File metadata
- Download URL: fr24sdk-0.3.0.tar.gz
- Upload date:
- Size: 120.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d1227f517e18e15e817d184a7584e81d442fe03b0209e59cf25d27628dc9757
|
|
| MD5 |
5b4ed12fcdfdbeff0d693633c2e1f06b
|
|
| BLAKE2b-256 |
35b8717d41cb3dab98d44954c6a2dc0de0b7cac663f8e6ac60aeb07de1a61626
|
Provenance
The following attestation bundles were made for fr24sdk-0.3.0.tar.gz:
Publisher:
publish.yaml on Flightradar24/fr24api-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fr24sdk-0.3.0.tar.gz -
Subject digest:
1d1227f517e18e15e817d184a7584e81d442fe03b0209e59cf25d27628dc9757 - Sigstore transparency entry: 724905061
- Sigstore integration time:
-
Permalink:
Flightradar24/fr24api-sdk-python@73e2f9ec3bd46b584f7f4c44df825a54da6eff7d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Flightradar24
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@73e2f9ec3bd46b584f7f4c44df825a54da6eff7d -
Trigger Event:
release
-
Statement type:
File details
Details for the file fr24sdk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: fr24sdk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 28.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
502a6b60294cd87d5c388c5fb45bc5a506525f8fd0d25db39d218ae9f7b7717a
|
|
| MD5 |
588d0bc3c7b1899affee043d2c883961
|
|
| BLAKE2b-256 |
a932563acb6475cd6a7c85efb47820f89a5429fe612129cd7a08eaca0c34a1d8
|
Provenance
The following attestation bundles were made for fr24sdk-0.3.0-py3-none-any.whl:
Publisher:
publish.yaml on Flightradar24/fr24api-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fr24sdk-0.3.0-py3-none-any.whl -
Subject digest:
502a6b60294cd87d5c388c5fb45bc5a506525f8fd0d25db39d218ae9f7b7717a - Sigstore transparency entry: 724905064
- Sigstore integration time:
-
Permalink:
Flightradar24/fr24api-sdk-python@73e2f9ec3bd46b584f7f4c44df825a54da6eff7d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Flightradar24
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@73e2f9ec3bd46b584f7f4c44df825a54da6eff7d -
Trigger Event:
release
-
Statement type: