Skip to main content
The 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

Search for one-way flights between two airports:
This example comes from examples/basic_one_way_search.py in the source code.
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:
Combine multiple filters for precise results:
This example comes from examples/complex_flight_search.py in the source code.

API reference

SearchFlights class

Defined in fli/search/flights.py:22.

Constructor

Creates a new instance with an initialized HTTP client. The client includes:
  • Automatic rate limiting (10 requests/second)
  • Retry logic with exponential backoff (up to 3 attempts)
  • Browser impersonation for API access

search() method

Parameters:
  • filters (FlightSearchFilters): Complete search configuration including airports, dates, and preferences
  • top_n (int): Number of outbound flights to consider for round-trip searches (default: 5)
Returns:
  • For one-way searches: list[FlightResult] or None
  • For round-trip searches: list[tuple[FlightResult, FlightResult]] or None
  • Returns None if no flights are found
Raises:
  • Exception: If the search fails or returns invalid data
Implementation notes:
  • Round-trip searches make multiple API calls to get return flight options
  • The top_n parameter limits how many outbound flights are used to find returns
  • Results are automatically parsed from Google Flights API response
See implementation at fli/search/flights.py:38-99.

FlightSearchFilters

Complete search configuration object. Required fields:
  • passenger_info (PassengerInfo): Passenger counts
  • flight_segments (list[FlightSegment]): One or more flight segments
Optional fields:
  • trip_type (TripType): ONE_WAY or ROUND_TRIP (default: ONE_WAY)
  • seat_type (SeatType): Cabin class preference
  • stops (MaxStops): Stop preferences
  • airlines (list[Airline]): Filter by specific airlines
  • max_duration (int): Maximum flight duration in minutes
  • sort_by (SortBy): Result sorting preference
  • layover_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 in YYYY-MM-DD format
Optional fields:
  • time_restrictions (TimeRestrictions): Departure/arrival time constraints
  • selected_flight (FlightResult): Pre-selected flight for return searches

FlightResult

Contains complete flight information. Fields:
  • price (float): Total flight price
  • duration (int): Total duration in minutes
  • stops (int): Number of stops (0 for non-stop)
  • legs (list[FlightLeg]): Individual flight legs

FlightLeg

Details for a single flight. Fields:
  • airline (Airline): Operating airline
  • flight_number (str): Flight number
  • departure_airport (Airport): Origin airport
  • arrival_airport (Airport): Destination airport
  • departure_datetime (datetime): Departure time
  • arrival_datetime (datetime): Arrival time
  • duration (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

SearchFlights requires exact travel dates. For flexible date searches, use SearchDates instead.
Always check if results is None before processing. No results doesn’t raise an exception.
Round-trip searches return tuples of (outbound, return) flights. Make sure to unpack them:
Use the top_n parameter to control how many outbound flights are used for round-trip searches:
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