# 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](https://pypi.org/project/virgin-atlantic/). You can install it directly using pip:
```bash
pip install virgin-atlantic
```
Or clone the repository and install it locally:
```bash
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:
```python
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:
```python
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:
```python
# 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).
```python
# 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:
```python
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:
```python
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](https://github.com/alexechoi)
Raw data
{
"_id": null,
"home_page": "https://github.com/alexechoi/virgin-atlantic-py",
"name": "virgin-atlantic",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Alex Choi",
"author_email": "alexchoidev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d5/56/6fb657d5fde00ef775c7604c6dffca6b79d92350f3d239fc7b1166436e10/virgin_atlantic-0.1.1.tar.gz",
"platform": null,
"description": "# Virgin Atlantic API Python Package\n\nThis 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.\n\n\u26a0\ufe0f **Disclaimer:** This package is not affiliated with Virgin Atlantic.\n\n---\n\n## Features\n\n- Fetch the **flight prices** for a specific route.\n- **Optional origin and destination** for broader searches.\n- Filter flights by **travel class**:\n - Economy\n - Premium\n - Upper Class\n- Sort results by:\n - Popularity\n - Departure Date (Earliest to Latest)\n - Departure Date (Latest to Earliest)\n - Price (Low to High)\n - Price (High to Low)\n- Handle pagination to fetch more results.\n\n---\n\n## Installation\n\nThis package is available on [PyPI](https://pypi.org/project/virgin-atlantic/). You can install it directly using pip:\n\n```bash\npip install virgin-atlantic\n```\n\nOr clone the repository and install it locally:\n\n```bash\ngit clone https://github.com/alexechoi/virgin-atlantic-py.git\ncd virgin-atlantic-py\npip install .\n```\n\n---\n\n## Usage\n\n### Initialize the Client\n\nTo use the package, initialize the `VirginAtlantic` client:\n\n```python\nfrom virginatlantic.api import VirginAtlantic\n\n# Initialize the client\nclient = VirginAtlantic()\n```\n\n---\n\n### Fetch Flight Prices\n\n#### **Basic Example**\nRetrieve flight prices for a specific route and travel class:\n\n```python\nflights = client.get_flight_prices(\n origin=\"LHR\", # London Heathrow\n destination=\"JFK\", # New York JFK\n travel_class=\"ECONOMY\", # Travel class\n sorting=\"PRICE_ASC\", # Sort by price (low to high)\n page_number=1, # First page\n limit=10 # Number of results per page\n)\n\n# Display results\nfor flight in flights:\n print(\n f\"From {flight['origin']} to {flight['destination']}: \"\n f\"{flight['price']} ({flight['departure_date']} to {flight['return_date']}, {flight['travel_class']})\"\n )\n```\n\n#### **Output**\n```\nFrom London to New York: $450 (2024-12-15 to 2024-12-22, Economy)\nFrom London to New York: $470 (2024-12-16 to 2024-12-23, Economy)\n```\n\n---\n\n### Optional Parameters\n\nYou can omit the `origin` or `destination` to fetch all flights departing from or arriving at any location:\n\n```python\n# Flights from any origin to JFK\nflights = client.get_flight_prices(destination=\"JFK\", travel_class=\"PREMIUM\")\n```\n\n---\n\n### Advanced Sorting\n\nSort results using any of the following options:\n- **`POPULAR`**: By popularity.\n- **`DEPARTURE_DATE_ASC`**: Departure date (earliest to latest).\n- **`DEPARTURE_DATE_DESC`**: Departure date (latest to earliest).\n- **`PRICE_ASC`**: Price (low to high).\n- **`PRICE_DESC`**: Price (high to low).\n\n```python\n# Sort by departure date (latest to earliest)\nflights = client.get_flight_prices(\n origin=\"LHR\", destination=\"JFK\", travel_class=\"UPPER CLASS\", sorting=\"DEPARTURE_DATE_DESC\"\n)\n```\n\n---\n\n## Error Handling\n\nThe package raises appropriate errors for invalid inputs:\n\n- **Invalid Travel Class**: Raises a `ValueError` if the travel class is not `ECONOMY`, `PREMIUM`, or `UPPER CLASS`.\n- **Invalid Sorting Option**: Raises a `ValueError` for unrecognized sorting methods.\n- **API Errors**: Raises an `APIError` for network or server-side issues.\n\nExample:\n```python\ntry:\n flights = client.get_flight_prices(\"LHR\", \"JFK\", \"INVALID_CLASS\")\nexcept ValueError as e:\n print(f\"Error: {e}\")\n```\n\n---\n\n## Contributing\n\nContributions are welcome! If you encounter bugs or have suggestions for new features, feel free to open an issue or submit a pull request.\n\n---\n\n## License\n\nThis project is licensed under the MIT License.\n\n---\n\n### Example Code\n\nHere's a full example for quick reference:\n\n```python\nfrom virginatlantic.api import VirginAtlantic\n\ndef main():\n # Initialize the client\n client = VirginAtlantic()\n\n # Fetch flight prices\n flights = client.get_flight_prices(\n origin=\"LHR\", # London Heathrow\n destination=\"JFK\", # New York JFK\n travel_class=\"ECONOMY\", # Travel class\n sorting=\"PRICE_ASC\", # Sort by price (low to high)\n page_number=1, # First page\n limit=5 # Fetch 5 results\n )\n\n # Print the flight details\n print(\"Available flights:\")\n for flight in flights:\n print(\n f\"From {flight['origin']} to {flight['destination']}: \"\n f\"{flight['price']} ({flight['departure_date']} to {flight['return_date']}, {flight['travel_class']})\"\n )\n\nif __name__ == \"__main__\":\n main()\n```\n\n---\n\n### Happy Coding! \ud83d\ude0a - Created by [Alex Choi](https://github.com/alexechoi)\n",
"bugtrack_url": null,
"license": null,
"summary": "A Python package for fetching Virgin Atlantic flight prices.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/alexechoi/virgin-atlantic-py"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "343f644425eaa9f6d1c199f5e9cf93908fed90bedfb3058639960361a872da5e",
"md5": "e29837a7c04b79f82033b4d78ed33c02",
"sha256": "ae02d08c7120d41d2847e05654ea8c1487fd8f591e9715d2da6ddc89f137e312"
},
"downloads": -1,
"filename": "virgin_atlantic-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e29837a7c04b79f82033b4d78ed33c02",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 3812,
"upload_time": "2024-12-01T12:34:53",
"upload_time_iso_8601": "2024-12-01T12:34:53.500996Z",
"url": "https://files.pythonhosted.org/packages/34/3f/644425eaa9f6d1c199f5e9cf93908fed90bedfb3058639960361a872da5e/virgin_atlantic-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d5566fb657d5fde00ef775c7604c6dffca6b79d92350f3d239fc7b1166436e10",
"md5": "b9881dd9ce64fb0a9c352ac21d51672f",
"sha256": "0fa1db49403227cfd63b7b11e3858b6b0d3d3575387fcb2e95e2a3b887136f5b"
},
"downloads": -1,
"filename": "virgin_atlantic-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "b9881dd9ce64fb0a9c352ac21d51672f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 4865,
"upload_time": "2024-12-01T12:35:05",
"upload_time_iso_8601": "2024-12-01T12:35:05.506473Z",
"url": "https://files.pythonhosted.org/packages/d5/56/6fb657d5fde00ef775c7604c6dffca6b79d92350f3d239fc7b1166436e10/virgin_atlantic-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-01 12:35:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "alexechoi",
"github_project": "virgin-atlantic-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "requests",
"specs": [
[
"==",
"2.32.3"
]
]
}
],
"lcname": "virgin-atlantic"
}