SearchFlights class provides direct access to Google Flights data for specific travel dates. It supports one-way and round-trip searches with comprehensive filtering options.
Basic usage
One-way search
Search for one-way flights between two airports:This example comes from
examples/basic_one_way_search.py in the source code.Round-trip search
Search for round-trip flights with outbound and return segments:This example comes from
examples/round_trip_search.py in the source code.Advanced filtering
Time restrictions
Filter flights by departure and arrival times:See
examples/time_restrictions_search.py for a complete working example.Multiple passengers
Search for family travel with multiple passenger types:Airline preferences
Filter by specific airlines:Layover restrictions
Control layover airports and duration:Complex search
Combine multiple filters for precise results:This example comes from
examples/complex_flight_search.py in the source code.API reference
SearchFlights class
Defined infli/search/flights.py:22.
Constructor
- Automatic rate limiting (10 requests/second)
- Retry logic with exponential backoff (up to 3 attempts)
- Browser impersonation for API access
search() method
filters(FlightSearchFilters): Complete search configuration including airports, dates, and preferencestop_n(int): Number of outbound flights to consider for round-trip searches (default: 5)
- For one-way searches:
list[FlightResult]orNone - For round-trip searches:
list[tuple[FlightResult, FlightResult]]orNone - Returns
Noneif no flights are found
Exception: If the search fails or returns invalid data
- Round-trip searches make multiple API calls to get return flight options
- The
top_nparameter limits how many outbound flights are used to find returns - Results are automatically parsed from Google Flights API response
fli/search/flights.py:38-99.
FlightSearchFilters
Complete search configuration object. Required fields:passenger_info(PassengerInfo): Passenger countsflight_segments(list[FlightSegment]): One or more flight segments
trip_type(TripType):ONE_WAYorROUND_TRIP(default:ONE_WAY)seat_type(SeatType): Cabin class preferencestops(MaxStops): Stop preferencesairlines(list[Airline]): Filter by specific airlinesmax_duration(int): Maximum flight duration in minutessort_by(SortBy): Result sorting preferencelayover_restrictions(LayoverRestrictions): Layover preferences
FlightSegment
Defines a single journey segment. Required fields:departure_airport(list[list]): Origin airport as[[Airport.CODE, 0]]arrival_airport(list[list]): Destination airport as[[Airport.CODE, 0]]travel_date(str): Date inYYYY-MM-DDformat
time_restrictions(TimeRestrictions): Departure/arrival time constraintsselected_flight(FlightResult): Pre-selected flight for return searches
FlightResult
Contains complete flight information. Fields:price(float): Total flight priceduration(int): Total duration in minutesstops(int): Number of stops (0 for non-stop)legs(list[FlightLeg]): Individual flight legs
FlightLeg
Details for a single flight. Fields:airline(Airline): Operating airlineflight_number(str): Flight numberdeparture_airport(Airport): Origin airportarrival_airport(Airport): Destination airportdeparture_datetime(datetime): Departure timearrival_datetime(datetime): Arrival timeduration(int): Flight duration in minutes
Result processing
Process and analyze search results with custom logic:See
examples/result_processing.py for comprehensive analysis examples including pandas integration.Error handling
Implement robust error handling for production use:The HTTP client already includes retry logic at
fli/search/client.py:39,63. See examples/error_handling_with_retries.py for advanced patterns using tenacity.Best practices
Use specific dates
Use specific dates
SearchFlights requires exact travel dates. For flexible date searches, use SearchDates instead.
Handle None results
Handle None results
Always check if results is
None before processing. No results doesn’t raise an exception.Round-trip result structure
Round-trip result structure
Round-trip searches return tuples of
(outbound, return) flights. Make sure to unpack them:Limit round-trip combinations
Limit round-trip combinations
Use the
top_n parameter to control how many outbound flights are used for round-trip searches:Date format
Date format
Always use
YYYY-MM-DD format for dates:Examples
Explore complete working examples:Basic one-way search
Simple flight search between two airports
Round-trip search
Search for outbound and return flights
Complex flight search
Multi-filter search with layovers and preferences
Time restrictions
Filter by departure and arrival times
Next steps
SearchDates
Find the cheapest dates to fly
All examples
Browse 11 complete code examples