{"id":21569343,"url":"https://github.com/aweirddev/flights","last_synced_at":"2025-05-16T03:04:15.544Z","repository":{"id":239455230,"uuid":"799572365","full_name":"AWeirdDev/flights","owner":"AWeirdDev","description":"Fast, robust Google Flights scraper (API) for Python. (Probably)","archived":false,"fork":false,"pushed_at":"2025-03-08T23:43:07.000Z","size":800,"stargazers_count":188,"open_issues_count":19,"forks_count":41,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-10T09:05:18.729Z","etag":null,"topics":["airport","flights","google-flights","google-flights-api","google-flights-wrapper","protobuf","protobuf3","python","travel","trip"],"latest_commit_sha":null,"homepage":"https://aweirddev.github.io/flights/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AWeirdDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-12T14:45:12.000Z","updated_at":"2025-05-09T11:49:03.000Z","dependencies_parsed_at":"2024-05-12T16:26:21.522Z","dependency_job_id":"dfe3cfa1-3773-4979-84d6-624a4ab488bb","html_url":"https://github.com/AWeirdDev/flights","commit_stats":null,"previous_names":["aweirddev/flights"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWeirdDev%2Fflights","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWeirdDev%2Fflights/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWeirdDev%2Fflights/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWeirdDev%2Fflights/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AWeirdDev","download_url":"https://codeload.github.com/AWeirdDev/flights/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254459088,"owners_count":22074605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["airport","flights","google-flights","google-flights-api","google-flights-wrapper","protobuf","protobuf3","python","travel","trip"],"created_at":"2024-11-24T11:09:13.028Z","updated_at":"2025-05-16T03:04:10.501Z","avatar_url":"https://github.com/AWeirdDev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e Apparently, it's always a better approach to interact with the Internal Google APIs. I'm working on that, and I'll deliver the results soon if my experimental project works out well.\n\n\u003cbr /\u003e\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n\n# ✈️ fast-flights\n\nThe fast and strongly-typed Google Flights scraper (API) implemented in Python. Based on Base64-encoded Protobuf string.\n\n[**Documentation**](https://aweirddev.github.io/flights) • [Issues](https://github.com/AWeirdDev/flights/issues) • [PyPi](https://pypi.org/project/fast-flights)\n\n```haskell\n$ pip install fast-flights\n```\n\n\u003c/div\u003e\n\n## Basics\n**TL;DR**: To use `fast-flights`, you'll first create a filter (for `?tfs=`) to perform a request.\nThen, add `flight_data`, `trip`, `seat`, `passengers` to use the API directly.\n\n```python\nfrom fast_flights import FlightData, Passengers, Result, get_flights\n\nresult: Result = get_flights(\n    flight_data=[\n        FlightData(date=\"2025-01-01\", from_airport=\"TPE\", to_airport=\"MYJ\")\n    ],\n    trip=\"one-way\",\n    seat=\"economy\",\n    passengers=Passengers(adults=2, children=1, infants_in_seat=0, infants_on_lap=0),\n    fetch_mode=\"fallback\",\n)\n\nprint(result)\n\n# The price is currently... low/typical/high\nprint(\"The price is currently\", result.current_price)\n```\n\n**Properties \u0026 usage for `Result`**:\n\n```python\nresult.current_price\n\n# Get the first flight\nflight = result.flights[0]\n\nflight.is_best\nflight.name\nflight.departure\nflight.arrival\nflight.arrival_time_ahead\nflight.duration\nflight.stops\nflight.delay?  # may not be present\nflight.price\n```\n\n**Useless enums**: Additionally, you can use the `Airport` enum to search for airports in code (as you type)! See `_generated_enum.py` in source.\n\n```python\nAirport.TAIPEI\n              ╭─────────────────────────────────╮\n              │ TAIPEI_SONGSHAN_AIRPORT         │\n              │ TAPACHULA_INTERNATIONAL_AIRPORT │\n              │ TAMPA_INTERNATIONAL_AIRPORT     │\n              ╰─────────────────────────────────╯\n```\n\n## What's new\n- `v2.0` – New (much more succinct) API, fallback support for Playwright serverless functions, and [documentation](https://aweirddev.github.io/flights)!\n- `v2.2` - Now supports **local playwright** for sending requests.\n\n## Cookies \u0026 consent\nThe EU region is a bit tricky to solve for now, but the fallback support should be able to handle it.\n\n## Contributing\nContributing is welcomed! I probably won't work on this project unless there's a need for a major update, but boy howdy do I love pull requests.\n\n***\n\n## How it's made\n\nThe 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](https://flights.google.com) since Google always has the best and most organized data on the web. Therefore, I searched for APIs on Google.\n\n\u003e 🔎 **Search** \u003cbr /\u003e\n\u003e google flights api\n\nThe results? Bad. It seems like they discontinued this service and it now lives in the Graveyard of Google.\n\n\u003e \u003csup\u003e\u003ca href=\"https://duffel.com/blog/google-flights-api\" target=\"_blank\"\u003e🧏‍♂️ \u003cb\u003eduffel.com\u003c/b\u003e\u003c/a\u003e\u003c/sup\u003e\u003cbr /\u003e\n\u003e \u003csup\u003e\u003ci\u003eGoogle Flights API: How did it work \u0026 what happened to it?\u003c/i\u003e\u003c/b\u003e\n\u003e\n\u003e 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**.\n\nThat's awful! I've also looked for free alternatives but their rate limits and pricing are just 😬 (not a good fit/deal for everyone).\n\n\u003cbr /\u003e\n\nHowever, Google Flights has their UI – [flights.google.com](https://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.\n\nPerhaps, we could scrape it? I mean, Google allowed many companies like [Serpapi](https://google.com/search?q=serpapi) to scrape their web just pretending like nothing happened... So let's scrape our own.\n\n\u003e 🔎 **Search** \u003cbr /\u003e\n\u003e google flights ~~api~~ scraper pypi\n\nExcluding the ones that are not active, I came across [hugoglvs/google-flights-scraper](https://pypi.org/project/google-flights-scraper) on Pypi. I thought to myself: \"aint no way this is the solution!\"\n\nI checked hugoglvs's code on [GitHub](https://github.com/hugoglvs/google-flights-scraper), 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](https://try.playwright.tech) and use a better environment, but that's just too risky if they added Cloudflare as an additional security barrier 😳.\n\nLife tells me to never give up. Let's just take a look at their URL params...\n\n```markdown\nhttps://www.google.com/travel/flights/search?tfs=CBwQAhoeEgoyMDI0LTA1LTI4agcIARIDVFBFcgcIARIDTVlKGh4SCjIwMjQtMDUtMzBqBwgBEgNNWUpyBwgBEgNUUEVAAUgBcAGCAQsI____________AZgBAQ\u0026hl=en\n```\n\n| Param | Content | My past understanding |\n|-------|---------|-----------------------|\n| hl    | en      | Sets the language.    |\n| tfs   | CBwQAhoeEgoyMDI0LTA1LTI4agcIARID… | What is this???? 🤮🤮 |\n\nI removed the `?tfs=` parameter and found out that this is the control of our request! And it looks so base64-y.\n\nIf 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.\n\nOr maybe it's some kind of a **data-storing method** Google uses? What if it's something like JSON? Let's look it up.\n\n\u003e 🔎 **Search** \u003cbr /\u003e\n\u003e google's json alternative\n\n\u003e 🐣 **Result**\u003cbr /\u003e\n\u003e Solution: The Power of **Protocol Buffers**\n\u003e \n\u003e LinkedIn 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.\n\nGotcha, Protobuf! Let's feed it to an online decoder and see how it does:\n\n\u003e 🔎 **Search** \u003cbr /\u003e\n\u003e protobuf decoder\n\n\u003e 🐣 **Result**\u003cbr /\u003e\n\u003e [protobuf-decoder.netlify.app](https://protobuf-decoder.netlify.app)\n\nI then pasted the Base64-encoded string to the decoder and no way! It DID return valid data!\n\n![annotated, Protobuf Decoder screenshot](https://github.com/AWeirdDev/flights/assets/90096971/77dfb097-f961-4494-be88-3640763dbc8c)\n\nI immediately recognized the values — that's my data, that's my query!\n\nSo, I wrote some simple Protobuf code to decode the data.\n\n```protobuf\nsyntax = \"proto3\"\n\nmessage Airport {\n    string name = 2;\n}\n\nmessage FlightInfo {\n    string date = 2;\n    Airport dep_airport = 13;\n    Airport arr_airport = 14;\n}\n\nmessage GoogleSucks {\n    repeated FlightInfo = 3;\n}\n```\n\nIt works! Now, I won't consider myself an \"experienced Protobuf developer\" but rather a complete beginner.\n\nI have no idea what I wrote but... it worked! And here it is, `fast-flights`.\n\n***\n\n\u003cdiv align=\"center\"\u003e\n\n(c) 2024-2025 AWeirdDev, and other awesome people\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faweirddev%2Fflights","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faweirddev%2Fflights","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faweirddev%2Fflights/lists"}