Skip to content

armgit / fli

Public Imported from GitHub
0

Google Flights MCP, CLI and Python Library

Feat: basic economy filter (#88)

Josh Rehders82e4abf245c5
diff --git a/fli/cli/commands/flights.py b/fli/cli/commands/flights.py
index afcc20a..ca87f84 100644
--- a/fli/cli/commands/flights.py
+++ b/fli/cli/commands/flights.py
@@ -40,6 +40,7 @@ def _search_flights_core(
cabin_class: str = "ECONOMY",
max_stops: str = "ANY",
sort_by: str = "CHEAPEST",
+ exclude_basic_economy: bool = False,
output_format: OutputFormat = OutputFormat.TEXT,
) -> None:
"""Core flight search functionality."""
@@ -101,6 +102,7 @@ def _search_flights_core(
seat_type=seat_type,
airlines=parsed_airlines,
sort_by=sort,
+ exclude_basic_economy=exclude_basic_economy,
)
# Perform search
@@ -218,6 +220,14 @@ def flights(
help="Sort results by (CHEAPEST, DURATION, DEPARTURE_TIME, ARRIVAL_TIME)",
),
] = "CHEAPEST",
+ exclude_basic_economy: Annotated[
+ bool,
+ typer.Option(
+ "--exclude-basic",
+ "-e",
+ help="Exclude basic economy fares",
+ ),
+ ] = False,
output_format: Annotated[
OutputFormat,
typer.Option(
@@ -232,6 +242,7 @@ def flights(
Example:
fli flights JFK LHR 2025-10-25 --time 6-20 --airlines BA KL --stops NON_STOP
fli flights JFK LHR 2025-10-25 --format json
+ fli flights JFK LHR 2025-10-25 --exclude-basic
"""
_search_flights_core(
@@ -244,5 +255,6 @@ def flights(
cabin_class=cabin_class,
max_stops=max_stops,
sort_by=sort_by,
+ exclude_basic_economy=exclude_basic_economy,
output_format=output_format,
)
diff --git a/fli/mcp/server.py b/fli/mcp/server.py
index 7ad5f5e..49f1502 100755
--- a/fli/mcp/server.py
+++ b/fli/mcp/server.py
@@ -240,6 +240,9 @@ class FlightSearchParams(BaseModel):
ge=1,
description="Number of adult passengers",
)
+ exclude_basic_economy: bool = Field(
+ False, description="Exclude basic economy fares from results"
+ )
class DateSearchParams(BaseModel):
@@ -362,6 +365,7 @@ def _execute_flight_search(params: FlightSearchParams) -> dict[str, Any]:
seat_type=cabin_class,
airlines=airlines,
sort_by=sort_by,
+ exclude_basic_economy=params.exclude_basic_economy,
)
# Perform search
@@ -512,6 +516,10 @@ def search_flights(
int | None,
Field(description="Number of adult passengers", ge=1),
] = None,
+ exclude_basic_economy: Annotated[
+ bool,
+ Field(description="Exclude basic economy fares from results"),
+ ] = False,
) -> dict[str, Any]:
"""Search for flights between two airports on a specific date.
@@ -530,6 +538,7 @@ def search_flights(
max_stops=max_stops,
sort_by=sort_by,
passengers=passengers or CONFIG.default_passengers,
+ exclude_basic_economy=exclude_basic_economy,
)
return _execute_flight_search(params)
diff --git a/fli/models/google_flights/flights.py b/fli/models/google_flights/flights.py
index bc7d2a6..3cda5b5 100644
--- a/fli/models/google_flights/flights.py
+++ b/fli/models/google_flights/flights.py
@@ -37,6 +37,7 @@ class FlightSearchFilters(BaseModel):
max_duration: PositiveInt | None = None
layover_restrictions: LayoverRestrictions | None = None
sort_by: SortBy = SortBy.NONE
+ exclude_basic_economy: bool = False
def format(self) -> list:
"""Format filters into Google Flights API structure.
@@ -172,11 +173,22 @@ class FlightSearchFilters(BaseModel):
None, # placeholder
None, # placeholder
1, # placeholder (hardcoded to 1)
+ None, # placeholder
+ None, # placeholder
+ None, # placeholder
+ None, # placeholder
+ None, # placeholder
+ None, # placeholder
+ None, # placeholder
+ None, # placeholder
+ None, # placeholder
+ None, # placeholder
+ 1 if self.exclude_basic_economy else 0,
],
serialize(self.sort_by.value),
0, # constant
0, # constant
- 2, # constant
+ 1, # constant
]
return filters
diff --git a/tests/models/test_flight_search_filters.py b/tests/models/test_flight_search_filters.py
index c8d4b31..2a57e40 100644
--- a/tests/models/test_flight_search_filters.py
+++ b/tests/models/test_flight_search_filters.py
@@ -87,11 +87,22 @@ TEST_CASES = [
None,
None,
1,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ 0,
],
2,
0,
0,
- 2,
+ 1,
],
"encoded": None,
},
@@ -156,11 +167,22 @@ TEST_CASES = [
None,
None,
1,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ 0,
],
1,
0,
0,
- 2,
+ 1,
],
"encoded": None,
},
@@ -236,14 +258,105 @@ TEST_CASES = [
None,
None,
1,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ 0,
],
0,
0,
0,
- 2,
+ 1,
],
"encoded": None, # Dynamic date makes encoded string non-deterministic
},
+ {
+ "name": "Test 4: Exclude Basic Economy",
+ "search": FlightSearchFilters(
+ passenger_info=PassengerInfo(
+ adults=1,
+ children=0,
+ infants_in_seat=0,
+ infants_on_lap=0,
+ ),
+ flight_segments=[
+ FlightSegment(
+ departure_airport=[[Airport.EWR, 0]],
+ arrival_airport=[[Airport.CHS, 0]],
+ time_restrictions=None,
+ travel_date=TRAVEL_DATE,
+ )
+ ],
+ stops=MaxStops.NON_STOP,
+ seat_type=SeatType.ECONOMY,
+ sort_by=SortBy.CHEAPEST,
+ exclude_basic_economy=True,
+ ),
+ "formatted": [
+ [],
+ [
+ None,
+ None,
+ 2,
+ None,
+ [],
+ 1,
+ [1, 0, 0, 0],
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ [
+ [
+ [[["EWR", 0]]],
+ [[["CHS", 0]]],
+ None,
+ 1,
+ None,
+ None,
+ TRAVEL_DATE,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ 3,
+ ]
+ ],
+ None,
+ None,
+ None,
+ 1,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ 1,
+ ],
+ 2,
+ 0,
+ 0,
+ 1,
+ ],
+ "encoded": None,
+ },
]