### Install fast-flights Source: https://github.com/aweirddev/flights/blob/dev/docs/content/docs/_index.md Install the fast-flights library using pip. ```sh pip install fast-flights ``` -------------------------------- ### Create Round-Trip Query Example Source: https://github.com/aweirddev/flights/blob/dev/docs/content/docs/queries.md This example demonstrates creating a structured query for a round-trip flight, including flight data, passenger details, seat class, and maximum stops. The `to_bytes()` and `to_str()` methods are available on the query object. ```python query: Query = create_query( flight_data=[ FlightQuery( date="2025-01-01", from_airport="TPE", to_airport="MYJ", ) ], trip="round-trip", passengers=Passengers(adults=2, children=1, infants_in_seat=0, infants_on_lap=0), seat="economy", max_stops=1, ) query.to_bytes() # Base64-encoded (bytes) query.to_str() # Serialize to string ``` -------------------------------- ### Get Flights Using Natural Language Source: https://github.com/aweirddev/flights/blob/dev/docs/content/docs/queries.md Alternatively, you can use natural text to get flights instead of using `create_query()`. This provides a more conversational way to search for flights. ```python get_flights( "Flights from TPE to MYJ on 2067-06-07 one way economy class" ) ``` -------------------------------- ### Create and Get Flights Query Source: https://github.com/aweirddev/flights/blob/dev/README.md Demonstrates how to create a flight query object with specified dates, airports, trip type, passengers, and language, then retrieve flight results using the get_flights function. Ensure dates are in YYYY-MM-DD format and airport codes are three-letter identifiers. ```python from fast_flights import ( FlightQuery, Passengers, create_query, get_flights ) query = create_query( flights=[ FlightQuery( date="YYYY-MM-DD", # change the date from_airport="MYJ", # three-letter name to_airport="TPE", # three-letter name ), ], seat="economy", # business/economy/first/premium-economy trip="one-way", # multi-city/one-way/round-trip passengers=Passengers(adults=1), language="zh-TW", ) res = get_flights(query) ``` -------------------------------- ### Google Flights Search URL Parameters Source: https://github.com/aweirddev/flights/blob/dev/README.md This is an example of a Google Flights search URL. The 'tfs' parameter is a Base64-encoded string containing flight search details. ```url https://www.google.com/travel/flights/search?tfs=CBwQAhoeEgoyMDI0LTA1LTI4agcIARIDVFBFcgcIARIDTVlKGh4SCjIwMjQtMDUtMzBqBwgBEgNNWUpyBwgBEgNUUEVAAUgBcAGCAQsI____________AZgBAQ&hl=en ``` -------------------------------- ### Get Flights with New Options Source: https://github.com/aweirddev/flights/wiki/What's-New Use this function to fetch flights with the new options enabled, such as bypassing EU consent screens with new cookies and setting display language and currency. The `dangerously_allow_looping_last_item` option can be set to `True` to prevent unexpected exits when looping into the last item. ```python # ...in a nutshell: get_flights( filter, dangerously_allow_looping_last_item=True, cookies=Cookies.new().to_dict(), currency="USD", language="en" ) ``` -------------------------------- ### Use Bright Data Integration Source: https://github.com/aweirddev/flights/blob/dev/README.md Integrate Bright Data to protect your IP address during flight searches. Ensure the BrightData class is imported from fast_flights.integrations. ```python from fast_flights.integrations import BrightData result = get_flights( ..., integration=BrightData(zone="...") ) # ... same as normal queries ``` -------------------------------- ### Use SearchApi Integration Source: https://github.com/aweirddev/flights/blob/dev/README.md Integrate SearchApi for improved consistency and richer flight data. Import SearchApi and SearchApiResult from fast_flights.integrations. The result object provides access to flights, cheaper alternatives, price insights, and booking options. ```python from fast_flights.integrations import SearchApi, SearchApiResult result: SearchApiResult = get_flights( ..., integration=SearchApi() ) # rich data! result.flights result.cheaper_alternatives result.price_insights result.booking_options ... ``` -------------------------------- ### Create a Flight Query Source: https://github.com/aweirddev/flights/blob/dev/docs/content/docs/_index.md Create a flight query object to search for flights. Specify departure date, origin and destination airports, trip type, seat class, and passenger details. Note that 'multi-city' trip type is not yet supported. ```python from fast_flights import FlightQuery, Passengers, ResultList, create_query, get_flights result: ResultList = create_query( flights=[ FlightQuery(date="2025-01-01", from_airport="TPE", to_airport="MYJ") # (1) ], trip="one-way", # (2) seat="economy", # (3) passengers=Passengers(adults=2, children=1, infants_in_seat=0, infants_on_lap=0), # (4) ) print(result) ``` -------------------------------- ### Create Flight Query Programmatically Source: https://github.com/aweirddev/flights/blob/dev/docs/content/docs/queries.md Use `create_query` to build a structured query object for flight searches. This method takes detailed flight information, passenger counts, and preferences. ```python from fast_flights import ( FlightQuery, Passengers, create_query ) query = create_query( flights=[ FlightQuery( date="2067-06-07", from_airport="MYJ", to_airport="TPE" ), ], seat="economy", trip="one-way", passengers=Passengers(adults=1, infants_in_seat=2), language="en" ) # ...then you get get flights with the query! # res = get_flights(query) ``` -------------------------------- ### Protocol Buffers Definition for Flight Data Source: https://github.com/aweirddev/flights/blob/dev/README.md This Protobuf definition is used to decode the Base64-encoded 'tfs' parameter from Google Flights URLs. It defines messages for airports, flight information, and a container for multiple flight entries. ```protobuf syntax = "proto3" message Airport { string name = 2; } message FlightInfo { string date = 2; Airport dep_airport = 13; Airport arr_airport = 14; } message GoogleSucks { repeated FlightInfo = 3; } ``` -------------------------------- ### Define FlightQuery Object Source: https://github.com/aweirddev/flights/blob/dev/docs/content/docs/queries.md The `FlightQuery` object specifies general flight data like date, departure and arrival airports, and optionally airlines and maximum stops. ```python data = FlightQuery( date="2025-01-01", from_airport="TPE", to_airport="MYJ", airlines=["DL", "AA", "STAR_ALLIANCE"], # optional max_stops=10 # optional ) ``` -------------------------------- ### Define Passengers Object Source: https://github.com/aweirddev/flights/blob/dev/docs/content/docs/queries.md The `Passengers` object defines the number of adults, children, and infants. Ensure the total does not exceed 9 and that there's at least one adult per infant on lap. ```python passengers = Passengers( adults=2, children=1, infants_in_seat=0, infants_on_lap=0 ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.