disruptapi 0.2.0__py3-none-any.whl

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.
@@ -0,0 +1,315 @@
1
+ """Resources for the async client. Mirrors sync.py method for method."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import date
6
+ from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, Iterable, List, Optional, Union
7
+
8
+ from ..pagination import AsyncPage, AsyncPaginator
9
+ from ..types import (
10
+ AirportProfile,
11
+ CarrierProfile,
12
+ Change,
13
+ ChangePage,
14
+ Deleted,
15
+ ExposureResult,
16
+ FailureLayer,
17
+ Forecast,
18
+ Incident,
19
+ ItemLike,
20
+ ItemsUpsertResult,
21
+ PastEvent,
22
+ Provider,
23
+ Severity,
24
+ SeverityLevel,
25
+ Signal,
26
+ Source,
27
+ Watchlist,
28
+ WatchlistList,
29
+ Webhook,
30
+ WebhookDelivery,
31
+ WebhookFilters,
32
+ WebhookFormat,
33
+ )
34
+ from ..webhooks import Webhooks as _WebhookHelpers
35
+ from . import _specs as s
36
+
37
+ if TYPE_CHECKING:
38
+ from .._base_client import AsyncAPIClient
39
+
40
+ _UNSET: Any = object()
41
+
42
+
43
+ class _Resource:
44
+ def __init__(self, client: "AsyncAPIClient") -> None:
45
+ self._client = client
46
+
47
+ async def _data(self, spec: Any) -> Any:
48
+ return (await self._client.request(spec)).data
49
+
50
+
51
+ class Signals(_Resource):
52
+ def list(self, *, status: Optional[str] = None, type: s.Types = None, min_severity: Optional[Severity] = None,
53
+ country: Optional[str] = None, airport: Optional[str] = None, provider: Optional[str] = None,
54
+ since: s.Since = None, limit: Optional[int] = None, offset: int = 0,
55
+ include: Optional[str] = None) -> AsyncPaginator[Signal]:
56
+ """``GET /v1/signals``. ``await`` it for the first page, or ``async for`` over it to walk every page.
57
+
58
+ ``type`` takes one type or a list. ``since`` takes a string or a datetime (sent as
59
+ ``YYYY-MM-DDTHH:MM:SSZ``). ``include="outlook"`` adds each signal's history-based outlook
60
+ (slower: use small pages). Records returned count against the daily record budget.
61
+ """
62
+ async def fetch(off: int) -> Any:
63
+ return await self._client.request(s.signals_list(
64
+ status=status, type=type, min_severity=min_severity, country=country, airport=airport,
65
+ provider=provider, since=since, limit=limit, offset=off, include=include))
66
+ async def start() -> Any:
67
+ return AsyncPage(await fetch(offset), fetch)
68
+ return AsyncPaginator(start)
69
+
70
+ async def get(self, signal_id: str) -> Signal:
71
+ """``GET /v1/signals/{signal_id}``, with ``impact_forecast``."""
72
+ return await self._data(s.signals_get(signal_id)) # type: ignore[no-any-return]
73
+
74
+
75
+ class Events(_Resource):
76
+ def list(self, *, provider: Optional[str] = None, failure_layer: Optional[str] = None,
77
+ anchor_only: Optional[bool] = None, limit: Optional[int] = None, offset: int = 0) -> AsyncPaginator[PastEvent]:
78
+ """``GET /v1/events``: the catalogue of past disruptions."""
79
+ async def fetch(off: int) -> Any:
80
+ return await self._client.request(s.events_list(provider=provider, failure_layer=failure_layer,
81
+ anchor_only=anchor_only, limit=limit, offset=off))
82
+ async def start() -> Any:
83
+ return AsyncPage(await fetch(offset), fetch)
84
+ return AsyncPaginator(start)
85
+
86
+ async def get(self, event_id: str) -> PastEvent:
87
+ """``GET /v1/events/{event_id}``."""
88
+ return await self._data(s.events_get(event_id)) # type: ignore[no-any-return]
89
+
90
+
91
+ class Exposure(_Resource):
92
+ async def check(self, items: Optional[Iterable[ItemLike]] = None, *, trips: Optional[Iterable[ItemLike]] = None,
93
+ min_severity: Optional[Severity] = None) -> List[ExposureResult]:
94
+ """``POST /v1/exposure/check``: one result per item, in request order (up to 500)."""
95
+ return await self._data(s.exposure_check(items, trips, min_severity)) # type: ignore[no-any-return]
96
+
97
+
98
+ class Forecasts(_Resource):
99
+ async def get(self, *, failure_layer: str, provider: Optional[str] = None) -> Forecast:
100
+ """``GET /v1/forecast``."""
101
+ return await self._data(s.forecast_get(failure_layer, provider)) # type: ignore[no-any-return]
102
+
103
+
104
+ class FailureLayers(_Resource):
105
+ async def list(self) -> List[FailureLayer]:
106
+ """``GET /v1/failure-layers``."""
107
+ return await self._data(s.failure_layers_list()) # type: ignore[no-any-return]
108
+
109
+
110
+ class WatchlistItems(_Resource):
111
+ async def upsert(self, wl_id: str, items: Iterable[ItemLike], *,
112
+ idempotency_key: Optional[str] = None) -> ItemsUpsertResult:
113
+ """``POST /v1/watchlists/{wl_id}/items``: add or replace items, keyed by your ``id``."""
114
+ return await self._data(s.items_upsert(wl_id, items, idempotency_key)) # type: ignore[no-any-return]
115
+
116
+ async def remove(self, wl_id: str, ref: str) -> Deleted:
117
+ """``DELETE /v1/watchlists/{wl_id}/items/{ref}``."""
118
+ return await self._data(s.items_remove(wl_id, ref)) # type: ignore[no-any-return]
119
+
120
+
121
+ class Watchlists(_Resource):
122
+ def __init__(self, client: "AsyncAPIClient") -> None:
123
+ super().__init__(client)
124
+ self.items = WatchlistItems(client)
125
+
126
+ async def list(self) -> WatchlistList:
127
+ """``GET /v1/watchlists``: ``{"data": [...], "limits": {"watch_items", "used"}}``."""
128
+ r = await self._client.request(s.watchlists_list())
129
+ return {"data": r.data or [], "limits": (r.body or {}).get("limits")} # type: ignore[typeddict-item]
130
+
131
+ async def create(self, *, name: str, description: Optional[str] = None,
132
+ items: Optional[Iterable[ItemLike]] = None, idempotency_key: Optional[str] = None) -> Watchlist:
133
+ """``POST /v1/watchlists``. Sends an ``Idempotency-Key`` (yours, or a new one per call), so
134
+ retries after a network error or 5xx cannot create a duplicate."""
135
+ return await self._data(s.watchlists_create(name, description, items, idempotency_key)) # type: ignore[no-any-return]
136
+
137
+ async def get(self, wl_id: str, *, limit: Optional[int] = None, after: Optional[str] = None) -> Watchlist:
138
+ """``GET /v1/watchlists/{wl_id}`` with up to ``limit`` live items (1 to 1000, default 100).
139
+ For the next items pass ``after=`` the response's ``meta.next_after`` (in ``items_meta``)."""
140
+ r = await self._client.request(s.watchlists_get(wl_id, limit, after))
141
+ out = dict(r.data or {})
142
+ meta = (r.body or {}).get("meta") if isinstance(r.body, dict) else None
143
+ if meta is not None:
144
+ out["items_meta"] = meta
145
+ return out # type: ignore[return-value]
146
+
147
+ async def update(self, wl_id: str, *, name: Optional[str] = None, description: Optional[str] = _UNSET) -> Watchlist:
148
+ """``PATCH /v1/watchlists/{wl_id}``."""
149
+ fields: Dict[str, Any] = {}
150
+ if name is not None:
151
+ fields["name"] = name
152
+ if description is not _UNSET:
153
+ fields["description"] = description
154
+ return await self._data(s.watchlists_update(wl_id, fields)) # type: ignore[no-any-return]
155
+
156
+ async def delete(self, wl_id: str) -> Deleted:
157
+ """``DELETE /v1/watchlists/{wl_id}``."""
158
+ return await self._data(s.watchlists_delete(wl_id)) # type: ignore[no-any-return]
159
+
160
+ async def exposure(self, wl_id: str, *, min_severity: Optional[Severity] = None) -> List[ExposureResult]:
161
+ """``GET /v1/watchlists/{wl_id}/exposure``: items active signals touch right now."""
162
+ return await self._data(s.watchlists_exposure(wl_id, min_severity)) # type: ignore[no-any-return]
163
+
164
+
165
+ class Airports(_Resource):
166
+ async def get(self, iata: str) -> AirportProfile:
167
+ """``GET /v1/airports/{iata}``."""
168
+ return await self._data(s.airports_get(iata)) # type: ignore[no-any-return]
169
+
170
+ async def faa_outlook(self, iata: str) -> Dict[str, Any]:
171
+ """``GET /v1/airports/{iata}/faa-outlook``: the chance of an FAA ground stop or delay program."""
172
+ return await self._data(s.airports_faa_outlook(iata)) # type: ignore[no-any-return]
173
+
174
+ async def observed_weather(self, iata: str, *, start: s.Since, end: s.Since) -> Dict[str, Any]:
175
+ """``GET /v1/airports/{iata}/observed-weather?from=&to=``: the METARs over a past window
176
+ (at most 48 hours) with the hazards read in them."""
177
+ return await self._data(s.airports_observed_weather(iata, start, end)) # type: ignore[no-any-return]
178
+
179
+
180
+ class Carriers(_Resource):
181
+ async def get(self, code: str) -> CarrierProfile:
182
+ """``GET /v1/carriers/{code}``. 404 when there is no data for the code yet."""
183
+ return await self._data(s.carriers_get(code)) # type: ignore[no-any-return]
184
+
185
+
186
+ class Sources(_Resource):
187
+ async def list(self) -> List[Source]:
188
+ """``GET /v1/sources``."""
189
+ return await self._data(s.sources_list()) # type: ignore[no-any-return]
190
+
191
+
192
+ class Providers(_Resource):
193
+ async def list(self) -> List[Provider]:
194
+ """``GET /v1/providers``."""
195
+ return await self._data(s.providers_list()) # type: ignore[no-any-return]
196
+
197
+
198
+ class Webhooks(_Resource, _WebhookHelpers):
199
+ async def list(self) -> List[Webhook]:
200
+ """``GET /v1/webhooks``: newest first, disabled ones included, secrets cut."""
201
+ return await self._data(s.webhooks_list()) # type: ignore[no-any-return]
202
+
203
+ async def create(self, *, url: str, filters: Optional[WebhookFilters] = None, format: Optional[WebhookFormat] = None,
204
+ routing_key: Optional[str] = None, idempotency_key: Optional[str] = None) -> Webhook:
205
+ """``POST /v1/webhooks``. The full ``secret`` is in this response only. ``format`` is ``json``
206
+ (default), ``slack``, ``teams`` or ``pagerduty`` (with ``routing_key``, your PagerDuty
207
+ integration key). Sends an ``Idempotency-Key``, so it is retried safely."""
208
+ return await self._data(s.webhooks_create(url, filters, format, routing_key, idempotency_key)) # type: ignore[no-any-return]
209
+
210
+ async def get(self, hook_id: str) -> Webhook:
211
+ """``GET /v1/webhooks/{hook_id}``."""
212
+ return await self._data(s.webhooks_get(hook_id)) # type: ignore[no-any-return]
213
+
214
+ async def update(self, hook_id: str, *, url: Optional[str] = None, filters: Optional[WebhookFilters] = _UNSET) -> Webhook:
215
+ """``PATCH /v1/webhooks/{hook_id}``."""
216
+ fields: Dict[str, Any] = {}
217
+ if url is not None:
218
+ fields["url"] = url
219
+ if filters is not _UNSET:
220
+ fields["filters"] = filters
221
+ return await self._data(s.webhooks_update(hook_id, fields)) # type: ignore[no-any-return]
222
+
223
+ async def rotate_secret(self, hook_id: str, *, idempotency_key: Optional[str] = None) -> Webhook:
224
+ """``POST /v1/webhooks/{hook_id}/rotate-secret``: a new ``secret`` (in this response only); the
225
+ old one keeps signing too for 24 hours so you can switch over."""
226
+ return await self._data(s.webhooks_rotate_secret(hook_id, idempotency_key)) # type: ignore[no-any-return]
227
+
228
+ async def deliveries(self, hook_id: str, *, status: Optional[str] = None, before: Optional[str] = None,
229
+ limit: Optional[int] = None) -> List[WebhookDelivery]:
230
+ """``GET /v1/webhooks/{hook_id}/deliveries``: newest first, kept 90 days. ``status`` is
231
+ ``pending``, ``delivered`` or ``failed``; ``before`` a delivery id, for older ones."""
232
+ return await self._data(s.webhooks_deliveries(hook_id, status, before, limit)) # type: ignore[no-any-return]
233
+
234
+ async def redeliver(self, hook_id: str, delivery_id: str) -> WebhookDelivery:
235
+ """``POST /v1/webhooks/{hook_id}/deliveries/{delivery_id}/redeliver``: queue the same payload again."""
236
+ return await self._data(s.webhooks_redeliver(hook_id, delivery_id)) # type: ignore[no-any-return]
237
+
238
+ async def test(self, hook_id: str) -> Dict[str, Any]:
239
+ """``POST /v1/webhooks/{hook_id}/test``: send a test event now and report the receiver's answer."""
240
+ return await self._data(s.webhooks_test(hook_id)) # type: ignore[no-any-return]
241
+
242
+ async def delete(self, hook_id: str) -> Deleted:
243
+ """``DELETE /v1/webhooks/{hook_id}``: disables it. 404 if already disabled."""
244
+ return await self._data(s.webhooks_delete(hook_id)) # type: ignore[no-any-return]
245
+
246
+
247
+ class Changes(_Resource):
248
+ async def list(self, *, after: Optional[str] = None, limit: Optional[int] = None) -> ChangePage:
249
+ """``GET /v1/changes``: every signal create, update and resolve in order, oldest first.
250
+ Pass ``after=`` the previous page's ``meta["next_cursor"]`` (or a change's ``cursor``).
251
+ Cursors last 30 days; an older one raises :class:`GoneError` (code ``cursor_expired``)."""
252
+ r = await self._client.request(s.changes_list(after, limit))
253
+ body = r.body if isinstance(r.body, dict) else {}
254
+ return {"data": r.data or [], "meta": body.get("meta") or {}}
255
+
256
+ async def iter(self, *, after: Optional[str] = None, limit: Optional[int] = None) -> AsyncIterator[Change]:
257
+ """Every change from ``after`` to the newest, page by page. Keep the last item's ``cursor``
258
+ and call again later to continue."""
259
+ while True:
260
+ page = await self.list(after=after, limit=limit)
261
+ for item in page["data"]:
262
+ yield item
263
+ meta = page["meta"]
264
+ if not meta.get("has_more") or not meta.get("next_cursor"):
265
+ return
266
+ after = meta["next_cursor"]
267
+
268
+
269
+ class Incidents(_Resource):
270
+ def list(self, *, status: Optional[str] = None, type: s.Types = None, min_severity: Optional[Severity] = None,
271
+ country: Optional[str] = None, airport: Optional[str] = None, limit: Optional[int] = None,
272
+ offset: int = 0) -> AsyncPaginator[Incident]:
273
+ """``GET /v1/incidents``: signals grouped into one incident each (a storm, an outage)."""
274
+ async def fetch(off: int) -> Any:
275
+ return await self._client.request(s.incidents_list(
276
+ status=status, type=type, min_severity=min_severity, country=country, airport=airport,
277
+ limit=limit, offset=off))
278
+
279
+ async def start() -> AsyncPage[Incident]:
280
+ return AsyncPage(await fetch(offset), fetch)
281
+ return AsyncPaginator(start)
282
+
283
+ async def get(self, incident_id: str) -> Incident:
284
+ """``GET /v1/incidents/{incident_id}`` with its signals."""
285
+ return await self._data(s.incidents_get(incident_id)) # type: ignore[no-any-return]
286
+
287
+
288
+ class Severities(_Resource):
289
+ async def list(self) -> List[SeverityLevel]:
290
+ """``GET /v1/severities``: the four levels, their rank and what each means."""
291
+ return await self._data(s.severities_list()) # type: ignore[no-any-return]
292
+
293
+
294
+ class Flights(_Resource):
295
+ async def outcome(self, *, carrier: str, flight_number: int, date: Union[str, date], origin: Optional[str] = None,
296
+ destination: Optional[str] = None) -> List[Dict[str, Any]]:
297
+ """``GET /v1/flights/outcome``: what happened to a US domestic flight, as the airline
298
+ reported it to the US DOT (one leg per segment). About two months behind."""
299
+ return await self._data(s.flights_outcome(carrier, flight_number, date, origin, destination)) # type: ignore[no-any-return]
300
+
301
+ async def outlook(self, *, carrier: str, origin: str, destination: str, date: Union[str, date],
302
+ departure_time: Optional[str] = None) -> Dict[str, Any]:
303
+ """``GET /v1/flights/outlook``: the chance a US domestic flight is cancelled or leaves 15, 60
304
+ or 180 minutes late (``probabilities``), from yesterday to 14 days ahead."""
305
+ return await self._data(s.flights_outlook(carrier, origin, destination, date, departure_time)) # type: ignore[no-any-return]
306
+
307
+
308
+ class Evidence(_Resource):
309
+ async def get(self, *, date: Union[str, date], airport: Optional[str] = None, origin: Optional[str] = None,
310
+ destination: Optional[str] = None, carrier: Optional[str] = None,
311
+ flight_number: Optional[int] = None) -> Dict[str, Any]:
312
+ """``GET /v1/evidence``: a claims evidence pack for an airport, a route (``origin`` and
313
+ ``destination``) or a flight (``carrier`` and ``flight_number``) on one day (JSON form)."""
314
+ return await self._data(s.evidence_get(date_=date, airport=airport, origin=origin, # type: ignore[no-any-return]
315
+ destination=destination, carrier=carrier, flight_number=flight_number))
@@ -0,0 +1,307 @@
1
+ """Resources for the sync client."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import date
6
+ from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Optional, Union
7
+
8
+ from ..pagination import SyncPage
9
+ from ..types import (
10
+ AirportProfile,
11
+ CarrierProfile,
12
+ Change,
13
+ ChangePage,
14
+ Deleted,
15
+ ExposureResult,
16
+ FailureLayer,
17
+ Forecast,
18
+ Incident,
19
+ ItemLike,
20
+ ItemsUpsertResult,
21
+ PastEvent,
22
+ Provider,
23
+ Severity,
24
+ SeverityLevel,
25
+ Signal,
26
+ Source,
27
+ Watchlist,
28
+ WatchlistList,
29
+ Webhook,
30
+ WebhookDelivery,
31
+ WebhookFilters,
32
+ WebhookFormat,
33
+ )
34
+ from ..webhooks import Webhooks as _WebhookHelpers
35
+ from . import _specs as s
36
+
37
+ if TYPE_CHECKING:
38
+ from .._base_client import SyncAPIClient
39
+
40
+ _UNSET: Any = object()
41
+
42
+
43
+ class _Resource:
44
+ def __init__(self, client: "SyncAPIClient") -> None:
45
+ self._client = client
46
+
47
+ def _data(self, spec: Any) -> Any:
48
+ return self._client.request(spec).data
49
+
50
+
51
+ class Signals(_Resource):
52
+ def list(self, *, status: Optional[str] = None, type: s.Types = None, min_severity: Optional[Severity] = None,
53
+ country: Optional[str] = None, airport: Optional[str] = None, provider: Optional[str] = None,
54
+ since: s.Since = None, limit: Optional[int] = None, offset: int = 0,
55
+ include: Optional[str] = None) -> SyncPage[Signal]:
56
+ """``GET /v1/signals``. Returns the first page; iterate it to walk every page.
57
+
58
+ ``type`` takes one type or a list. ``since`` takes a string or a datetime (sent as
59
+ ``YYYY-MM-DDTHH:MM:SSZ``). ``include="outlook"`` adds each signal's history-based outlook
60
+ (slower: use small pages). Records returned count against the daily record budget.
61
+ """
62
+ def fetch(off: int) -> Any:
63
+ return self._client.request(s.signals_list(
64
+ status=status, type=type, min_severity=min_severity, country=country, airport=airport,
65
+ provider=provider, since=since, limit=limit, offset=off, include=include))
66
+ return SyncPage(fetch(offset), fetch)
67
+
68
+ def get(self, signal_id: str) -> Signal:
69
+ """``GET /v1/signals/{signal_id}``, with ``impact_forecast``."""
70
+ return self._data(s.signals_get(signal_id)) # type: ignore[no-any-return]
71
+
72
+
73
+ class Events(_Resource):
74
+ def list(self, *, provider: Optional[str] = None, failure_layer: Optional[str] = None,
75
+ anchor_only: Optional[bool] = None, limit: Optional[int] = None, offset: int = 0) -> SyncPage[PastEvent]:
76
+ """``GET /v1/events``: the catalogue of past disruptions."""
77
+ def fetch(off: int) -> Any:
78
+ return self._client.request(s.events_list(provider=provider, failure_layer=failure_layer,
79
+ anchor_only=anchor_only, limit=limit, offset=off))
80
+ return SyncPage(fetch(offset), fetch)
81
+
82
+ def get(self, event_id: str) -> PastEvent:
83
+ """``GET /v1/events/{event_id}``."""
84
+ return self._data(s.events_get(event_id)) # type: ignore[no-any-return]
85
+
86
+
87
+ class Exposure(_Resource):
88
+ def check(self, items: Optional[Iterable[ItemLike]] = None, *, trips: Optional[Iterable[ItemLike]] = None,
89
+ min_severity: Optional[Severity] = None) -> List[ExposureResult]:
90
+ """``POST /v1/exposure/check``: one result per item, in request order (up to 500)."""
91
+ return self._data(s.exposure_check(items, trips, min_severity)) # type: ignore[no-any-return]
92
+
93
+
94
+ class Forecasts(_Resource):
95
+ def get(self, *, failure_layer: str, provider: Optional[str] = None) -> Forecast:
96
+ """``GET /v1/forecast``."""
97
+ return self._data(s.forecast_get(failure_layer, provider)) # type: ignore[no-any-return]
98
+
99
+
100
+ class FailureLayers(_Resource):
101
+ def list(self) -> List[FailureLayer]:
102
+ """``GET /v1/failure-layers``."""
103
+ return self._data(s.failure_layers_list()) # type: ignore[no-any-return]
104
+
105
+
106
+ class WatchlistItems(_Resource):
107
+ def upsert(self, wl_id: str, items: Iterable[ItemLike], *,
108
+ idempotency_key: Optional[str] = None) -> ItemsUpsertResult:
109
+ """``POST /v1/watchlists/{wl_id}/items``: add or replace items, keyed by your ``id``."""
110
+ return self._data(s.items_upsert(wl_id, items, idempotency_key)) # type: ignore[no-any-return]
111
+
112
+ def remove(self, wl_id: str, ref: str) -> Deleted:
113
+ """``DELETE /v1/watchlists/{wl_id}/items/{ref}``."""
114
+ return self._data(s.items_remove(wl_id, ref)) # type: ignore[no-any-return]
115
+
116
+
117
+ class Watchlists(_Resource):
118
+ def __init__(self, client: "SyncAPIClient") -> None:
119
+ super().__init__(client)
120
+ self.items = WatchlistItems(client)
121
+
122
+ def list(self) -> WatchlistList:
123
+ """``GET /v1/watchlists``: ``{"data": [...], "limits": {"watch_items", "used"}}``."""
124
+ r = self._client.request(s.watchlists_list())
125
+ return {"data": r.data or [], "limits": (r.body or {}).get("limits")} # type: ignore[typeddict-item]
126
+
127
+ def create(self, *, name: str, description: Optional[str] = None,
128
+ items: Optional[Iterable[ItemLike]] = None, idempotency_key: Optional[str] = None) -> Watchlist:
129
+ """``POST /v1/watchlists``. Sends an ``Idempotency-Key`` (yours, or a new one per call), so
130
+ retries after a network error or 5xx cannot create a duplicate."""
131
+ return self._data(s.watchlists_create(name, description, items, idempotency_key)) # type: ignore[no-any-return]
132
+
133
+ def get(self, wl_id: str, *, limit: Optional[int] = None, after: Optional[str] = None) -> Watchlist:
134
+ """``GET /v1/watchlists/{wl_id}`` with up to ``limit`` live items (1 to 1000, default 100).
135
+ For the next items pass ``after=`` the response's ``meta.next_after`` (in ``items_meta``)."""
136
+ r = self._client.request(s.watchlists_get(wl_id, limit, after))
137
+ out = dict(r.data or {})
138
+ meta = (r.body or {}).get("meta") if isinstance(r.body, dict) else None
139
+ if meta is not None:
140
+ out["items_meta"] = meta
141
+ return out # type: ignore[return-value]
142
+
143
+ def update(self, wl_id: str, *, name: Optional[str] = None, description: Optional[str] = _UNSET) -> Watchlist:
144
+ """``PATCH /v1/watchlists/{wl_id}``."""
145
+ fields: Dict[str, Any] = {}
146
+ if name is not None:
147
+ fields["name"] = name
148
+ if description is not _UNSET:
149
+ fields["description"] = description
150
+ return self._data(s.watchlists_update(wl_id, fields)) # type: ignore[no-any-return]
151
+
152
+ def delete(self, wl_id: str) -> Deleted:
153
+ """``DELETE /v1/watchlists/{wl_id}``."""
154
+ return self._data(s.watchlists_delete(wl_id)) # type: ignore[no-any-return]
155
+
156
+ def exposure(self, wl_id: str, *, min_severity: Optional[Severity] = None) -> List[ExposureResult]:
157
+ """``GET /v1/watchlists/{wl_id}/exposure``: items active signals touch right now."""
158
+ return self._data(s.watchlists_exposure(wl_id, min_severity)) # type: ignore[no-any-return]
159
+
160
+
161
+ class Airports(_Resource):
162
+ def get(self, iata: str) -> AirportProfile:
163
+ """``GET /v1/airports/{iata}``."""
164
+ return self._data(s.airports_get(iata)) # type: ignore[no-any-return]
165
+
166
+ def faa_outlook(self, iata: str) -> Dict[str, Any]:
167
+ """``GET /v1/airports/{iata}/faa-outlook``: the chance of an FAA ground stop or delay program."""
168
+ return self._data(s.airports_faa_outlook(iata)) # type: ignore[no-any-return]
169
+
170
+ def observed_weather(self, iata: str, *, start: s.Since, end: s.Since) -> Dict[str, Any]:
171
+ """``GET /v1/airports/{iata}/observed-weather?from=&to=``: the METARs over a past window
172
+ (at most 48 hours) with the hazards read in them."""
173
+ return self._data(s.airports_observed_weather(iata, start, end)) # type: ignore[no-any-return]
174
+
175
+
176
+ class Carriers(_Resource):
177
+ def get(self, code: str) -> CarrierProfile:
178
+ """``GET /v1/carriers/{code}``. 404 when there is no data for the code yet."""
179
+ return self._data(s.carriers_get(code)) # type: ignore[no-any-return]
180
+
181
+
182
+ class Sources(_Resource):
183
+ def list(self) -> List[Source]:
184
+ """``GET /v1/sources``."""
185
+ return self._data(s.sources_list()) # type: ignore[no-any-return]
186
+
187
+
188
+ class Providers(_Resource):
189
+ def list(self) -> List[Provider]:
190
+ """``GET /v1/providers``."""
191
+ return self._data(s.providers_list()) # type: ignore[no-any-return]
192
+
193
+
194
+ class Webhooks(_Resource, _WebhookHelpers):
195
+ def list(self) -> List[Webhook]:
196
+ """``GET /v1/webhooks``: newest first, disabled ones included, secrets cut."""
197
+ return self._data(s.webhooks_list()) # type: ignore[no-any-return]
198
+
199
+ def create(self, *, url: str, filters: Optional[WebhookFilters] = None, format: Optional[WebhookFormat] = None,
200
+ routing_key: Optional[str] = None, idempotency_key: Optional[str] = None) -> Webhook:
201
+ """``POST /v1/webhooks``. The full ``secret`` is in this response only. ``format`` is ``json``
202
+ (default), ``slack``, ``teams`` or ``pagerduty`` (with ``routing_key``, your PagerDuty
203
+ integration key). Sends an ``Idempotency-Key``, so it is retried safely."""
204
+ return self._data(s.webhooks_create(url, filters, format, routing_key, idempotency_key)) # type: ignore[no-any-return]
205
+
206
+ def get(self, hook_id: str) -> Webhook:
207
+ """``GET /v1/webhooks/{hook_id}``."""
208
+ return self._data(s.webhooks_get(hook_id)) # type: ignore[no-any-return]
209
+
210
+ def update(self, hook_id: str, *, url: Optional[str] = None, filters: Optional[WebhookFilters] = _UNSET) -> Webhook:
211
+ """``PATCH /v1/webhooks/{hook_id}``."""
212
+ fields: Dict[str, Any] = {}
213
+ if url is not None:
214
+ fields["url"] = url
215
+ if filters is not _UNSET:
216
+ fields["filters"] = filters
217
+ return self._data(s.webhooks_update(hook_id, fields)) # type: ignore[no-any-return]
218
+
219
+ def rotate_secret(self, hook_id: str, *, idempotency_key: Optional[str] = None) -> Webhook:
220
+ """``POST /v1/webhooks/{hook_id}/rotate-secret``: a new ``secret`` (in this response only); the
221
+ old one keeps signing too for 24 hours so you can switch over."""
222
+ return self._data(s.webhooks_rotate_secret(hook_id, idempotency_key)) # type: ignore[no-any-return]
223
+
224
+ def deliveries(self, hook_id: str, *, status: Optional[str] = None, before: Optional[str] = None,
225
+ limit: Optional[int] = None) -> List[WebhookDelivery]:
226
+ """``GET /v1/webhooks/{hook_id}/deliveries``: newest first, kept 90 days. ``status`` is
227
+ ``pending``, ``delivered`` or ``failed``; ``before`` a delivery id, for older ones."""
228
+ return self._data(s.webhooks_deliveries(hook_id, status, before, limit)) # type: ignore[no-any-return]
229
+
230
+ def redeliver(self, hook_id: str, delivery_id: str) -> WebhookDelivery:
231
+ """``POST /v1/webhooks/{hook_id}/deliveries/{delivery_id}/redeliver``: queue the same payload again."""
232
+ return self._data(s.webhooks_redeliver(hook_id, delivery_id)) # type: ignore[no-any-return]
233
+
234
+ def test(self, hook_id: str) -> Dict[str, Any]:
235
+ """``POST /v1/webhooks/{hook_id}/test``: send a test event now and report the receiver's answer."""
236
+ return self._data(s.webhooks_test(hook_id)) # type: ignore[no-any-return]
237
+
238
+ def delete(self, hook_id: str) -> Deleted:
239
+ """``DELETE /v1/webhooks/{hook_id}``: disables it. 404 if already disabled."""
240
+ return self._data(s.webhooks_delete(hook_id)) # type: ignore[no-any-return]
241
+
242
+
243
+ class Changes(_Resource):
244
+ def list(self, *, after: Optional[str] = None, limit: Optional[int] = None) -> ChangePage:
245
+ """``GET /v1/changes``: every signal create, update and resolve in order, oldest first.
246
+ Pass ``after=`` the previous page's ``meta["next_cursor"]`` (or a change's ``cursor``).
247
+ Cursors last 30 days; an older one raises :class:`GoneError` (code ``cursor_expired``)."""
248
+ r = self._client.request(s.changes_list(after, limit))
249
+ body = r.body if isinstance(r.body, dict) else {}
250
+ return {"data": r.data or [], "meta": body.get("meta") or {}}
251
+
252
+ def iter(self, *, after: Optional[str] = None, limit: Optional[int] = None) -> Iterator[Change]:
253
+ """Every change from ``after`` to the newest, page by page. Keep the last item's ``cursor``
254
+ and call again later to continue."""
255
+ while True:
256
+ page = self.list(after=after, limit=limit)
257
+ yield from page["data"]
258
+ meta = page["meta"]
259
+ if not meta.get("has_more") or not meta.get("next_cursor"):
260
+ return
261
+ after = meta["next_cursor"]
262
+
263
+
264
+ class Incidents(_Resource):
265
+ def list(self, *, status: Optional[str] = None, type: s.Types = None, min_severity: Optional[Severity] = None,
266
+ country: Optional[str] = None, airport: Optional[str] = None, limit: Optional[int] = None,
267
+ offset: int = 0) -> SyncPage[Incident]:
268
+ """``GET /v1/incidents``: signals grouped into one incident each (a storm, an outage)."""
269
+ def fetch(off: int) -> Any:
270
+ return self._client.request(s.incidents_list(
271
+ status=status, type=type, min_severity=min_severity, country=country, airport=airport,
272
+ limit=limit, offset=off))
273
+ return SyncPage(fetch(offset), fetch)
274
+
275
+ def get(self, incident_id: str) -> Incident:
276
+ """``GET /v1/incidents/{incident_id}`` with its signals."""
277
+ return self._data(s.incidents_get(incident_id)) # type: ignore[no-any-return]
278
+
279
+
280
+ class Severities(_Resource):
281
+ def list(self) -> List[SeverityLevel]:
282
+ """``GET /v1/severities``: the four levels, their rank and what each means."""
283
+ return self._data(s.severities_list()) # type: ignore[no-any-return]
284
+
285
+
286
+ class Flights(_Resource):
287
+ def outcome(self, *, carrier: str, flight_number: int, date: Union[str, date], origin: Optional[str] = None,
288
+ destination: Optional[str] = None) -> List[Dict[str, Any]]:
289
+ """``GET /v1/flights/outcome``: what happened to a US domestic flight, as the airline
290
+ reported it to the US DOT (one leg per segment). About two months behind."""
291
+ return self._data(s.flights_outcome(carrier, flight_number, date, origin, destination)) # type: ignore[no-any-return]
292
+
293
+ def outlook(self, *, carrier: str, origin: str, destination: str, date: Union[str, date],
294
+ departure_time: Optional[str] = None) -> Dict[str, Any]:
295
+ """``GET /v1/flights/outlook``: the chance a US domestic flight is cancelled or leaves 15, 60
296
+ or 180 minutes late (``probabilities``), from yesterday to 14 days ahead."""
297
+ return self._data(s.flights_outlook(carrier, origin, destination, date, departure_time)) # type: ignore[no-any-return]
298
+
299
+
300
+ class Evidence(_Resource):
301
+ def get(self, *, date: Union[str, date], airport: Optional[str] = None, origin: Optional[str] = None,
302
+ destination: Optional[str] = None, carrier: Optional[str] = None,
303
+ flight_number: Optional[int] = None) -> Dict[str, Any]:
304
+ """``GET /v1/evidence``: a claims evidence pack for an airport, a route (``origin`` and
305
+ ``destination``) or a flight (``carrier`` and ``flight_number``) on one day (JSON form)."""
306
+ return self._data(s.evidence_get(date_=date, airport=airport, origin=origin, # type: ignore[no-any-return]
307
+ destination=destination, carrier=carrier, flight_number=flight_number))