Here’s an updated version of your README tailored for a pip-distributed package:
SAS-PRICES-PY is a Python package for interacting with SAS (Scandinavian Airlines) flight pricing APIs. It provides functionality to fetch and process flight data, including round-trip prices for specified origins, destinations, regions, and durations. Designed for efficiency, the package supports asynchronous requests and advanced filtering.
-
Cheapest Round Trips:
- Fetch the cheapest round-trip prices for specific destinations or regions.
- Filter results by origin, destination, and trip start date.
-
Monthly Prices:
- Retrieve monthly outbound and inbound prices for specific origin-destination pairs.
- Calculate combined round-trip prices for selected months.
-
Trips by Length:
- Find the cheapest trips of a specified duration (e.g., 2-day trips).
- Search across all destinations or specific regions.
-
Batch Request Optimization:
- Use asynchronous requests for faster data retrieval when fetching multiple destinations.
-
Error Handling:
- Handle API failures, empty responses, and invalid data gracefully.
Install SAS-PRICES-PY via pip:
pip install sas-prices-py
from sas_prices_py import SAS
sas = SAS(market="gb-en") # Default market: "gb-en"
trips = sas.get_cheapest_round_trips(region="Europe", origin="LHR", start_date="2025-01-01")
print(trips)
monthly_trips = sas.get_monthly_round_trips(origin="LHR", destination="CPH", year_month="202501,202501")
print(monthly_trips)
trips = sas.get_cheapest_trips_by_length(origin="LHR", destination="CPH", year_month="202501,202501", trip_length=2)
print(trips)
trips = sas.get_cheapest_trips_by_length_all_destinations(
origin="LHR", year_month="202501,202501", trip_length=2
)
print(trips)
-
sas_prices_py/api.py
:- Main interface for interacting with SAS APIs.
- Includes methods for fetching cheapest trips, monthly prices, and filtering by trip length.
-
sas_prices_py/sas_monthly.py
:- Handles monthly round-trip price logic.
-
sas_prices_py/sas_cheapest.py
:- Implements fetching the cheapest round trips.
-
sas_prices_py/data.py
:- Defines regions and their destinations.
-
tests/test_api.py
:- Unit tests for package functionality.
To run tests:
python -m unittest discover tests
Example output:
.....
----------------------------------------------------------------------
Ran 5 tests in 0.300s
OK
The following dependencies are required and installed automatically with pip:
requests
aiohttp
brotli
-
Batch Requests:
- Optimized with asynchronous requests to reduce API call latency.
-
Dynamic Filtering:
- Filter by region, origin, destination, and trip duration.
-
Customizable Markets:
- Set the market during initialization (
gb-en
,us-en
, etc.).
- Set the market during initialization (
- Empty responses may occur if no flights are available.
- Network-related errors can slow or fail batch requests; retry mechanisms may improve performance.
This project is licensed under the MIT License. See the LICENSE file for details.
Disclaimer: This project is in no way affiliated with Scandinavian Airlines.
Contributions are welcome! Please submit issues or pull requests via the GitHub repository.
Created by Alex Choi, November 2024.