Skip to content

armgit / fli

Public Imported from GitHub
0

Google Flights MCP, CLI and Python Library

Add docs

Punit Arani6fc0ab5aee13
diff --git a/docs/api/models.md b/docs/api/models.md
new file mode 100644
index 0000000..adde5e2
--- /dev/null
+++ b/docs/api/models.md
@@ -0,0 +1,74 @@
+# Models Reference
+
+## Core Models
+
+### FlightSearchFilters
+
+The main model for configuring flight searches.
+
+```python
+from fli.models import FlightSearchFilters, SeatType, MaxStops, SortBy
+
+filters = FlightSearchFilters(
+ trip_type=TripType.ONE_WAY,
+ passenger_info=PassengerInfo(adults=1),
+ flight_segments=[...],
+ stops=MaxStops.NON_STOP,
+ seat_type=SeatType.ECONOMY,
+ sort_by=SortBy.CHEAPEST
+)
+```
+
+::: fli.models.google_flights.FlightSearchFilters
+
+### FlightResult
+
+Represents a flight search result with complete details.
+
+::: fli.models.google_flights.FlightResult
+
+### FlightLeg
+
+Represents a single flight segment with airline and timing details.
+
+::: fli.models.google_flights.FlightLeg
+
+## Enums
+
+### SeatType
+
+Available cabin classes for flights.
+
+::: fli.models.google_flights.SeatType
+
+### MaxStops
+
+Maximum number of stops allowed in flight search.
+
+::: fli.models.google_flights.MaxStops
+
+### SortBy
+
+Available sorting options for flight results.
+
+::: fli.models.google_flights.SortBy
+
+## Support Models
+
+### PassengerInfo
+
+Configuration for passenger counts.
+
+::: fli.models.google_flights.PassengerInfo
+
+### TimeRestrictions
+
+Time constraints for flight departure and arrival.
+
+::: fli.models.google_flights.TimeRestrictions
+
+### PriceLimit
+
+Price constraints for flight search.
+
+::: fli.models.google_flights.PriceLimit
\ No newline at end of file
diff --git a/docs/api/search.md b/docs/api/search.md
new file mode 100644
index 0000000..e0b6e8a
--- /dev/null
+++ b/docs/api/search.md
@@ -0,0 +1,75 @@
+# Search API Reference
+
+## Flight Search
+
+The main search functionality for finding specific flights.
+
+### SearchFlights
+
+::: fli.search.flights.SearchFlights
+
+### SearchFlightsFilters
+
+A simplified interface for flight search parameters.
+
+::: fli.search.flights.SearchFlightsFilters
+
+## Date Search
+
+Search functionality for finding the cheapest dates to fly.
+
+### SearchDates
+
+::: fli.search.dates.SearchDates
+
+### DatePrice
+
+::: fli.search.dates.DatePrice
+
+## Examples
+
+### Basic Flight Search
+
+```python
+from fli.search import SearchFlights, SearchFlightsFilters
+from fli.models import Airport, SeatType
+
+# Create filters
+filters = SearchFlightsFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LAX,
+ departure_date="2024-06-01",
+ seat_type=SeatType.ECONOMY
+)
+
+# Search flights
+search = SearchFlights()
+results = search.search(filters)
+```
+
+### Date Range Search
+
+```python
+from fli.search import SearchDates
+from fli.models import DateSearchFilters, Airport
+
+# Create filters
+filters = DateSearchFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LAX,
+ from_date="2024-06-01",
+ to_date="2024-06-30"
+)
+
+# Search dates
+search = SearchDates()
+results = search.search(filters)
+```
+
+## HTTP Client
+
+The underlying HTTP client used for API requests.
+
+### Client
+
+::: fli.search.client.Client
\ No newline at end of file
diff --git a/docs/examples/advanced.md b/docs/examples/advanced.md
new file mode 100644
index 0000000..f37707f
--- /dev/null
+++ b/docs/examples/advanced.md
@@ -0,0 +1,182 @@
+# Advanced Examples
+
+## Complex Flight Search
+
+### Search with Multiple Filters
+
+```python
+from fli.models import (
+ Airport, Airline, SeatType, MaxStops,
+ PassengerInfo, TimeRestrictions, LayoverRestrictions
+)
+from fli.search import SearchFlights, SearchFlightsFilters
+
+# Create detailed filters
+filters = SearchFlightsFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LHR,
+ departure_date="2024-06-01",
+ passenger_info=PassengerInfo(
+ adults=2,
+ children=1,
+ infants_on_lap=1
+ ),
+ seat_type=SeatType.BUSINESS,
+ stops=MaxStops.ONE_STOP_OR_FEWER,
+ airlines=[Airline.BA, Airline.VS], # British Airways and Virgin Atlantic
+ max_duration=720, # 12 hours in minutes
+ layover_restrictions=LayoverRestrictions(
+ airports=[Airport.BOS, Airport.ORD], # Prefer these layover airports
+ max_duration=180 # Maximum 3-hour layover
+ )
+)
+
+search = SearchFlights()
+results = search.search(filters)
+```
+
+### Search with Time Restrictions
+
+```python
+from fli.models import TimeRestrictions
+from fli.search import SearchFlights, SearchFlightsFilters
+
+# Create filters with time restrictions
+filters = SearchFlightsFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LAX,
+ departure_date="2024-06-01",
+ flight_segments=[
+ FlightSegment(
+ departure_airport=[[Airport.JFK, 0]],
+ arrival_airport=[[Airport.LAX, 0]],
+ travel_date="2024-06-01",
+ time_restrictions=TimeRestrictions(
+ earliest_departure=6, # 6 AM
+ latest_departure=10, # 10 AM
+ earliest_arrival=12, # 12 PM
+ latest_arrival=18 # 6 PM
+ )
+ )
+ ]
+)
+
+search = SearchFlights()
+results = search.search(filters)
+```
+
+## Advanced Date Search
+
+### Search with Day Preferences
+
+```python
+from datetime import datetime, timedelta
+from fli.models import DateSearchFilters, Airport, SeatType
+
+# Create filters for weekends only
+filters = DateSearchFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LAX,
+ from_date="2024-06-01",
+ to_date="2024-06-30",
+ seat_type=SeatType.PREMIUM_ECONOMY
+)
+
+search = SearchDates()
+results = search.search(filters)
+
+# Filter for weekends only
+weekend_results = [
+ r for r in results
+ if r.date.weekday() >= 5 # Saturday = 5, Sunday = 6
+]
+```
+
+### Price Tracking Over Time
+
+```python
+import time
+from fli.models import DateSearchFilters, Airport
+from fli.search import SearchDates
+
+
+def track_prices(days=7):
+ filters = DateSearchFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LAX,
+ from_date="2024-06-01",
+ to_date="2024-06-07"
+ )
+
+ search = SearchDates()
+ price_history = {}
+
+ for _ in range(days):
+ results = search.search(filters)
+
+ # Store prices
+ for result in results:
+ date_str = result.date.strftime("%Y-%m-%d")
+ if date_str not in price_history:
+ price_history[date_str] = []
+ price_history[date_str].append(result.price)
+
+ # Wait for next check
+ time.sleep(86400) # Wait 24 hours
+
+ return price_history
+```
+
+## Error Handling
+
+### Handling Rate Limits and Retries
+
+```python
+from fli.search import SearchFlights, SearchFlightsFilters
+from tenacity import retry, stop_after_attempt, wait_exponential
+
+
+@retry(stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=4, max=60))
+def search_with_retry(filters: SearchFlightsFilters):
+ search = SearchFlights()
+ try:
+ results = search.search(filters)
+ if not results:
+ raise ValueError("No results found")
+ return results
+ except Exception as e:
+ print(f"Search failed: {str(e)}")
+ raise # Retry will handle this
+```
+
+## Working with Results
+
+### Custom Result Processing
+
+```python
+from fli.models import FlightResult
+from typing import List
+import pandas as pd
+
+
+def analyze_results(results: List[FlightResult]) -> pd.DataFrame:
+ """Convert results to pandas DataFrame for analysis."""
+ flights_data = []
+
+ for flight in results:
+ for leg in flight.legs:
+ flights_data.append({
+ 'price': flight.price,
+ 'total_duration': flight.duration,
+ 'stops': flight.stops,
+ 'airline': leg.airline.value,
+ 'flight_number': leg.flight_number,
+ 'departure_airport': leg.departure_airport.value,
+ 'arrival_airport': leg.arrival_airport.value,
+ 'departure_time': leg.departure_datetime,
+ 'arrival_time': leg.arrival_datetime,
+ 'leg_duration': leg.duration
+ })
+
+ return pd.DataFrame(flights_data)
+```
\ No newline at end of file
diff --git a/docs/guides/quickstart.md b/docs/guides/quickstart.md
new file mode 100644
index 0000000..d44f0f5
--- /dev/null
+++ b/docs/guides/quickstart.md
@@ -0,0 +1,100 @@
+# Quick Start Guide
+
+This guide will help you get started with Fli quickly.
+
+## Installation
+
+### For Python Usage
+
+```bash
+pip install git+https://github.com/punitarani/fli.git
+```
+
+### For CLI Usage
+
+```bash
+pipx install git+https://github.com/punitarani/fli.git
+```
+
+## Basic Usage
+
+### Command Line Interface
+
+1. Search for flights on a specific date:
+
+```bash
+fli search JFK LHR 2024-06-01
+```
+
+2. Search with filters:
+
+```bash
+fli search JFK LHR 2024-06-01 \
+ -t 6-20 \ # Time range (6 AM - 8 PM)
+ -a BA KL \ # Airlines (British Airways, KLM)
+ -s BUSINESS \ # Seat type
+ -x NON_STOP # Non-stop flights only
+```
+
+3. Find cheapest dates:
+
+```bash
+fli cheap JFK LHR --from 2024-06-01 --to 2024-06-30
+```
+
+### Python API
+
+1. Basic Flight Search:
+
+```python
+from fli.search import SearchFlights, SearchFlightsFilters
+from fli.models import Airport, SeatType
+
+# Create filters
+filters = SearchFlightsFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LAX,
+ departure_date="2024-06-01",
+ seat_type=SeatType.ECONOMY
+)
+
+# Search flights
+search = SearchFlights()
+results = search.search(filters)
+
+# Process results
+for flight in results:
+ print(f"Price: ${flight.price}")
+ print(f"Duration: {flight.duration} minutes")
+ for leg in flight.legs:
+ print(f"Flight: {leg.airline.value} {leg.flight_number}")
+```
+
+2. Date Range Search:
+
+```python
+from fli.search import SearchDates
+from fli.models import DateSearchFilters, Airport
+
+# Create filters
+filters = DateSearchFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LAX,
+ from_date="2024-06-01",
+ to_date="2024-06-30"
+)
+
+# Search dates
+search = SearchDates()
+results = search.search(filters)
+
+# Process results
+for date_price in results:
+ print(f"Date: {date_price.date}, Price: ${date_price.price}")
+```
+
+## Next Steps
+
+- Check out the [API Reference](../api/models.md) for detailed documentation
+- See [Advanced Examples](../examples/advanced.md) for more complex use cases
+- Read about [Rate Limiting and Error Handling](../api/search.md#http-client)
\ No newline at end of file
diff --git a/docs/index.md b/docs/index.md
new file mode 100644
index 0000000..d50b503
--- /dev/null
+++ b/docs/index.md
@@ -0,0 +1,99 @@
+# Welcome to Fli Documentation
+
+Fli is a powerful Python library that provides direct access to Google Flights' API through reverse engineering. Unlike
+other flight search libraries that rely on web scraping, Fli offers a clean, fast, and reliable way to search for
+flights and analyze pricing data.
+
+## Key Features
+
+### πŸš€ Direct API Access
+
+- No web scraping or browser automation
+- Fast and reliable results
+- Less prone to breaking from UI changes
+- Clean, modular architecture
+
+### πŸ” Search Capabilities
+
+- One-way flight searches
+- Flexible departure times
+- Multi-airline support
+- Various cabin classes
+- Stop preferences
+- Custom result sorting
+
+### πŸ’° Price Analysis
+
+- Search across date ranges
+- Find cheapest dates to fly
+- Price tracking and analysis
+- Flexible date options
+
+## Quick Start
+
+### Installation
+
+```bash
+# Install using pip
+pip install git+https://github.com/punitarani/fli.git
+
+# Or install using pipx (recommended for CLI usage)
+pipx install git+https://github.com/punitarani/fli.git
+```
+
+### Basic Usage
+
+```python
+from datetime import datetime, timedelta
+from fli.models import Airport, PassengerInfo, SeatType, MaxStops, SortBy
+from fli.search import SearchFlights, SearchFlightsFilters
+
+# Create search filters
+filters = SearchFlightsFilters(
+ departure_airport=Airport.JFK,
+ arrival_airport=Airport.LAX,
+ departure_date=(datetime.now() + timedelta(days=30)).strftime("%Y-%m-%d"),
+ passenger_info=PassengerInfo(adults=1),
+ seat_type=SeatType.ECONOMY,
+ stops=MaxStops.NON_STOP,
+ sort_by=SortBy.CHEAPEST,
+)
+
+# Search flights
+search = SearchFlights()
+flights = search.search(filters)
+
+# Process results
+for flight in flights:
+ print(f"πŸ’° Price: ${flight.price}")
+ print(f"⏱️ Duration: {flight.duration} minutes")
+ print(f"✈️ Stops: {flight.stops}")
+```
+
+## Project Structure
+
+The library is organized into several key modules:
+
+- `models/`: Data models and enums
+ - `google_flights.py`: Core data models
+ - `airline.py`: Airline enums and data
+ - `airport.py`: Airport enums and data
+
+- `search/`: Search functionality
+ - `flights.py`: Flight search implementation
+ - `dates.py`: Date-based price search
+ - `client.py`: HTTP client with rate limiting
+
+## Contributing
+
+We welcome contributions! Here's how you can help:
+
+1. Fork the repository
+2. Create a feature branch
+3. Make your changes
+4. Run tests: `poetry run pytest`
+5. Submit a pull request
+
+## License
+
+This project is licensed under the MIT License. See the LICENSE file for details.
\ No newline at end of file