The fast, robust, strongly-typed Google Flights scraper (API) implemented in Python.
Project description
✈️ fast-flights (v3.0)
The fast and strongly-typed Google Flights scraper (API) implemented in Python. Based on Base64-encoded Protobuf string.
Documentation (v2) • Issues • PyPi (v3.0)
$ pip install fast-flights
What's New
v2.0– New (much more succinct) API, fallback support for Playwright serverless functions, and documentation!v2.2– Now supports local playwright for sending requests.v3.0rc0– Uses JavaScript data instead.v3.0– Polished new API! I suppose.
At a glance
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)
Integrations
If you'd like, you can use integrations.
Bright Data
Use the BrightData integration to protect your IP.
from fast_flights.integrations import BrightData
result = get_flights(
...,
integration=BrightData(zone="...")
)
# ... same as normal queries
SearchApi Sponsored
If you want better consistency and richer data, consider using SearchApi.
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
...
Roadmap
- Use JavaScript data instead of traditional HTML parsing
- Add support for integrations
- Dangerously use Google's
GetShoppingResultsinternal API. Get ready to get banned.
Contributing
Contributing is welcomed! A few notes though:
- please no ai slop. i am not reading all that.
- im really busy with life; im not a full-time reddit mod.
How it's made
The other day, I was making a chat-interface-based trip recommendation app and wanted to add a feature that can search for flights available for booking. My personal choice is definitely Google Flights since Google always has the best and most organized data on the web. Therefore, I searched for APIs on Google.
🔎 Search
google flights api
The results? Bad. It seems like they discontinued this service and it now lives in the Graveyard of Google.
🧏♂️ duffel.com
Google Flights API: How did it work & what happened to it?The Google Flights API offered developers access to aggregated airline data, including flight times, availability, and prices. Over a decade ago, Google announced the acquisition of ITA Software Inc. which it used to develop its API. However, in 2018, Google ended access to the public-facing API and now only offers access through the QPX enterprise product.
That's awful! I've also looked for free alternatives but their rate limits and pricing are just 😬 (not a good fit/deal for everyone).
However, Google Flights has their UI – flights.google.com. So, maybe I could just use Developer Tools to log the requests made and just replicate all of that? Undoubtedly not! Their requests are just full of numbers and unreadable text, so that's not the solution.
Perhaps, we could scrape it? I mean, Google allowed many companies like Serpapi to scrape their web just pretending like nothing happened... So let's scrape our own.
🔎 Search
google flightsapiscraper pypi
Excluding the ones that are not active, I came across hugoglvs/google-flights-scraper on Pypi. I thought to myself: "aint no way this is the solution!"
I checked hugoglvs's code on GitHub, and I immediately detected "playwright," my worst enemy. One word can describe it well: slow. Two words? Extremely slow. What's more, it doesn't even run on the 🗻 Edge because of configuration errors, missing libraries... etc. I could just reverse try.playwright.tech and use a better environment, but that's just too risky if they added Cloudflare as an additional security barrier 😳.
Life tells me to never give up. Let's just take a look at their URL params...
https://www.google.com/travel/flights/search?tfs=CBwQAhoeEgoyMDI0LTA1LTI4agcIARIDVFBFcgcIARIDTVlKGh4SCjIwMjQtMDUtMzBqBwgBEgNNWUpyBwgBEgNUUEVAAUgBcAGCAQsI____________AZgBAQ&hl=en
| Param | Content | My past understanding |
|---|---|---|
| hl | en | Sets the language. |
| tfs | CBwQAhoeEgoyMDI0LTA1LTI4agcIARID… | What is this???? 🤮🤮 |
I removed the ?tfs= parameter and found out that this is the control of our request! And it looks so base64-y.
If we decode it to raw text, we can still see the dates, but we're not quite there — there's too much unwanted Unicode text.
Or maybe it's some kind of a data-storing method Google uses? What if it's something like JSON? Let's look it up.
🔎 Search
google's json alternative
🐣 Result
Solution: The Power of Protocol BuffersLinkedIn turned to Protocol Buffers, often referred to as protobuf, a binary serialization format developed by Google. The key advantage of Protocol Buffers is its efficiency, compactness, and speed, making it significantly faster than JSON for serialization and deserialization.
Gotcha, Protobuf! Let's feed it to an online decoder and see how it does:
🔎 Search
protobuf decoder
🐣 Result
protobuf-decoder.netlify.app
I then pasted the Base64-encoded string to the decoder and no way! It DID return valid data!
I immediately recognized the values — that's my data, that's my query!
So, I wrote some simple Protobuf code to decode the data.
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;
}
It works! Now, I won't consider myself an "experienced Protobuf developer" but rather a complete beginner.
I have no idea what I wrote but... it worked! And here it is, fast-flights.
(c) 2024-2026 AWeirdDev, and all the awesome people
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_flights-3.0.tar.gz.
File metadata
- Download URL: fast_flights-3.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
597a8c425677627d8bc1f61dfc77cd35ced921cd22a1b0b4157274a8ed93a2ef
|
|
| MD5 |
74e9275a60b27fbdf10846c8e65cbe01
|
|
| BLAKE2b-256 |
b4334c947af8484add0baa55b0b45fb5e27afb0708080dbfb54c914707238315
|
Provenance
The following attestation bundles were made for fast_flights-3.0.tar.gz:
Publisher:
python-publish.yml on AWeirdDev/flights
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_flights-3.0.tar.gz -
Subject digest:
597a8c425677627d8bc1f61dfc77cd35ced921cd22a1b0b4157274a8ed93a2ef - Sigstore transparency entry: 1809545588
- Sigstore integration time:
-
Permalink:
AWeirdDev/flights@a8327b0c611bf3e98952df4399cd6efc2ee39c97 -
Branch / Tag:
refs/tags/v3.0 - Owner: https://github.com/AWeirdDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a8327b0c611bf3e98952df4399cd6efc2ee39c97 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fast_flights-3.0-py3-none-any.whl.
File metadata
- Download URL: fast_flights-3.0-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31c74145aac8db913d43c13d574cf65f0fadcd6af1afb19b5378d517a48b4b96
|
|
| MD5 |
01ae2f8c6887902c7776841c70c90b07
|
|
| BLAKE2b-256 |
33c556ea05e99816207181e2d57fbf6e4d4b2b3d841ccf52029cbfac1e0f617b
|
Provenance
The following attestation bundles were made for fast_flights-3.0-py3-none-any.whl:
Publisher:
python-publish.yml on AWeirdDev/flights
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_flights-3.0-py3-none-any.whl -
Subject digest:
31c74145aac8db913d43c13d574cf65f0fadcd6af1afb19b5378d517a48b4b96 - Sigstore transparency entry: 1809545601
- Sigstore integration time:
-
Permalink:
AWeirdDev/flights@a8327b0c611bf3e98952df4399cd6efc2ee39c97 -
Branch / Tag:
refs/tags/v3.0 - Owner: https://github.com/AWeirdDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a8327b0c611bf3e98952df4399cd6efc2ee39c97 -
Trigger Event:
release
-
Statement type: