Installation
Quick start
Here’s a basic one-way flight search:Core classes
SearchFlights
TheSearchFlights class handles specific flight searches with detailed filters. Use it when you know your travel dates and want to find available flights.
Key features:
- Search one-way or round-trip flights
- Filter by cabin class, stops, airlines, and more
- Set time restrictions for departures and arrivals
- Automatic rate limiting (10 requests/second)
- Built-in retry logic with exponential backoff
- For one-way: List of
FlightResultobjects - For round-trip: List of tuples
(outbound_flight, return_flight)
SearchDates
TheSearchDates class finds the cheapest dates to fly within a date range. Use it for flexible travel planning when you want to find the best prices.
Key features:
- Search across date ranges (up to 305 days in future)
- Automatic chunking for ranges over 61 days
- Filter by cabin class, stops, airlines, and more
- Returns price data for each date in range
- List of
DatePriceobjects containing date and price pairs
Data models
Fli uses Pydantic models for type safety and validation:FlightSearchFilters
Complete search configuration forSearchFlights:
DateSearchFilters
Complete search configuration forSearchDates:
FlightSegment
Defines a single leg of the journey:FlightResult
Contains complete flight information:FlightLeg
Details for a single flight:DatePrice
Price information for specific dates:Enums and filters
Airport
IATA airport codes as enums:Airline
IATA airline codes as enums:SeatType
Cabin class options:MaxStops
Stop preferences:SortBy
Result sorting options:Rate limiting and retries
The library includes automatic rate limiting and retry logic:- Rate limit: 10 requests per second
- Retries: Up to 3 attempts with exponential backoff
- Session management: Persistent HTTP sessions for efficiency
- Browser impersonation: Uses curl-cffi to mimic browser behavior
fli/search/client.py:38-39,62-63.
Error handling
BothSearchFlights and SearchDates raise exceptions on failures:
- Network errors (with retries)
- Rate limit errors (with backoff)
- Invalid API responses
Next steps
SearchFlights
Search for specific flights with detailed filters
SearchDates
Find the cheapest dates to fly
Examples
Explore 11 complete code examples