openvan 0.3.0__tar.gz → 0.4.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: openvan
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Free vanlife & RV travel data: fuel prices in 160+ countries, toll roads, visa rules, holidays, travel hazards, weather scores, currency. No API key.
5
5
  Project-URL: Homepage, https://openvan.camp/en/developers?utm_source=pypi&utm_medium=referral&utm_campaign=python-sdk
6
6
  Project-URL: Documentation, https://openvan.camp/docs?utm_source=pypi&utm_medium=referral&utm_campaign=python-sdk
@@ -24,8 +24,8 @@ Description-Content-Type: text/markdown
24
24
 
25
25
  # openvan — Python client for the OpenVan.camp API
26
26
 
27
- Free vanlife & RV travel data in Python: fuel prices in 160+ countries, toll roads, visa and
28
- vehicle-import rules, public and school holidays, travel hazards and wildfires, customs rules,
27
+ Free vanlife & RV travel data in Python: whole-trip roadbooks, fuel prices in 170+ countries, toll roads, ferry
28
+ crossings and timetables, visa and vehicle-import rules, public and school holidays, travel hazards and wildfires, customs rules,
29
29
  power plugs, weather suitability scores, food cost index, currency rates, events, news and
30
30
  license plates of the world.
31
31
 
@@ -67,6 +67,14 @@ print(batumi["day"]["temp_day_c"], batumi["day"]["precipitation_days_of_35"], ba
67
67
 
68
68
  # School holidays in Germany this autumn, by federal state
69
69
  ov.holidays.country("DE", from_="2026-10-01", to="2026-12-31", kind="school")
70
+
71
+ # Ferries in the Tyrrhenian Sea (OpenStreetMap, ODbL) and the next departures of one line
72
+ lines = [f["properties"] for f in ov.ferries.window((8, 38, 16, 42), zoom=6)["features"] if f["properties"]["kind"] == "route"]
73
+ print(ov.ferries.schedule("r5958961")["directions"][0]["next"])
74
+
75
+ # A whole trip plan: route, days, budget and rules for every country (waits up to 60 s)
76
+ trip = ov.roadbook.plan(["Munich", "Venice"], inputs={"travelers": ["DE"]})
77
+ print("https://openvan.camp" + trip["url"])
70
78
  ```
71
79
 
72
80
  ### With pandas
@@ -1,7 +1,7 @@
1
1
  # openvan — Python client for the OpenVan.camp API
2
2
 
3
- Free vanlife & RV travel data in Python: fuel prices in 160+ countries, toll roads, visa and
4
- vehicle-import rules, public and school holidays, travel hazards and wildfires, customs rules,
3
+ Free vanlife & RV travel data in Python: whole-trip roadbooks, fuel prices in 170+ countries, toll roads, ferry
4
+ crossings and timetables, visa and vehicle-import rules, public and school holidays, travel hazards and wildfires, customs rules,
5
5
  power plugs, weather suitability scores, food cost index, currency rates, events, news and
6
6
  license plates of the world.
7
7
 
@@ -43,6 +43,14 @@ print(batumi["day"]["temp_day_c"], batumi["day"]["precipitation_days_of_35"], ba
43
43
 
44
44
  # School holidays in Germany this autumn, by federal state
45
45
  ov.holidays.country("DE", from_="2026-10-01", to="2026-12-31", kind="school")
46
+
47
+ # Ferries in the Tyrrhenian Sea (OpenStreetMap, ODbL) and the next departures of one line
48
+ lines = [f["properties"] for f in ov.ferries.window((8, 38, 16, 42), zoom=6)["features"] if f["properties"]["kind"] == "route"]
49
+ print(ov.ferries.schedule("r5958961")["directions"][0]["next"])
50
+
51
+ # A whole trip plan: route, days, budget and rules for every country (waits up to 60 s)
52
+ trip = ov.roadbook.plan(["Munich", "Venice"], inputs={"travelers": ["DE"]})
53
+ print("https://openvan.camp" + trip["url"])
46
54
  ```
47
55
 
48
56
  ### With pandas
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import math
6
+ import time
6
7
  from typing import Any, Dict, List, Optional, Sequence, Tuple
7
8
  from urllib.parse import quote
8
9
 
@@ -46,6 +47,8 @@ class OpenVan:
46
47
  self.hazards = Hazards(self.client)
47
48
  self.electricity = Electricity(self.client)
48
49
  self.customs = Customs(self.client)
50
+ self.roadbook = Roadbook(self.client)
51
+ self.ferries = Ferries(self.client)
49
52
 
50
53
 
51
54
  class _Resource:
@@ -225,6 +228,10 @@ class Stories(_Resource):
225
228
  """Semantic search over stories."""
226
229
  return self.client.get("/api/news/search", {"q": query, **options})
227
230
 
231
+ def digest(self, locale: Optional[str] = None) -> JSON:
232
+ """Today's news digest."""
233
+ return self.client.get("/api/news/digest", {"locale": locale})
234
+
228
235
 
229
236
  class Tolls(_Resource):
230
237
  def countries(self, locale: Optional[str] = None) -> JSON:
@@ -373,3 +380,54 @@ class Customs(_Resource):
373
380
  f"/api/customs/countries/{code.upper()}",
374
381
  {"from": from_country.upper() if from_country else None, "locale": locale},
375
382
  )
383
+
384
+
385
+ class Roadbook(_Resource):
386
+ def create(self, places: Sequence[str], locale: str = "en", name: Optional[str] = None, inputs: Optional[JSON] = None) -> JSON:
387
+ """Create a roadbook from 2–10 place names — the same trip plan as the OpenVan roadbook wizard.
388
+
389
+ Identical requests return the same roadbook. The route is built in the background: use
390
+ :meth:`status` or :meth:`plan` to wait for it.
391
+ """
392
+ return self.client.post(
393
+ "/api/roadbook/from-places",
394
+ {"places": list(places), "locale": locale, "name": name or " — ".join(places)[:80], "inputs": inputs or {}},
395
+ )
396
+
397
+ def status(self, code: str) -> JSON:
398
+ """Build status of a roadbook: ``pending``, ``building``, ``ready`` or ``failed``."""
399
+ return self.client.get(f"/api/roadbook/{quote(code)}/status")
400
+
401
+ def plan(self, places: Sequence[str], timeout: float = 60.0, **options: Any) -> JSON:
402
+ """Create a roadbook and wait until its route is built (default up to 60 s).
403
+
404
+ Open ``https://openvan.camp`` + ``url`` of the result for the full plan.
405
+ """
406
+ created = self.create(places, **options)
407
+ deadline = time.monotonic() + timeout
408
+ status = created.get("status")
409
+ while status not in ("ready", "failed") and time.monotonic() < deadline:
410
+ time.sleep(1.5)
411
+ status = self.status(created["code"])["status"]
412
+ return {**created, "status": status}
413
+
414
+
415
+ class Ferries(_Resource):
416
+ def window(self, bbox: Tuple[float, float, float, float], zoom: Optional[float] = None) -> JSON:
417
+ """Ferry and river crossing lines and ports in ``(min_lon, min_lat, max_lon, max_lat)`` as GeoJSON.
418
+
419
+ OpenStreetMap data (ODbL). ``zoom`` (0–22, default 8) sets geometry detail; at most 1400
420
+ features, ``truncated: True`` means zoom in.
421
+ """
422
+ return self.client.get("/api/ferries", {"bbox": ",".join(str(v) for v in bbox), "zoom": zoom})
423
+
424
+ def get(self, id: str) -> JSON:
425
+ """One ferry line or port by OSM id (e.g. ``r5958961``): tags, verified operator site, both ends."""
426
+ return self.client.get(f"/api/ferries/{quote(id)}")
427
+
428
+ def schedule(self, id: str) -> JSON:
429
+ """Timetable digest from open GTFS feeds: next departures, weekdays, rhythm, travel time.
430
+
431
+ ``available: False`` means no open timetable is matched, not that the ferry does not run.
432
+ """
433
+ return self.client.get(f"/api/ferries/{quote(id)}/schedule")
@@ -8,7 +8,7 @@ from urllib.error import HTTPError, URLError
8
8
  from urllib.parse import urlencode
9
9
  from urllib.request import Request, urlopen
10
10
 
11
- __version__ = "0.3.0"
11
+ __version__ = "0.4.0"
12
12
 
13
13
  DEFAULT_BASE_URL = "https://openvan.camp"
14
14
 
@@ -153,6 +153,28 @@ class OpenVanTest(unittest.TestCase):
153
153
  query = parse_qs(urlparse(calls[0].full_url).query)
154
154
  self.assertEqual(query["from"], ["2026-10-01"])
155
155
 
156
+ def test_ferries_window_joins_bbox_and_passes_zoom(self):
157
+ fake, calls = respond({"/api/ferries": {"type": "FeatureCollection", "features": []}})
158
+ with mock.patch("openvan.client.urlopen", fake):
159
+ OpenVan().ferries.window((4.9, 58.8, 6.2, 59.4), zoom=9)
160
+ query = parse_qs(urlparse(calls[0].full_url).query)
161
+ self.assertEqual((query["bbox"], query["zoom"]), (["4.9,58.8,6.2,59.4"], ["9"]))
162
+
163
+ def test_ferry_schedule_path(self):
164
+ fake, calls = respond({"/api/ferries/r5958961/schedule": {"available": False}})
165
+ with mock.patch("openvan.client.urlopen", fake):
166
+ self.assertFalse(OpenVan().ferries.schedule("r5958961")["available"])
167
+
168
+ def test_roadbook_plan_polls_until_ready(self):
169
+ fake, calls = respond({
170
+ "/api/roadbook/from-places": {"code": "abc12", "status": "building", "url": "/en/roadbook/abc12"},
171
+ "/api/roadbook/abc12/status": {"status": "ready", "error": None},
172
+ })
173
+ with mock.patch("openvan.client.urlopen", fake), mock.patch("openvan.api.time.sleep"):
174
+ result = OpenVan().roadbook.plan(["Munich", "Venice"])
175
+ self.assertEqual(result["status"], "ready")
176
+ self.assertEqual(json.loads(calls[0].data)["places"], ["Munich", "Venice"])
177
+
156
178
  def test_api_error_message_is_kept(self):
157
179
  body = io.BytesIO(json.dumps({"message": "Place not found: Atlantis"}).encode())
158
180
  error = HTTPError("https://openvan.camp/api/tolls/route", 422, "Unprocessable", {}, body)
@@ -188,6 +210,8 @@ class LiveSmokeTest(unittest.TestCase):
188
210
  self.assertIn("advisory", ov.hazards.country("TR"))
189
211
  self.assertIn("plugs", ov.electricity.country("GB"))
190
212
  self.assertIn("items", ov.customs.country("TR", from_country="DE"))
213
+ self.assertIn("features", ov.ferries.window((4.9, 58.8, 6.2, 59.4), zoom=9))
214
+ self.assertIn("available", ov.ferries.schedule("r5958961"))
191
215
 
192
216
 
193
217
  if __name__ == "__main__":
File without changes
File without changes
File without changes
File without changes
File without changes