rihla 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rihla-0.1.0/LICENSE +202 -0
- rihla-0.1.0/NOTICE +2 -0
- rihla-0.1.0/PKG-INFO +227 -0
- rihla-0.1.0/README.md +197 -0
- rihla-0.1.0/pyproject.toml +47 -0
- rihla-0.1.0/setup.cfg +4 -0
- rihla-0.1.0/src/rihla/__init__.py +49 -0
- rihla-0.1.0/src/rihla/api.py +268 -0
- rihla-0.1.0/src/rihla/cli.py +213 -0
- rihla-0.1.0/src/rihla/config.py +81 -0
- rihla-0.1.0/src/rihla/core.py +179 -0
- rihla-0.1.0/src/rihla/fetchers/__init__.py +34 -0
- rihla-0.1.0/src/rihla/fetchers/_http.py +25 -0
- rihla-0.1.0/src/rihla/fetchers/base.py +147 -0
- rihla-0.1.0/src/rihla/fetchers/cache.py +60 -0
- rihla-0.1.0/src/rihla/fetchers/merge.py +65 -0
- rihla-0.1.0/src/rihla/fetchers/mock.py +41 -0
- rihla-0.1.0/src/rihla/fetchers/serpapi.py +67 -0
- rihla-0.1.0/src/rihla/fetchers/travelpayouts.py +98 -0
- rihla-0.1.0/src/rihla/mcp_server.py +166 -0
- rihla-0.1.0/src/rihla/places.py +50 -0
- rihla-0.1.0/src/rihla/resolve.py +117 -0
- rihla-0.1.0/src/rihla.egg-info/PKG-INFO +227 -0
- rihla-0.1.0/src/rihla.egg-info/SOURCES.txt +30 -0
- rihla-0.1.0/src/rihla.egg-info/dependency_links.txt +1 -0
- rihla-0.1.0/src/rihla.egg-info/entry_points.txt +3 -0
- rihla-0.1.0/src/rihla.egg-info/requires.txt +8 -0
- rihla-0.1.0/src/rihla.egg-info/top_level.txt +1 -0
- rihla-0.1.0/tests/test_cache.py +130 -0
- rihla-0.1.0/tests/test_core_merge.py +125 -0
- rihla-0.1.0/tests/test_query_api.py +287 -0
- rihla-0.1.0/tests/test_resolve.py +95 -0
rihla-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
rihla-0.1.0/NOTICE
ADDED
rihla-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rihla
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Flexible multi-leg, multi-airport flight search that finds the cheapest route across an entire itinerary.
|
|
5
|
+
Author: Leandro Garcia
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/leojg/rihla
|
|
8
|
+
Project-URL: Repository, https://github.com/leojg/rihla
|
|
9
|
+
Project-URL: Issues, https://github.com/leojg/rihla/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/leojg/rihla/blob/master/CHANGELOG.md
|
|
11
|
+
Keywords: flights,flight-search,travel,itinerary,mcp,mcp-server
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Internet
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
License-File: NOTICE
|
|
23
|
+
Requires-Dist: python-dotenv
|
|
24
|
+
Provides-Extra: mcp
|
|
25
|
+
Requires-Dist: mcp>=1.0; extra == "mcp"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# Rihla
|
|
32
|
+
|
|
33
|
+
> **Rihla** (رحلة), *"the journey."* Named for Ibn Battuta's 14th-century travelogue —
|
|
34
|
+
> the record of history's farthest-traveling explorer, who left Tangier for Mecca and
|
|
35
|
+
> kept going for 29 years and 75,000 miles.
|
|
36
|
+
|
|
37
|
+
Flexible multi-leg, multi-airport flight search that finds the cheapest route across an
|
|
38
|
+
**entire itinerary** — available as a CLI and as an MCP server for AI agents.
|
|
39
|
+
|
|
40
|
+
Consumer flight sites price one leg at a time. Rihla treats the whole trip as a single
|
|
41
|
+
optimization problem:
|
|
42
|
+
|
|
43
|
+
> *"Leave Montevideo — or Buenos Aires, it's a ferry ride away — around September 15
|
|
44
|
+
> for Europe. Stay 20–30 days, then Japan for 15, then home. What's the cheapest
|
|
45
|
+
> combination?"*
|
|
46
|
+
|
|
47
|
+
That query has three legs, flexible airports on both ends of each, a flexible departure
|
|
48
|
+
window, and stay-duration constraints linking the legs. Rihla prices each leg's
|
|
49
|
+
date×airport grid once, then finds the cheapest valid combinations in pure local
|
|
50
|
+
compute — so even a 3–4 leg flexible query costs only a handful of API calls.
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
1. 1,297 USD (44 days door-to-door)
|
|
54
|
+
MVD -> AMS 2026-09-08 $ 383 [mock, cached] AA AA127
|
|
55
|
+
FRA -> NRT 2026-10-07 $ 481 [mock, cached] KL KL411
|
|
56
|
+
HND -> EZE 2026-10-22 $ 433 [mock, cached] AZ AZ933
|
|
57
|
+
|
|
58
|
+
2. 1,308 USD (44 days door-to-door)
|
|
59
|
+
MVD -> AMS 2026-09-14 $ 446 [mock, cached] AA AA127
|
|
60
|
+
...
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Note the airport substitution at work: it enters Europe through Amsterdam, leaves from
|
|
64
|
+
Frankfurt, and flies home into Buenos Aires — each leg independently picks the cheapest
|
|
65
|
+
airport pair from its sets.
|
|
66
|
+
|
|
67
|
+
## Quick start
|
|
68
|
+
|
|
69
|
+
Requires Python ≥ 3.10.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install rihla # CLI
|
|
73
|
+
pip install "rihla[mcp]" # CLI + MCP server
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Runs offline out of the box (no keys needed — a deterministic mock data source):
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
RIHLA_PROFILE=mock rihla # the canonical demo trip above
|
|
80
|
+
rihla examples/queries/canonical.json # same trip, from a query file
|
|
81
|
+
rihla -i # build a query interactively
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
For live prices, copy `.env.example` to `.env` and add at least a
|
|
85
|
+
[Travelpayouts](https://www.travelpayouts.com) token (free). See
|
|
86
|
+
[Data sources](#data-sources--profiles).
|
|
87
|
+
|
|
88
|
+
## Writing a query
|
|
89
|
+
|
|
90
|
+
A query is a small JSON file: your origin airports, the ordered stops, a departure
|
|
91
|
+
window for the first leg, and how long to stay at each stop. Downstream date windows
|
|
92
|
+
are derived — you never hand-compute "if I leave Sep 15 and stay 20–30 days, when do I
|
|
93
|
+
fly to Tokyo?"
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"origins": ["MVD", "EZE", "AEP"],
|
|
98
|
+
"stops": ["EUROPE", ["NRT", "HND"], "MVD_AREA"],
|
|
99
|
+
"earliest": "2026-09-08",
|
|
100
|
+
"latest": "2026-09-22",
|
|
101
|
+
"stays": [[20, 30], [15, 15]],
|
|
102
|
+
"date_step": 3,
|
|
103
|
+
"top": 5
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- **`origins`** — IATA codes tried as one origin set; the cheapest wins per date.
|
|
108
|
+
- **`stops`** — each stop is a region name or a list of IATA codes. Built-in regions:
|
|
109
|
+
`EUROPE` (MAD, BCN, LIS, CDG, FCO, AMS, FRA), `TOKYO` (NRT, HND), `MVD_AREA`
|
|
110
|
+
(MVD, EZE, AEP). Make the last stop your origin set to fly home.
|
|
111
|
+
- **`earliest` / `latest`** — the departure window for the *first* leg only.
|
|
112
|
+
- **`stays`** — `[min, max]` nights at each intermediate stop
|
|
113
|
+
(`len(stays) == len(stops) - 1`).
|
|
114
|
+
- **`date_step`** — sample every N days across date windows (coarser = fewer API calls).
|
|
115
|
+
- **`top`** — how many ranked combinations to return.
|
|
116
|
+
- **`currency`** — optional ISO 4217 code (default `USD`).
|
|
117
|
+
|
|
118
|
+
`rihla -i` walks you through these questions and prints the resulting JSON to save for
|
|
119
|
+
reuse. Add `--links` to any run to show booking URLs.
|
|
120
|
+
|
|
121
|
+
## Reading results
|
|
122
|
+
|
|
123
|
+
Rihla is honest about data quality rather than pretending everything is bookable:
|
|
124
|
+
|
|
125
|
+
- Each flight is tagged with its source, and `cached` when the price is **indicative**
|
|
126
|
+
(Travelpayouts data is aggregated search history, not a live fare) versus a real,
|
|
127
|
+
bookable fare (SerpApi / Google Flights).
|
|
128
|
+
- If some legs can't be priced (thin routes are real — cached sources have gaps), you
|
|
129
|
+
get a **partial** result over the legs that were found, never a silently wrong total.
|
|
130
|
+
- For unpriced legs, Rihla shows the nearest cached fares *outside* your departure
|
|
131
|
+
window — a hint to shift or widen dates.
|
|
132
|
+
|
|
133
|
+
Ranking is price-only in v0.1. Open-jaw within a region is allowed by default (enter
|
|
134
|
+
Europe at one city, leave from another); the cost of repositioning inside the region is
|
|
135
|
+
not modeled.
|
|
136
|
+
|
|
137
|
+
## Data sources & profiles
|
|
138
|
+
|
|
139
|
+
| Source | Role | Cost | Notes |
|
|
140
|
+
|---|---|---|---|
|
|
141
|
+
| **Travelpayouts / Aviasales** | Primary | Free | Cached, redistribution-licensed. A month of prices per call, so the call budget stays tiny. Prices indicative; coverage follows route popularity. |
|
|
142
|
+
| **SerpApi** (Google Flights) | Fill | 250 free searches/mo (BYO key) | Real bookable fares; fills routes Travelpayouts misses. Only spent on uncovered routes. |
|
|
143
|
+
| **Mock** | Offline | — | Deterministic fake prices for development and demos. |
|
|
144
|
+
|
|
145
|
+
Configure via `.env` (see `.env.example`) or environment variables:
|
|
146
|
+
`TRAVELPAYOUTS_TOKEN`, `SERPAPI_KEY`, and `RIHLA_PROFILE`:
|
|
147
|
+
|
|
148
|
+
- `local` (default) — every source whose key is set, including SerpApi.
|
|
149
|
+
- `hosted` — redistribution-licensed sources only (SerpApi disabled: it scrapes Google,
|
|
150
|
+
so **do not serve it from a public hosted instance**).
|
|
151
|
+
- `mock` — force the offline fetcher, no network.
|
|
152
|
+
|
|
153
|
+
With no keys set, Rihla falls back to the mock source and says so.
|
|
154
|
+
|
|
155
|
+
## MCP server
|
|
156
|
+
|
|
157
|
+
Rihla ships an MCP server (stdio) so agents like Claude can run trip searches:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pip install "rihla[mcp]"
|
|
161
|
+
claude mcp add rihla -- rihla-mcp # Claude Code
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
or in any MCP client config:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"mcpServers": {
|
|
169
|
+
"rihla": {
|
|
170
|
+
"command": "rihla-mcp",
|
|
171
|
+
"env": {
|
|
172
|
+
"TRAVELPAYOUTS_TOKEN": "your-token",
|
|
173
|
+
"SERPAPI_KEY": "your-key"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
(The server also loads a `.env` from its working directory, so `env` is optional if you
|
|
181
|
+
run it from a checkout.)
|
|
182
|
+
|
|
183
|
+
It exposes two read-only tools with an enforced etiquette:
|
|
184
|
+
|
|
185
|
+
1. **`resolve_airports`** — the agent proposes IATA codes for the traveler's named
|
|
186
|
+
places; Rihla validates and enriches them (nearby alternatives included). Cheap and
|
|
187
|
+
quota-free.
|
|
188
|
+
2. **`search_trip`** — the priced, quota-limited search. Tool descriptions instruct the
|
|
189
|
+
agent to get the traveler's explicit confirmation of the airports *before* spending
|
|
190
|
+
quota here.
|
|
191
|
+
|
|
192
|
+
mcp-name: io.github.leojg/rihla
|
|
193
|
+
|
|
194
|
+
## How it works
|
|
195
|
+
|
|
196
|
+
Leg prices are independent — the MVD→Europe fare doesn't depend on the Tokyo dates. So
|
|
197
|
+
Rihla fetches each leg's date×airport grid **once**, then enumerates valid date
|
|
198
|
+
combinations (respecting the stay constraints) entirely in memory. The combinatorial
|
|
199
|
+
explosion lives in local compute, not in API calls.
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
core.py data model + the pure optimizer (no I/O)
|
|
203
|
+
fetchers/ PriceFetcher protocol: Mock / Travelpayouts / SerpApi + merge
|
|
204
|
+
places.py airport sets / regions
|
|
205
|
+
api.py search_trip: serializable query in, result dict out
|
|
206
|
+
cli.py thin CLI over search_trip
|
|
207
|
+
mcp_server.py thin MCP wrapper over the same seam
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Adding a data source (Duffel, Kiwi, …) is one more class implementing a one-method
|
|
211
|
+
protocol: `quote(origin, dest, day) -> Quote`.
|
|
212
|
+
|
|
213
|
+
**Scope (v0.1):** flight search only — no lodging, no booking or payments, single adult,
|
|
214
|
+
one cabin. Search returns booking links, never handles the transaction.
|
|
215
|
+
|
|
216
|
+
## Development
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
git clone https://github.com/leojg/rihla && cd rihla
|
|
220
|
+
pip install -e ".[dev,mcp]"
|
|
221
|
+
pytest # offline, no keys needed
|
|
222
|
+
ruff check .
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
Licensed under the Apache License 2.0 — see [LICENSE](LICENSE).
|
rihla-0.1.0/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Rihla
|
|
2
|
+
|
|
3
|
+
> **Rihla** (رحلة), *"the journey."* Named for Ibn Battuta's 14th-century travelogue —
|
|
4
|
+
> the record of history's farthest-traveling explorer, who left Tangier for Mecca and
|
|
5
|
+
> kept going for 29 years and 75,000 miles.
|
|
6
|
+
|
|
7
|
+
Flexible multi-leg, multi-airport flight search that finds the cheapest route across an
|
|
8
|
+
**entire itinerary** — available as a CLI and as an MCP server for AI agents.
|
|
9
|
+
|
|
10
|
+
Consumer flight sites price one leg at a time. Rihla treats the whole trip as a single
|
|
11
|
+
optimization problem:
|
|
12
|
+
|
|
13
|
+
> *"Leave Montevideo — or Buenos Aires, it's a ferry ride away — around September 15
|
|
14
|
+
> for Europe. Stay 20–30 days, then Japan for 15, then home. What's the cheapest
|
|
15
|
+
> combination?"*
|
|
16
|
+
|
|
17
|
+
That query has three legs, flexible airports on both ends of each, a flexible departure
|
|
18
|
+
window, and stay-duration constraints linking the legs. Rihla prices each leg's
|
|
19
|
+
date×airport grid once, then finds the cheapest valid combinations in pure local
|
|
20
|
+
compute — so even a 3–4 leg flexible query costs only a handful of API calls.
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
1. 1,297 USD (44 days door-to-door)
|
|
24
|
+
MVD -> AMS 2026-09-08 $ 383 [mock, cached] AA AA127
|
|
25
|
+
FRA -> NRT 2026-10-07 $ 481 [mock, cached] KL KL411
|
|
26
|
+
HND -> EZE 2026-10-22 $ 433 [mock, cached] AZ AZ933
|
|
27
|
+
|
|
28
|
+
2. 1,308 USD (44 days door-to-door)
|
|
29
|
+
MVD -> AMS 2026-09-14 $ 446 [mock, cached] AA AA127
|
|
30
|
+
...
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Note the airport substitution at work: it enters Europe through Amsterdam, leaves from
|
|
34
|
+
Frankfurt, and flies home into Buenos Aires — each leg independently picks the cheapest
|
|
35
|
+
airport pair from its sets.
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
Requires Python ≥ 3.10.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install rihla # CLI
|
|
43
|
+
pip install "rihla[mcp]" # CLI + MCP server
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Runs offline out of the box (no keys needed — a deterministic mock data source):
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
RIHLA_PROFILE=mock rihla # the canonical demo trip above
|
|
50
|
+
rihla examples/queries/canonical.json # same trip, from a query file
|
|
51
|
+
rihla -i # build a query interactively
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
For live prices, copy `.env.example` to `.env` and add at least a
|
|
55
|
+
[Travelpayouts](https://www.travelpayouts.com) token (free). See
|
|
56
|
+
[Data sources](#data-sources--profiles).
|
|
57
|
+
|
|
58
|
+
## Writing a query
|
|
59
|
+
|
|
60
|
+
A query is a small JSON file: your origin airports, the ordered stops, a departure
|
|
61
|
+
window for the first leg, and how long to stay at each stop. Downstream date windows
|
|
62
|
+
are derived — you never hand-compute "if I leave Sep 15 and stay 20–30 days, when do I
|
|
63
|
+
fly to Tokyo?"
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"origins": ["MVD", "EZE", "AEP"],
|
|
68
|
+
"stops": ["EUROPE", ["NRT", "HND"], "MVD_AREA"],
|
|
69
|
+
"earliest": "2026-09-08",
|
|
70
|
+
"latest": "2026-09-22",
|
|
71
|
+
"stays": [[20, 30], [15, 15]],
|
|
72
|
+
"date_step": 3,
|
|
73
|
+
"top": 5
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- **`origins`** — IATA codes tried as one origin set; the cheapest wins per date.
|
|
78
|
+
- **`stops`** — each stop is a region name or a list of IATA codes. Built-in regions:
|
|
79
|
+
`EUROPE` (MAD, BCN, LIS, CDG, FCO, AMS, FRA), `TOKYO` (NRT, HND), `MVD_AREA`
|
|
80
|
+
(MVD, EZE, AEP). Make the last stop your origin set to fly home.
|
|
81
|
+
- **`earliest` / `latest`** — the departure window for the *first* leg only.
|
|
82
|
+
- **`stays`** — `[min, max]` nights at each intermediate stop
|
|
83
|
+
(`len(stays) == len(stops) - 1`).
|
|
84
|
+
- **`date_step`** — sample every N days across date windows (coarser = fewer API calls).
|
|
85
|
+
- **`top`** — how many ranked combinations to return.
|
|
86
|
+
- **`currency`** — optional ISO 4217 code (default `USD`).
|
|
87
|
+
|
|
88
|
+
`rihla -i` walks you through these questions and prints the resulting JSON to save for
|
|
89
|
+
reuse. Add `--links` to any run to show booking URLs.
|
|
90
|
+
|
|
91
|
+
## Reading results
|
|
92
|
+
|
|
93
|
+
Rihla is honest about data quality rather than pretending everything is bookable:
|
|
94
|
+
|
|
95
|
+
- Each flight is tagged with its source, and `cached` when the price is **indicative**
|
|
96
|
+
(Travelpayouts data is aggregated search history, not a live fare) versus a real,
|
|
97
|
+
bookable fare (SerpApi / Google Flights).
|
|
98
|
+
- If some legs can't be priced (thin routes are real — cached sources have gaps), you
|
|
99
|
+
get a **partial** result over the legs that were found, never a silently wrong total.
|
|
100
|
+
- For unpriced legs, Rihla shows the nearest cached fares *outside* your departure
|
|
101
|
+
window — a hint to shift or widen dates.
|
|
102
|
+
|
|
103
|
+
Ranking is price-only in v0.1. Open-jaw within a region is allowed by default (enter
|
|
104
|
+
Europe at one city, leave from another); the cost of repositioning inside the region is
|
|
105
|
+
not modeled.
|
|
106
|
+
|
|
107
|
+
## Data sources & profiles
|
|
108
|
+
|
|
109
|
+
| Source | Role | Cost | Notes |
|
|
110
|
+
|---|---|---|---|
|
|
111
|
+
| **Travelpayouts / Aviasales** | Primary | Free | Cached, redistribution-licensed. A month of prices per call, so the call budget stays tiny. Prices indicative; coverage follows route popularity. |
|
|
112
|
+
| **SerpApi** (Google Flights) | Fill | 250 free searches/mo (BYO key) | Real bookable fares; fills routes Travelpayouts misses. Only spent on uncovered routes. |
|
|
113
|
+
| **Mock** | Offline | — | Deterministic fake prices for development and demos. |
|
|
114
|
+
|
|
115
|
+
Configure via `.env` (see `.env.example`) or environment variables:
|
|
116
|
+
`TRAVELPAYOUTS_TOKEN`, `SERPAPI_KEY`, and `RIHLA_PROFILE`:
|
|
117
|
+
|
|
118
|
+
- `local` (default) — every source whose key is set, including SerpApi.
|
|
119
|
+
- `hosted` — redistribution-licensed sources only (SerpApi disabled: it scrapes Google,
|
|
120
|
+
so **do not serve it from a public hosted instance**).
|
|
121
|
+
- `mock` — force the offline fetcher, no network.
|
|
122
|
+
|
|
123
|
+
With no keys set, Rihla falls back to the mock source and says so.
|
|
124
|
+
|
|
125
|
+
## MCP server
|
|
126
|
+
|
|
127
|
+
Rihla ships an MCP server (stdio) so agents like Claude can run trip searches:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install "rihla[mcp]"
|
|
131
|
+
claude mcp add rihla -- rihla-mcp # Claude Code
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
or in any MCP client config:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"mcpServers": {
|
|
139
|
+
"rihla": {
|
|
140
|
+
"command": "rihla-mcp",
|
|
141
|
+
"env": {
|
|
142
|
+
"TRAVELPAYOUTS_TOKEN": "your-token",
|
|
143
|
+
"SERPAPI_KEY": "your-key"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
(The server also loads a `.env` from its working directory, so `env` is optional if you
|
|
151
|
+
run it from a checkout.)
|
|
152
|
+
|
|
153
|
+
It exposes two read-only tools with an enforced etiquette:
|
|
154
|
+
|
|
155
|
+
1. **`resolve_airports`** — the agent proposes IATA codes for the traveler's named
|
|
156
|
+
places; Rihla validates and enriches them (nearby alternatives included). Cheap and
|
|
157
|
+
quota-free.
|
|
158
|
+
2. **`search_trip`** — the priced, quota-limited search. Tool descriptions instruct the
|
|
159
|
+
agent to get the traveler's explicit confirmation of the airports *before* spending
|
|
160
|
+
quota here.
|
|
161
|
+
|
|
162
|
+
mcp-name: io.github.leojg/rihla
|
|
163
|
+
|
|
164
|
+
## How it works
|
|
165
|
+
|
|
166
|
+
Leg prices are independent — the MVD→Europe fare doesn't depend on the Tokyo dates. So
|
|
167
|
+
Rihla fetches each leg's date×airport grid **once**, then enumerates valid date
|
|
168
|
+
combinations (respecting the stay constraints) entirely in memory. The combinatorial
|
|
169
|
+
explosion lives in local compute, not in API calls.
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
core.py data model + the pure optimizer (no I/O)
|
|
173
|
+
fetchers/ PriceFetcher protocol: Mock / Travelpayouts / SerpApi + merge
|
|
174
|
+
places.py airport sets / regions
|
|
175
|
+
api.py search_trip: serializable query in, result dict out
|
|
176
|
+
cli.py thin CLI over search_trip
|
|
177
|
+
mcp_server.py thin MCP wrapper over the same seam
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Adding a data source (Duffel, Kiwi, …) is one more class implementing a one-method
|
|
181
|
+
protocol: `quote(origin, dest, day) -> Quote`.
|
|
182
|
+
|
|
183
|
+
**Scope (v0.1):** flight search only — no lodging, no booking or payments, single adult,
|
|
184
|
+
one cabin. Search returns booking links, never handles the transaction.
|
|
185
|
+
|
|
186
|
+
## Development
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
git clone https://github.com/leojg/rihla && cd rihla
|
|
190
|
+
pip install -e ".[dev,mcp]"
|
|
191
|
+
pytest # offline, no keys needed
|
|
192
|
+
ruff check .
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
Licensed under the Apache License 2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rihla"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Flexible multi-leg, multi-airport flight search that finds the cheapest route across an entire itinerary."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "Leandro Garcia" }]
|
|
14
|
+
keywords = ["flights", "flight-search", "travel", "itinerary", "mcp", "mcp-server"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Intended Audience :: End Users/Desktop",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Topic :: Internet",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"python-dotenv", # load credentials from a local .env in the CLI
|
|
26
|
+
]
|
|
27
|
+
# Live fetchers (Travelpayouts, SerpApi) use stdlib urllib - no extra runtime deps yet.
|
|
28
|
+
# httpx joins at the MCP milestone (M5) for async/concurrent fetching.
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/leojg/rihla"
|
|
32
|
+
Repository = "https://github.com/leojg/rihla"
|
|
33
|
+
Issues = "https://github.com/leojg/rihla/issues"
|
|
34
|
+
Changelog = "https://github.com/leojg/rihla/blob/master/CHANGELOG.md"
|
|
35
|
+
|
|
36
|
+
[project.optional-dependencies]
|
|
37
|
+
# MCP server: pip install "rihla[mcp]"
|
|
38
|
+
mcp = ["mcp>=1.0"]
|
|
39
|
+
# Tooling for local development: pip install -e ".[dev]"
|
|
40
|
+
dev = ["pytest", "ruff"]
|
|
41
|
+
|
|
42
|
+
[project.scripts]
|
|
43
|
+
rihla = "rihla.cli:main"
|
|
44
|
+
rihla-mcp = "rihla.mcp_server:main"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
rihla-0.1.0/setup.cfg
ADDED