Python package for fetching SAS flight prices
Project description
SAS-PY: Python Package for Fetching SAS Flight Prices
Overview
SAS-PY is a Python package designed to interact 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. The package enables efficient data retrieval with support for asynchronous requests and custom filtering.
Features
-
Cheapest Round Trips:
- Fetch the cheapest round-trip prices for specific destinations or entire regions.
- Support for filtering 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 given months.
-
Trips by Length:
- Identify the cheapest trips of a specified duration (e.g., 2-day trips).
- Option to search across all destinations or specific regions.
-
Batch Request Optimization:
- Simultaneous fetching of prices for multiple destinations using asynchronous requests for improved performance.
-
Error Handling:
- Gracefully handles API failures, empty responses, and invalid data.
Installation
To install SAS-PY, clone the repository and ensure the required dependencies are installed:
git clone https://github.com/alexechoi/sas-py.git
cd sas-py
pip install -r requirements.txt
Usage
1. Initialize the SAS Client
from sas.api import SAS
sas = SAS(market="gb-en") # Default market: "gb-en"
2. Fetch Cheapest Round Trips
trips = sas.get_cheapest_round_trips(region="Europe", origin="LHR", start_date="2025-01-01")
print(trips)
3. Fetch Monthly Round Trip Prices
monthly_trips = sas.get_monthly_round_trips(origin="LHR", destination="CPH", year_month="202501,202501")
print(monthly_trips)
4. Fetch Cheapest Trips by Length
trips = sas.get_cheapest_trips_by_length(origin="LHR", destination="CPH", year_month="202501,202501", trip_length=2)
print(trips)
5. Fetch Cheapest Trips Across All Destinations
trips = sas.get_cheapest_trips_by_length_all_destinations(
origin="LHR", year_month="202501,202501", trip_length=2
)
print(trips)
Code Structure
-
sas/api.py:- Main interface for fetching data from the SAS API.
- Provides methods for cheapest trips, monthly prices, and filtering by length.
-
sas/sas_monthly.py:- Contains logic to fetch and process monthly round-trip prices.
-
sas/sas_cheapest.py:- Implements fetching the cheapest round trips for multiple destinations.
-
sas/data.py:- Defines available regions and their respective destinations.
-
tests/test_api.py:- Unit tests to validate package functionality.
Example Test Run
To run tests:
python -m unittest discover tests
Example output:
.....
----------------------------------------------------------------------
Ran 5 tests in 0.300s
OK
Dependencies
requestsaiohttpbrotliunittest
Install them using:
pip install -r requirements.txt
Development Notes
Key Features
-
Batch Requests:
- Optimized with asynchronous requests to reduce API call latency.
-
Dynamic Filtering:
- Supports filtering by region, origin, destination, and trip duration.
-
Customizable Markets:
- Set the market during initialization (
gb-en,us-en, etc.).
- Set the market during initialization (
Known Limitations
- The API may return empty responses if no flights are available.
- Network-related errors can slow down or fail batch requests; retry mechanisms may be necessary.
License
This project is licensed under the MIT License. See the LICENSE file for details.
NOTE THAT THIS PROJECT IS IN NO WAY AFFILIATED WITH SCANDINAVIAN AIRLINES
Contributions
Contributions are welcome! Please submit issues or pull requests via the GitHub repository.
Author
Created by Alex Choi, November 2024.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 sas_prices_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sas_prices_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c86550bd116ef4ff0c6566e198f597cc36bffa80724e51c7b132e3628f2aae4a
|
|
| MD5 |
00c3cdb66fc4c1ff1ae8b74100fca3e1
|
|
| BLAKE2b-256 |
758ca2ab27f6e7981786ecd9f7730cdce9def3a67ffeb315e1f3c8994dee9a8b
|