python-google-weather-api 0.0.7__tar.gz → 0.0.8__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.
Files changed (17) hide show
  1. {python_google_weather_api-0.0.7/src/python_google_weather_api.egg-info → python_google_weather_api-0.0.8}/PKG-INFO +1 -1
  2. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/pyproject.toml +1 -1
  3. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/google_weather_api/__init__.py +4 -0
  4. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/google_weather_api/api.py +41 -7
  5. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/google_weather_api/model.py +61 -0
  6. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8/src/python_google_weather_api.egg-info}/PKG-INFO +1 -1
  7. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/tests/test_api.py +16 -0
  8. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/tests/test_model.py +34 -0
  9. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/LICENSE +0 -0
  10. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/README.md +0 -0
  11. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/setup.cfg +0 -0
  12. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/google_weather_api/exceptions.py +0 -0
  13. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/google_weather_api/py.typed +0 -0
  14. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/python_google_weather_api.egg-info/SOURCES.txt +0 -0
  15. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/python_google_weather_api.egg-info/dependency_links.txt +0 -0
  16. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/python_google_weather_api.egg-info/requires.txt +0 -0
  17. {python_google_weather_api-0.0.7 → python_google_weather_api-0.0.8}/src/python_google_weather_api.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-google-weather-api
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: A python client library for Google Weather API
5
5
  Author-email: tronikos <tronikos@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-google-weather-api"
3
- version = "0.0.7"
3
+ version = "0.0.8"
4
4
  license = "Apache-2.0"
5
5
  authors = [
6
6
  { name="tronikos", email="tronikos@gmail.com" },
@@ -21,9 +21,11 @@ from .model import (
21
21
  IceThickness,
22
22
  Interval,
23
23
  LocalizedText,
24
+ MinuteForecastResponse,
24
25
  MoonEvents,
25
26
  Precipitation,
26
27
  PrecipitationProbability,
28
+ PrecipitationSegment,
27
29
  QuantitativePrecipitationForecast,
28
30
  SunEvents,
29
31
  Temperature,
@@ -54,9 +56,11 @@ __all__ = [
54
56
  "IceThickness",
55
57
  "Interval",
56
58
  "LocalizedText",
59
+ "MinuteForecastResponse",
57
60
  "MoonEvents",
58
61
  "Precipitation",
59
62
  "PrecipitationProbability",
63
+ "PrecipitationSegment",
60
64
  "QuantitativePrecipitationForecast",
61
65
  "SunEvents",
62
66
  "Temperature",
@@ -17,6 +17,7 @@ from .model import (
17
17
  CurrentConditionsResponse,
18
18
  DailyForecastResponse,
19
19
  HourlyForecastResponse,
20
+ MinuteForecastResponse,
20
21
  )
21
22
 
22
23
  _LOGGER = logging.getLogger(__name__)
@@ -45,7 +46,7 @@ class GoogleWeatherApi:
45
46
  self.referrer = referrer
46
47
  self.timeout = aiohttp.ClientTimeout(total=timeout)
47
48
 
48
- async def _async_get(self, endpoint: str, params: dict[str, Any]) -> dict[str, Any]:
49
+ async def _async_get(self, endpoint: str, params: dict[str, Any], *, include_language_code: bool = True) -> dict[str, Any]:
49
50
  """Perform a GET request."""
50
51
  url = f"{_BASE_URL}/{endpoint}"
51
52
  headers = {aiohttp.hdrs.USER_AGENT: _USER_AGENT}
@@ -53,9 +54,10 @@ class GoogleWeatherApi:
53
54
  headers[aiohttp.hdrs.REFERER] = self.referrer
54
55
  params = {
55
56
  **params,
56
- "language_code": self.language_code,
57
57
  "units_system": self.units_system,
58
58
  }
59
+ if include_language_code:
60
+ params["language_code"] = self.language_code
59
61
  # Log before adding the API key so it doesn't end up in debug logs.
60
62
  _LOGGER.debug("GET %s with params: %s", url, params)
61
63
  params["key"] = self.api_key
@@ -89,18 +91,27 @@ class GoogleWeatherApi:
89
91
  raise GoogleWeatherApiConnectionError(err) from err
90
92
 
91
93
  async def _async_get_all_pages(
92
- self, endpoint: str, params: dict[str, Any], records_key: str, limit: int
94
+ self,
95
+ endpoint: str,
96
+ params: dict[str, Any],
97
+ records_key: str,
98
+ limit: int,
99
+ *,
100
+ include_language_code: bool = True,
93
101
  ) -> dict[str, Any]:
94
102
  """Perform a GET request, following pagination until `limit` records are collected.
95
103
 
96
- The API caps the number of records it returns per page (24 for hourly forecasts),
97
- regardless of the requested page size, so a single request is not enough.
104
+ Some endpoints cap the number of records they return per page regardless of the
105
+ requested page size, for example 24 for hourly forecasts, so a single request is
106
+ not always enough.
98
107
  """
99
108
  params = {**params, "page_size": limit}
100
- data = await self._async_get(endpoint, params)
109
+ data = await self._async_get(endpoint, params, include_language_code=include_language_code)
101
110
  records: list[Any] = data.get(records_key, [])
102
111
  while len(records) < limit and (page_token := data.get("nextPageToken")):
103
- data = await self._async_get(endpoint, {**params, "page_token": page_token})
112
+ data = await self._async_get(
113
+ endpoint, {**params, "page_token": page_token}, include_language_code=include_language_code
114
+ )
104
115
  page_records: list[Any] = data.get(records_key, [])
105
116
  if not page_records:
106
117
  break
@@ -155,3 +166,26 @@ class GoogleWeatherApi:
155
166
  days,
156
167
  )
157
168
  return DailyForecastResponse.from_dict(data)
169
+
170
+ async def async_get_minute_forecast(
171
+ self, latitude: float, longitude: float, page_size: int = 360
172
+ ) -> MinuteForecastResponse:
173
+ """Fetch the precipitation nowcast for up to 6 hours.
174
+
175
+ Segments cover 2- or 15-minute intervals depending on the location. The endpoint
176
+ does not accept language_code (a reserved field in google.maps.weather.v1), so it
177
+ is omitted from these requests.
178
+
179
+ See https://developers.google.com/maps/documentation/weather/minute-forecast
180
+ """
181
+ data = await self._async_get_all_pages(
182
+ "forecast/minutes:lookup",
183
+ {
184
+ "location.latitude": latitude,
185
+ "location.longitude": longitude,
186
+ },
187
+ "segments",
188
+ page_size,
189
+ include_language_code=False,
190
+ )
191
+ return MinuteForecastResponse.from_dict(data)
@@ -639,3 +639,64 @@ class HourlyForecastResponse(BaseModel):
639
639
 
640
640
  next_page_token: str | None = field(default=None, metadata={"alias": "nextPageToken"})
641
641
  """The token to retrieve the next page."""
642
+
643
+
644
+ @dataclass
645
+ class PrecipitationSegment(BaseModel):
646
+ """Represents a segment of precipitation forecast data."""
647
+
648
+ class DominantPrecipitationType(ApiStrEnum):
649
+ """Represents the type of precipitation of a segment."""
650
+
651
+ DOMINANT_PRECIPITATION_TYPE_UNSPECIFIED = "DOMINANT_PRECIPITATION_TYPE_UNSPECIFIED"
652
+ NONE = "NONE"
653
+ RAIN = "RAIN"
654
+ SNOW = "SNOW"
655
+ HAIL = "HAIL"
656
+
657
+ class PrecipitationIntensity(ApiStrEnum):
658
+ """Represents the precipitation intensity of a segment."""
659
+
660
+ PRECIPITATION_INTENSITY_UNSPECIFIED = "PRECIPITATION_INTENSITY_UNSPECIFIED"
661
+ NO_INTENSITY = "NO_INTENSITY"
662
+ LIGHT = "LIGHT"
663
+ MID_LIGHT = "MID_LIGHT"
664
+ MODERATE = "MODERATE"
665
+ MID_MODERATE = "MID_MODERATE"
666
+ HEAVY = "HEAVY"
667
+ MID_HEAVY = "MID_HEAVY"
668
+
669
+ time_frame: Interval = field(metadata={"alias": "timeFrame"})
670
+ """The timeframe relevant to the segment."""
671
+
672
+ type: DominantPrecipitationType = DominantPrecipitationType.DOMINANT_PRECIPITATION_TYPE_UNSPECIFIED
673
+ """A code that indicates the type of precipitation."""
674
+
675
+ probability: int = 0
676
+ """The chance of precipitation (values from 0 to 100)."""
677
+
678
+ qpf: QuantitativePrecipitationForecast | None = None
679
+ """The amount of precipitation, measured as liquid water equivalent."""
680
+
681
+ snowfall_amount: QuantitativePrecipitationForecast | None = field(default=None, metadata={"alias": "snowfallAmount"})
682
+ """The amount of snow accumulation, measured as liquid water equivalent."""
683
+
684
+ intensity: PrecipitationIntensity = PrecipitationIntensity.PRECIPITATION_INTENSITY_UNSPECIFIED
685
+ """A code that indicates the precipitation intensity of the segment."""
686
+
687
+
688
+ @dataclass
689
+ class MinuteForecastResponse(BaseModel):
690
+ """Response model for the forecast.minutes.lookup method."""
691
+
692
+ overall_prediction_timeframe: Interval = field(metadata={"alias": "overallPredictionTimeframe"})
693
+ """The overall timeframe for the predictions."""
694
+
695
+ time_zone: TimeZone = field(metadata={"alias": "timeZone"})
696
+ """The time zone at the requested location."""
697
+
698
+ segments: list[PrecipitationSegment] = field(default_factory=list)
699
+ """The minute-level prediction segments."""
700
+
701
+ next_page_token: str | None = field(default=None, metadata={"alias": "nextPageToken"})
702
+ """The token to retrieve the next page."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-google-weather-api
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: A python client library for Google Weather API
5
5
  Author-email: tronikos <tronikos@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -267,3 +267,19 @@ async def test_custom_timeout(session: aiohttp.ClientSession) -> None:
267
267
  api = GoogleWeatherApi(session=session, api_key=API_KEY, timeout=30)
268
268
 
269
269
  assert api.timeout.total == 30
270
+
271
+
272
+ async def test_get_minute_forecast(api: GoogleWeatherApi, mock_server: MockServer) -> None:
273
+ """Test fetching the minute forecast, which must not send language_code."""
274
+ mock_server.add_response(load_fixture("minute_forecast"))
275
+
276
+ result = await api.async_get_minute_forecast(LATITUDE, LONGITUDE)
277
+
278
+ assert result.time_zone.id == "America/New_York"
279
+ assert result.overall_prediction_timeframe.start_time == "2026-08-11T14:17:00Z"
280
+ assert len(result.segments) == 2
281
+ assert result.segments[0].probability == 62
282
+ request = mock_server.requests[0]
283
+ assert request.path == "/v1/forecast/minutes:lookup"
284
+ assert request.query["page_size"] == "360"
285
+ assert "language_code" not in request.query
@@ -13,8 +13,10 @@ from google_weather_api import (
13
13
  HourlyForecastResponse,
14
14
  IceThickness,
15
15
  Interval,
16
+ MinuteForecastResponse,
16
17
  MoonEvents,
17
18
  PrecipitationProbability,
19
+ PrecipitationSegment,
18
20
  QuantitativePrecipitationForecast,
19
21
  Temperature,
20
22
  Visibility,
@@ -32,12 +34,15 @@ _RESPONSES = [
32
34
  (CurrentConditionsResponse, "current_conditions"),
33
35
  (DailyForecastResponse, "daily_forecast"),
34
36
  (HourlyForecastResponse, "hourly_forecast_page1"),
37
+ (MinuteForecastResponse, "minute_forecast"),
35
38
  ]
36
39
 
37
40
  _ENUMS = [
38
41
  IceThickness.Unit,
39
42
  MoonEvents.MoonPhase,
40
43
  PrecipitationProbability.PrecipitationType,
44
+ PrecipitationSegment.DominantPrecipitationType,
45
+ PrecipitationSegment.PrecipitationIntensity,
41
46
  QuantitativePrecipitationForecast.Unit,
42
47
  Temperature.TemperatureUnit,
43
48
  Visibility.Unit,
@@ -141,3 +146,32 @@ def test_next_page_token_is_optional() -> None:
141
146
  data.pop("nextPageToken", None)
142
147
 
143
148
  assert DailyForecastResponse.from_dict(data).next_page_token is None
149
+
150
+
151
+ def test_minute_forecast_segment_defaults() -> None:
152
+ """Test parsing a minute forecast where proto3-default segment fields are omitted."""
153
+ response = MinuteForecastResponse.from_dict(
154
+ {
155
+ "overallPredictionTimeframe": {"startTime": "2026-08-11T14:17:00Z"},
156
+ "timeZone": {"id": "America/New_York"},
157
+ "segments": [{"timeFrame": {"startTime": "2026-08-11T14:16:00Z"}, "type": "NONE"}],
158
+ }
159
+ )
160
+ segment = response.segments[0]
161
+ assert segment.type is PrecipitationSegment.DominantPrecipitationType.NONE
162
+ assert segment.probability == 0
163
+ assert segment.qpf is None
164
+ assert segment.snowfall_amount is None
165
+ assert segment.intensity is PrecipitationSegment.PrecipitationIntensity.PRECIPITATION_INTENSITY_UNSPECIFIED
166
+ assert response.next_page_token is None
167
+
168
+
169
+ def test_minute_forecast_without_segments() -> None:
170
+ """Test parsing a minute forecast response where the segments list is omitted."""
171
+ response = MinuteForecastResponse.from_dict(
172
+ {
173
+ "overallPredictionTimeframe": {"startTime": "2026-08-11T14:17:00Z"},
174
+ "timeZone": {"id": "America/New_York"},
175
+ }
176
+ )
177
+ assert response.segments == []