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.
Currently only supports one-way flights.
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: SearchFlightsFilters) -> list[FlightResult] | None
¶
Search for flights using the provided filters.
PARAMETER | DESCRIPTION |
---|---|
filters
|
Search parameters including airports, dates, and preferences
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[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
SearchFlightsFilters¶
A simplified interface for flight search parameters.
fli.search.flights.SearchFlightsFilters
¶
Bases: BaseModel
Simplified search filters for flight searches.
This model provides a simpler interface compared to the full FlightSearchFilters, focusing on the most common search parameters.
ATTRIBUTE | DESCRIPTION |
---|---|
departure_airport |
Origin airport
TYPE:
|
arrival_airport |
Destination airport
TYPE:
|
departure_date |
Date in YYYY-MM-DD format
TYPE:
|
passenger_info |
Passenger configuration (defaults to 1 adult)
TYPE:
|
seat_type |
Cabin class (defaults to economy)
TYPE:
|
stops |
Maximum stops allowed (defaults to any)
TYPE:
|
sort_by |
Sort criteria (defaults to cheapest)
TYPE:
|
arrival_airport: Airport
instance-attribute
¶
departure_airport: Airport
instance-attribute
¶
departure_date: str
instance-attribute
¶
passenger_info: PassengerInfo = PassengerInfo(adults=1)
class-attribute
instance-attribute
¶
seat_type: SeatType = SeatType.ECONOMY
class-attribute
instance-attribute
¶
sort_by: SortBy = SortBy.CHEAPEST
class-attribute
instance-attribute
¶
stops: MaxStops = MaxStops.ANY
class-attribute
instance-attribute
¶
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/GetCalendarGrid'
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
¶
__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 |
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 |