Skip to main content

A Python package for fetching Virgin Atlantic flight prices.

Project description

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 ValueError if the travel class is not ECONOMY, PREMIUM, or UPPER CLASS.
  • Invalid Sorting Option: Raises a ValueError for unrecognized sorting methods.
  • API Errors: Raises an APIError for 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

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

virgin_atlantic-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

virgin_atlantic-0.1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file virgin_atlantic-0.1.1.tar.gz.

File metadata

  • Download URL: virgin_atlantic-0.1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for virgin_atlantic-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0fa1db49403227cfd63b7b11e3858b6b0d3d3575387fcb2e95e2a3b887136f5b
MD5 b9881dd9ce64fb0a9c352ac21d51672f
BLAKE2b-256 d5566fb657d5fde00ef775c7604c6dffca6b79d92350f3d239fc7b1166436e10

See more details on using hashes here.

Provenance

The following attestation bundles were made for virgin_atlantic-0.1.1.tar.gz:

Publisher: python-publish.yml on alexechoi/virgin-atlantic-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file virgin_atlantic-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for virgin_atlantic-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae02d08c7120d41d2847e05654ea8c1487fd8f591e9715d2da6ddc89f137e312
MD5 e29837a7c04b79f82033b4d78ed33c02
BLAKE2b-256 343f644425eaa9f6d1c199f5e9cf93908fed90bedfb3058639960361a872da5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for virgin_atlantic-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on alexechoi/virgin-atlantic-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page