Search API Reference¶
Flight Search¶
The main search functionality for finding specific flights.
SearchFlights¶
fli.search.flights.SearchFlights()
¶
Flight search implementation using Google Flights' API.
This class handles searching for specific flights with detailed filters, parsing the results into structured data models.
Initialize the search client for flight searches.
Source code in fli/search/flights.py
BASE_URL = 'https://www.google.com/_/FlightsFrontendUi/data/travel.frontend.flights.FlightsFrontendService/GetShoppingResults'
class-attribute
instance-attribute
¶
DEFAULT_HEADERS = {'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'}
class-attribute
instance-attribute
¶
client = get_client()
instance-attribute
¶
search(filters: FlightSearchFilters, top_n: int = 5) -> list[FlightResult | tuple[FlightResult, FlightResult]] | None
¶
Search for flights using the given FlightSearchFilters.
PARAMETER | DESCRIPTION |
---|---|
filters
|
Full flight search object including airports, dates, and preferences
TYPE:
|
top_n
|
Number of flights to limit the return flight search to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[FlightResult | tuple[FlightResult, FlightResult]] | None
|
List of FlightResult objects containing flight details, or None if no results |
RAISES | DESCRIPTION |
---|---|
Exception
|
If the search fails or returns invalid data |
Source code in fli/search/flights.py
FlightSearchFilters¶
A simplified interface for flight search parameters.
fli.models.google_flights.FlightSearchFilters
¶
Bases: BaseModel
Complete set of filters for flight search.
This model matches required Google Flights' API structure.
airlines: list[Airline] | None = None
class-attribute
instance-attribute
¶
flight_segments: list[FlightSegment]
instance-attribute
¶
layover_restrictions: LayoverRestrictions | None = None
class-attribute
instance-attribute
¶
max_duration: PositiveInt | None = None
class-attribute
instance-attribute
¶
passenger_info: PassengerInfo
instance-attribute
¶
price_limit: PriceLimit | None = None
class-attribute
instance-attribute
¶
seat_type: SeatType = SeatType.ECONOMY
class-attribute
instance-attribute
¶
sort_by: SortBy = SortBy.NONE
class-attribute
instance-attribute
¶
stops: MaxStops = MaxStops.ANY
class-attribute
instance-attribute
¶
trip_type: TripType = TripType.ONE_WAY
class-attribute
instance-attribute
¶
encode() -> str
¶
URL encode the formatted filters for API request.
Source code in fli/models/google_flights/flights.py
format() -> list
¶
Format filters into Google Flights API structure.
This method converts the FlightSearchFilters model into the specific nested list/dict structure required by Google Flights' API.
The output format matches Google Flights' internal API structure, with careful handling of nested arrays and proper serialization of enums and model objects.
RETURNS | DESCRIPTION |
---|---|
list
|
A formatted list structure ready for the Google Flights API request
TYPE:
|
Source code in fli/models/google_flights/flights.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
Date Search¶
Search functionality for finding the cheapest dates to fly.
SearchDates¶
fli.search.dates.SearchDates()
¶
Date-based flight search implementation.
This class provides methods to search for flight prices across a date range, useful for finding the cheapest dates to fly.
Initialize the search client for date-based searches.
Source code in fli/search/dates.py
BASE_URL = 'https://www.google.com/_/FlightsFrontendUi/data/travel.frontend.flights.FlightsFrontendService/GetCalendarGraph'
class-attribute
instance-attribute
¶
DEFAULT_HEADERS = {'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'}
class-attribute
instance-attribute
¶
MAX_DAYS_PER_SEARCH = 61
class-attribute
instance-attribute
¶
client = get_client()
instance-attribute
¶
__parse_date(item: list[list] | list | None, trip_type: TripType) -> tuple[datetime] | tuple[datetime, datetime]
staticmethod
¶
Parse date data from the API response.
PARAMETER | DESCRIPTION |
---|---|
item
|
Raw date data from the API response
TYPE:
|
trip_type
|
Trip type (one-way or round-trip)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[datetime] | tuple[datetime, datetime]
|
Tuple of datetime objects |
Source code in fli/search/dates.py
__parse_price(item: list[list] | list | None) -> float | None
staticmethod
¶
Parse price data from the API response.
PARAMETER | DESCRIPTION |
---|---|
item
|
Raw price data from the API response
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | None
|
Float price value if valid, None if invalid or missing |
Source code in fli/search/dates.py
search(filters: DateSearchFilters) -> list[DatePrice] | None
¶
Search for flight prices across a date range and search parameters.
PARAMETER | DESCRIPTION |
---|---|
filters
|
Search parameters including date range, airports, and preferences
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[DatePrice] | None
|
List of DatePrice objects containing date and price pairs, or None if no results |
RAISES | DESCRIPTION |
---|---|
Exception
|
If the search fails or returns invalid data |
Notes
- For date ranges larger than 61 days, splits into multiple searches.
- We can't search more than 305 days in the future.
Source code in fli/search/dates.py
DatePrice¶
fli.search.dates.DatePrice
¶
Examples¶
Basic Flight Search¶
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¶
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()
¶
HTTP client with built-in rate limiting, retry and user agent impersonation functionality.
Initialize a new client session with default headers.
Source code in fli/search/client.py
DEFAULT_HEADERS = {'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'}
class-attribute
instance-attribute
¶
__del__()
¶
get(url: str, **kwargs) -> requests.Response
¶
Make a rate-limited GET request with automatic retries.
PARAMETER | DESCRIPTION |
---|---|
url
|
Target URL for the request
TYPE:
|
**kwargs
|
Additional arguments passed to requests.get()
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Response
|
Response object from the server |
RAISES | DESCRIPTION |
---|---|
Exception
|
If request fails after all retries |
Source code in fli/search/client.py
post(url: str, **kwargs) -> requests.Response
¶
Make a rate-limited POST request with automatic retries.
PARAMETER | DESCRIPTION |
---|---|
url
|
Target URL for the request
TYPE:
|
**kwargs
|
Additional arguments passed to requests.post()
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Response
|
Response object from the server |
RAISES | DESCRIPTION |
---|---|
Exception
|
If request fails after all retries |