parsers module provides utilities for parsing and validating user input into strongly-typed domain model objects. These functions are used by both the CLI and MCP interfaces to ensure consistent parameter handling.
resolve_enum
Resolve an enum member by name with normalized errors.The enum class to resolve from
The name of the enum member (case-insensitive)
ParseError if the name is not a valid enum member
Usage
resolve_airport
Resolve an airport code to an Airport enum.IATA airport code (e.g., ‘JFK’, ‘LHR’)
Airport enum member
Raises: ParseError if the code is not a valid airport
Usage
parse_airlines
Parse a list of airline codes into Airline enums.List of IATA airline codes (e.g., [‘BA’, ‘KL’]). Can be None.
Airline enums, or None if input is empty
Raises: ParseError if any code is not a valid airline
Usage
parse_max_stops
Parse a stops parameter into a MaxStops enum. Accepts both string names (ANY, NON_STOP, ONE_STOP, TWO_PLUS_STOPS) and integer values (0, 1, 2+).Stops value as string or integer representation. Valid values:
- String names:
"ANY","NON_STOP","NONSTOP","ONE_STOP","ONE_STOP_OR_FEWER","TWO_PLUS_STOPS","TWO_OR_FEWER_STOPS" - Integers:
"0"(non-stop),"1"(one stop or fewer),"2"(two or fewer stops)
MaxStops enum member
Raises: ParseError if the value is not valid
Usage
parse_cabin_class
Parse a cabin class string into a SeatType enum.Cabin class name. Valid values:
"ECONOMY", "PREMIUM_ECONOMY", "BUSINESS", "FIRST"SeatType enum member
Raises: ParseError if the value is not valid
Usage
parse_sort_by
Parse a sort_by string into a SortBy enum.Sort option. Valid values:
"CHEAPEST", "DURATION", "DEPARTURE_TIME", "ARRIVAL_TIME"SortBy enum member
Raises: ParseError if the value is not valid
Usage
parse_time_range
Parse a time range string into start and end hours.Time range in ‘HH-HH’ format (e.g., ‘6-20’ for 6 AM to 8 PM)
(start_hour, end_hour) where hours are integers from 0-23
Raises: ParseError if the format is invalid or hours are out of range
Usage
ParseError
Exception raised when parsing fails.ParseError when they encounter invalid input. This exception inherits from ValueError and includes descriptive error messages with valid value suggestions.