openvan 0.2.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.2.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
 
@@ -56,12 +56,25 @@ print(ov.tolls.route(["Rome", "Paris"], vehicle_class="van"))
56
56
  for c in ov.weather.top(5):
57
57
  print(c["code"], c["van_score"], c["score_label"])
58
58
 
59
+ # Countries of Europe by the score of the coming week (the site ranking), one city with its place
60
+ for c in ov.weather.ranking(region="europe", limit=5):
61
+ print(c["rank"], c["name"], c["week_score"])
62
+ print(ov.weather.city("GE", "batumi")["rank"])
63
+
59
64
  # Typical weather (climate) in Batumi on 18 September and the best month to go
60
65
  batumi = ov.weather.city_climate("GE", "batumi", date="09-18")
61
66
  print(batumi["day"]["temp_day_c"], batumi["day"]["precipitation_days_of_35"], batumi["best_month"])
62
67
 
63
68
  # School holidays in Germany this autumn, by federal state
64
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"])
65
78
  ```
66
79
 
67
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
 
@@ -32,12 +32,25 @@ print(ov.tolls.route(["Rome", "Paris"], vehicle_class="van"))
32
32
  for c in ov.weather.top(5):
33
33
  print(c["code"], c["van_score"], c["score_label"])
34
34
 
35
+ # Countries of Europe by the score of the coming week (the site ranking), one city with its place
36
+ for c in ov.weather.ranking(region="europe", limit=5):
37
+ print(c["rank"], c["name"], c["week_score"])
38
+ print(ov.weather.city("GE", "batumi")["rank"])
39
+
35
40
  # Typical weather (climate) in Batumi on 18 September and the best month to go
36
41
  batumi = ov.weather.city_climate("GE", "batumi", date="09-18")
37
42
  print(batumi["day"]["temp_day_c"], batumi["day"]["precipitation_days_of_35"], batumi["best_month"])
38
43
 
39
44
  # School holidays in Germany this autumn, by federal state
40
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"])
41
54
  ```
42
55
 
43
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:
@@ -143,6 +146,33 @@ class Weather(_Resource):
143
146
  """Vanlife weather of one country: ``van_score`` 0–100, ``score_label``, 7-day ``forecast``."""
144
147
  return self.client.get(f"/api/vansky/weather/{code.upper()}")["data"]
145
148
 
149
+ def city(self, code: str, city_slug: str, locale: Optional[str] = None, hourly: bool = False) -> JSON:
150
+ """One city, as on its page: score today and for the coming 7 days, place among the cities of the
151
+ country (``rank``), per-day score breakdown, worst day, best stretch, air quality, recommendations.
152
+ ``hourly=True`` adds 3-hour steps.
153
+ """
154
+ params = {"locale": locale, "include": "hourly" if hourly else None}
155
+ return self.client.get(f"/api/vansky/weather/{code.upper()}/{quote(city_slug)}", params)["data"]
156
+
157
+ def cities(
158
+ self, code: str, sort: str = "week", limit: Optional[int] = None, offset: Optional[int] = None,
159
+ locale: Optional[str] = None,
160
+ ) -> JSON:
161
+ """Cities of a country ranked by the score of the coming 7 days (``sort="week"``, as on the site) or today."""
162
+ params = {"sort": sort, "limit": limit, "offset": offset, "locale": locale}
163
+ return self.client.get(f"/api/vansky/weather/{code.upper()}/cities", params)
164
+
165
+ def ranking(
166
+ self, by: str = "week", region: Optional[str] = None, limit: Optional[int] = None, locale: Optional[str] = None
167
+ ) -> List[JSON]:
168
+ """Countries ranked by the score of the coming 7 days (``by="week"``) or today, optionally in one region."""
169
+ params = {"by": by, "region": region, "limit": limit, "locale": locale}
170
+ return self.client.get("/api/vansky/ranking", params)["data"]
171
+
172
+ def methodology(self) -> JSON:
173
+ """How the VanSky score is calculated: curves, weights, adjustments, week score."""
174
+ return self.client.get("/api/vansky/methodology")
175
+
146
176
  def all(self) -> List[JSON]:
147
177
  """Every country with weather data (one request, ~1 MB)."""
148
178
  return self.client.get("/api/vansky/weather")["data"]
@@ -198,6 +228,10 @@ class Stories(_Resource):
198
228
  """Semantic search over stories."""
199
229
  return self.client.get("/api/news/search", {"q": query, **options})
200
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
+
201
235
 
202
236
  class Tolls(_Resource):
203
237
  def countries(self, locale: Optional[str] = None) -> JSON:
@@ -346,3 +380,54 @@ class Customs(_Resource):
346
380
  f"/api/customs/countries/{code.upper()}",
347
381
  {"from": from_country.upper() if from_country else None, "locale": locale},
348
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.2.0"
11
+ __version__ = "0.4.0"
12
12
 
13
13
  DEFAULT_BASE_URL = "https://openvan.camp"
14
14
 
@@ -104,6 +104,18 @@ class OpenVanTest(unittest.TestCase):
104
104
  with mock.patch("openvan.client.urlopen", fake):
105
105
  self.assertEqual([c["code"] for c in OpenVan().weather.top(2)], ["B", "C"])
106
106
 
107
+ def test_weather_city_hourly_and_ranking(self):
108
+ fake, calls = respond({
109
+ "/api/vansky/weather/GE/batumi": {"data": {"rank": {"position": 10, "total": 32}}},
110
+ "/api/vansky/ranking": {"data": [{"rank": 1, "code": "CL"}]},
111
+ })
112
+ with mock.patch("openvan.client.urlopen", fake):
113
+ self.assertEqual(OpenVan().weather.city("ge", "batumi", hourly=True)["rank"]["position"], 10)
114
+ self.assertEqual(OpenVan().weather.ranking(region="europe", limit=5)[0]["code"], "CL")
115
+ self.assertEqual(parse_qs(urlparse(calls[0].full_url).query)["include"], ["hourly"])
116
+ q = parse_qs(urlparse(calls[1].full_url).query)
117
+ self.assertEqual((q["by"], q["region"], q["limit"]), (["week"], ["europe"], ["5"]))
118
+
107
119
  def test_climate_point_passes_lat_lng_and_date(self):
108
120
  fake, calls = respond({"/api/vansky/climate": {"period": "2021–2025", "day": {"date": "09-18"}}})
109
121
  with mock.patch("openvan.client.urlopen", fake):
@@ -141,6 +153,28 @@ class OpenVanTest(unittest.TestCase):
141
153
  query = parse_qs(urlparse(calls[0].full_url).query)
142
154
  self.assertEqual(query["from"], ["2026-10-01"])
143
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
+
144
178
  def test_api_error_message_is_kept(self):
145
179
  body = io.BytesIO(json.dumps({"message": "Place not found: Atlantis"}).encode())
146
180
  error = HTTPError("https://openvan.camp/api/tolls/route", 422, "Unprocessable", {}, body)
@@ -176,6 +210,8 @@ class LiveSmokeTest(unittest.TestCase):
176
210
  self.assertIn("advisory", ov.hazards.country("TR"))
177
211
  self.assertIn("plugs", ov.electricity.country("GB"))
178
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"))
179
215
 
180
216
 
181
217
  if __name__ == "__main__":
File without changes
File without changes
File without changes
File without changes
File without changes