Skip to main content
This page showcases all 11 example files from the examples/ directory. Each example is a complete, runnable Python script that demonstrates specific features of the Fli library.

Running examples

Basic examples

File: examples/basic_one_way_search.py Demonstrates the simplest flight search between two airports on a specific date. Shows core API usage with basic filters. Features:
  • Single passenger search
  • Non-stop flights filter
  • Economy class
  • Sort by cheapest price
  • Result processing and display
File: examples/round_trip_search.py Shows how to search for round-trip flights with outbound and return segments. Demonstrates handling the tuple structure of round-trip results. Features:
  • Two flight segments (outbound and return)
  • Round-trip trip type
  • Combined price calculation
  • Tuple unpacking for results
File: examples/date_range_search.py Demonstrates searching across a date range to find the cheapest dates to fly. Features:
  • SearchDates for flexible date searching
  • 30-day date range
  • DatePrice result processing

Advanced examples

File: examples/complex_flight_search.py Demonstrates advanced filtering with multiple passengers, airline preferences, layover restrictions, and more. Features:
  • Multiple passenger types (adults, children, infants)
  • Business class search
  • Airline filtering (British Airways and Virgin Atlantic)
  • Maximum duration limit
  • Layover restrictions (preferred airports and max duration)
  • Detailed result display
See the full code in examples/complex_flight_search.py. This example shows how to combine multiple filters for precise search requirements.
File: examples/time_restrictions_search.py Shows how to filter flights by specific departure and arrival time windows. Features:
  • TimeRestrictions for departure window (6 AM - 10 AM)
  • Arrival time constraints (12 PM - 6 PM)
  • Morning flight preference
  • Time formatting in results

Date search with preferences

File: examples/date_search_with_preferences.py Demonstrates date-based searching with post-processing filters for specific day preferences (e.g., weekends only). Features:
  • Date range searching
  • Weekend-only filtering (Saturday/Sunday)
  • Premium economy class
  • Day-of-week detection
  • Custom result formatting

Enterprise examples

Complex round-trip validation

File: examples/complex_round_trip_validation.py Enterprise-level round-trip search with comprehensive date validation, complex passenger configurations, and detailed requirements. Features:
  • Date validation function (future dates, max duration)
  • Multiple passengers with infants
  • Time restrictions for both outbound and return
  • Business class
  • Layover optimization
  • Multi-airline preferences
  • Detailed error handling
This example is perfect for production applications that need robust validation and error handling.

Advanced date search validation

File: examples/advanced_date_search_validation.py Comprehensive date range searching with validation, stay duration constraints, and weekend trip optimization. Features:
  • Date range validation function
  • Stay duration constraints (min/max days)
  • Round-trip date searches with variable durations
  • Weekend departure filtering
  • Time restrictions
  • Top 5 results sorted by price
  • Detailed validation error messages
Ideal for building flexible booking tools that need to validate user input and find optimal weekend trips.

Utility examples

Price tracking

File: examples/price_tracking.py Demonstrates tracking flight prices over multiple days to analyze trends and find deals. Features:
  • Multi-day price monitoring
  • Price history storage
  • Statistical analysis (min, max, average)
  • Time-based iteration
  • Trend identification concepts

Error handling with retries

File: examples/error_handling_with_retries.py Shows robust error handling patterns with both simple and advanced retry logic. Features:
  • Simple retry implementation (no dependencies)
  • Advanced retry with tenacity library
  • Exponential backoff
  • Graceful degradation
  • Optional dependency handling
The HTTP client already includes retry logic at the network level. These examples show application-level retry patterns for additional robustness.

Result processing

File: examples/result_processing.py Demonstrates advanced result analysis and data format conversion. Features:
  • Convert results to dictionary format
  • Basic statistical analysis (no dependencies)
  • Pandas integration for advanced analysis
  • CSV export capabilities
  • Price and duration statistics
  • Airline distribution analysis

Example categories

Basic examples

basic_one_way_search.py
round_trip_search.py
date_range_search.py
Core functionality and simple usage patterns

Advanced examples

complex_flight_search.py
time_restrictions_search.py
date_search_with_preferences.py
Multiple filters and constraints

Enterprise examples

complex_round_trip_validation.py
advanced_date_search_validation.py
Production-ready validation and complex requirements

Utility examples

price_tracking.py
error_handling_with_retries.py
result_processing.py
Robust implementation and data analysis

Common patterns

Airport selection

Date handling

Passenger configuration

Next steps

SearchFlights API

Detailed SearchFlights documentation

SearchDates API

Detailed SearchDates documentation

Library overview

Core concepts and data models