Python package for fetching SAS flight prices
Project description
Here’s an updated version of your README tailored for a pip-distributed package:
SAS-PRICES-PY: Python Package for Fetching SAS Flight Prices
Overview
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.
⚠️ Disclaimer: This package is in no way affiliated with Scandinavian Airlines.
Features
-
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.
Installation
Install SAS-PRICES-PY via pip:
pip install sas-prices-py
Usage
1. Initialize the SAS Client
from sas_prices_py 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_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.
Example Test Run
To run tests:
python -m unittest discover tests
Example output:
.....
----------------------------------------------------------------------
Ran 5 tests in 0.300s
OK
Dependencies
The following dependencies are required and installed automatically with pip:
requestsaiohttpbrotli
Development Notes
Key Features
-
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 (
Known Limitations
- Empty responses may occur if no flights are available.
- Network-related errors can slow or fail batch requests; retry mechanisms may improve performance.
License
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
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 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 sas_prices_py-0.1.2.tar.gz.
File metadata
- Download URL: sas_prices_py-0.1.2.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ed4bdf8cd46dd7e95b79965c3bb2f5227c388a3ce6af1fb9659076c3d862127
|
|
| MD5 |
5c8e36671a151aa5733dae6604a178d0
|
|
| BLAKE2b-256 |
e0cec40d021ee47906a64d66cae794c1025943c61e7cb79130a88273d2cff80e
|
Provenance
The following attestation bundles were made for sas_prices_py-0.1.2.tar.gz:
Publisher:
python-publish.yml on alexechoi/sas-prices-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sas_prices_py-0.1.2.tar.gz -
Subject digest:
0ed4bdf8cd46dd7e95b79965c3bb2f5227c388a3ce6af1fb9659076c3d862127 - Sigstore transparency entry: 152428784
- Sigstore integration time:
-
Permalink:
alexechoi/sas-prices-py@597546699d48e685dfd4fb342126b68b0617bfb1 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/alexechoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@597546699d48e685dfd4fb342126b68b0617bfb1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sas_prices_py-0.1.2-py3-none-any.whl.
File metadata
- Download URL: sas_prices_py-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d37191215be3c027f47920475816a25f3ecbe3d9d2ead511a7019d71b53011d
|
|
| MD5 |
60e0eccbb30ae1d88b9d14447453ac84
|
|
| BLAKE2b-256 |
83120de33b862d1c03b54b3b8c6bb53512c4db526bb2292048c0cf1c4884d612
|
Provenance
The following attestation bundles were made for sas_prices_py-0.1.2-py3-none-any.whl:
Publisher:
python-publish.yml on alexechoi/sas-prices-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sas_prices_py-0.1.2-py3-none-any.whl -
Subject digest:
7d37191215be3c027f47920475816a25f3ecbe3d9d2ead511a7019d71b53011d - Sigstore transparency entry: 152428785
- Sigstore integration time:
-
Permalink:
alexechoi/sas-prices-py@597546699d48e685dfd4fb342126b68b0617bfb1 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/alexechoi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@597546699d48e685dfd4fb342126b68b0617bfb1 -
Trigger Event:
release
-
Statement type: