Overview
TheSearchFlights class handles searching for specific flights with detailed filters, parsing the results into structured data models. It interfaces directly with Google Flights’ API to find available flights and their details.
Class initialization
Methods
search
Search for flights using the given filters.FlightSearchFilters
required
Full flight search object including airports, dates, and preferences
int
default:"5"
Number of flights to limit the return flight search to
list[FlightResult | tuple[FlightResult, FlightResult]] | None
For one-way trips: list of
FlightResult objects containing flight detailsFor round-trip: list of tuples containing (outbound FlightResult, return FlightResult) pairsReturns None if no results foundException: If the search fails or returns invalid data
Return types
FlightResult
EachFlightResult object contains:
float
Flight price in the search currency
int
Total flight duration in minutes
int
Number of stops (0 for non-stop)
list[FlightLeg]
List of individual flight leg details
FlightLeg
EachFlightLeg object contains:
Airline
Airline operating the flight leg
str
Flight number (e.g., “AA123”)
Airport
Departure airport code
Airport
Arrival airport code
datetime
Departure date and time
datetime
Arrival date and time
int
Leg duration in minutes
Notes
- For round-trip searches, the method automatically searches for return flights for the top N outbound flights
- The search client includes automatic rate limiting (10 req/sec) and retries
- Prices may be 0.0 if price data is unavailable from the API