Virgin Atlantic API Python Package
This Python package provides an interface to fetch data from the Virgin Atlantic API. It supports retrieving flight prices with various filters such as travel class, sorting options, and pagination. The package handles GraphQL queries to fetch and parse the flight data for user-friendly usage.
⚠️ Disclaimer: This package is not affiliated with Virgin Atlantic.
Features
- Fetch the flight prices for a specific route.
- Optional origin and destination for broader searches.
- Filter flights by travel class:
- Economy
- Premium
- Upper Class
- Sort results by:
- Popularity
- Departure Date (Earliest to Latest)
- Departure Date (Latest to Earliest)
- Price (Low to High)
- Price (High to Low)
- Handle pagination to fetch more results.
Installation
This package is available on PyPI. You can install it directly using pip:
pip install virgin-atlantic
Or clone the repository and install it locally:
git clone https://github.com/alexechoi/virgin-atlantic-py.git
cd virgin-atlantic-py
pip install .
Usage
Initialize the Client
To use the package, initialize the VirginAtlantic client:
from virginatlantic.api import VirginAtlantic
# Initialize the client
client = VirginAtlantic()
Fetch Flight Prices
Basic Example
Retrieve flight prices for a specific route and travel class:
flights = client.get_flight_prices(
origin="LHR", # London Heathrow
destination="JFK", # New York JFK
travel_class="ECONOMY", # Travel class
sorting="PRICE_ASC", # Sort by price (low to high)
page_number=1, # First page
limit=10 # Number of results per page
)
# Display results
for flight in flights:
print(
f"From {flight['origin']} to {flight['destination']}: "
f"{flight['price']} ({flight['departure_date']} to {flight['return_date']}, {flight['travel_class']})"
)
Output
From London to New York: $450 (2024-12-15 to 2024-12-22, Economy)
From London to New York: $470 (2024-12-16 to 2024-12-23, Economy)
Optional Parameters
You can omit the origin or destination to fetch all flights departing from or arriving at any location:
# Flights from any origin to JFK
flights = client.get_flight_prices(destination="JFK", travel_class="PREMIUM")
Advanced Sorting
Sort results using any of the following options:
POPULAR: By popularity.DEPARTURE_DATE_ASC: Departure date (earliest to latest).DEPARTURE_DATE_DESC: Departure date (latest to earliest).PRICE_ASC: Price (low to high).PRICE_DESC: Price (high to low).
# Sort by departure date (latest to earliest)
flights = client.get_flight_prices(
origin="LHR", destination="JFK", travel_class="UPPER CLASS", sorting="DEPARTURE_DATE_DESC"
)
Error Handling
The package raises appropriate errors for invalid inputs:
- Invalid Travel Class: Raises a
ValueErrorif the travel class is notECONOMY,PREMIUM, orUPPER CLASS. - Invalid Sorting Option: Raises a
ValueErrorfor unrecognized sorting methods. - API Errors: Raises an
APIErrorfor network or server-side issues.
Example:
try:
flights = client.get_flight_prices("LHR", "JFK", "INVALID_CLASS")
except ValueError as e:
print(f"Error: {e}")
Contributing
Contributions are welcome! If you encounter bugs or have suggestions for new features, feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License.
Example Code
Here's a full example for quick reference:
from virginatlantic.api import VirginAtlantic
def main():
# Initialize the client
client = VirginAtlantic()
# Fetch flight prices
flights = client.get_flight_prices(
origin="LHR", # London Heathrow
destination="JFK", # New York JFK
travel_class="ECONOMY", # Travel class
sorting="PRICE_ASC", # Sort by price (low to high)
page_number=1, # First page
limit=5 # Fetch 5 results
)
# Print the flight details
print("Available flights:")
for flight in flights:
print(
f"From {flight['origin']} to {flight['destination']}: "
f"{flight['price']} ({flight['departure_date']} to {flight['return_date']}, {flight['travel_class']})"
)
if __name__ == "__main__":
main()
Happy Coding! 😊 - Created by Alex Choi
Metadata
Release files for virgin-atlantic 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| virgin_atlantic-0.1.1.tar.gz | 4.9 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| virgin_atlantic-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / virgin_atlantic-0.1.1.tar.gz
| Download URL | virgin_atlantic-0.1.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0fa1db49403227cfd63b7b11e3858b6b0d3d3575387fcb2e95e2a3b887136f5b
|
|
BLAKE2b-256 checksum How to use checksums |
d5566fb657d5fde00ef775c7604c6dffca6b79d92350f3d239fc7b1166436e10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2024.
Transparency logRelease files / virgin_atlantic-0.1.1-py3-none-any.whl
| Download URL | virgin_atlantic-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae02d08c7120d41d2847e05654ea8c1487fd8f591e9715d2da6ddc89f137e312
|
|
BLAKE2b-256 checksum How to use checksums |
343f644425eaa9f6d1c199f5e9cf93908fed90bedfb3058639960361a872da5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2024.
Transparency logSecurity for virgin-atlantic 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for virgin_atlantic-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.