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 will soon be available on PyPI. You can install it directly using pip:

pip install virginatlantic

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.0.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.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file virgin-atlantic-0.1.0.tar.gz.

File metadata

  • Download URL: virgin-atlantic-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.12

File hashes

Hashes for virgin-atlantic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9cd7839d62f36747a83d2221a01cd5554008d89f36a5685cd96b8d8b8055909e
MD5 9e4635632b06f8f639a86ab3af59eb6d
BLAKE2b-256 c5e76e7ba5266a3cf945332ab8935be57c170d90476f5ebad741eef8b778cb95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for virgin_atlantic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c423f4de04348bdaf2da80143bfe1bddc6d3ffbf7d1cc558056618c80ac9edbb
MD5 bc815d4b4d18e07497bb59533d4a49d8
BLAKE2b-256 b9dfbdef33de912c82ab1f060d71ad198ccccbd3cc2de3a25a19915cc6c97848

See more details on using hashes here.

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