-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_client.py
More file actions
825 lines (660 loc) · 28.4 KB
/
Copy path_client.py
File metadata and controls
825 lines (660 loc) · 28.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
"""Public entry points: :class:`SkyLink` (blocking) and :class:`AsyncSkyLink`.
Besides the constructor, the ``request()`` escape hatch and lifecycle
management, this module attaches the resource namespaces. Each one is a
``functools.cached_property`` so that building a client stays free and only the
namespaces a program actually touches are instantiated.
"""
from __future__ import annotations
import time
from collections.abc import Awaitable, Callable, Mapping
from functools import cached_property
from typing import Any
import httpx
from ._base_client import AsyncAPIClient, SyncAPIClient, _default_async_sleep
from ._config import resolve_config
from ._types import (
NOT_GIVEN,
HistoryPlan,
NotGiven,
NotGivenOr,
Provider,
RequestOptions,
RequestSpec,
ResponseKind,
)
from .helpers.cache import CacheProtocol
from .models.distance import DistanceResponse
from .models.flight_status import FlightStatusResponse
from .resources.adsb import Adsb, AsyncAdsb
from .resources.aircraft import Aircraft, AsyncAircraft
from .resources.airlines import Airlines, AsyncAirlines
from .resources.airports import Airports, AsyncAirports
from .resources.batch import AsyncBatch, Batch
from .resources.briefing import AsyncBriefing, Briefing
from .resources.carbon import AsyncCarbon, Carbon
from .resources.charts import AsyncCharts, Charts
from .resources.compose import AsyncCompose, Compose
from .resources.delays import AsyncDelays, Delays
from .resources.distance import AsyncDistance, Distance, DistanceUnit
from .resources.flight_status import AsyncFlightStatus, FlightStatus
from .resources.geo import AsyncGeo, Geo
from .resources.history import AsyncHistory, History
from .resources.ml import AsyncMl, Ml
from .resources.navaids import AsyncNavaids, Navaids
from .resources.notams import AsyncNotams, Notams
from .resources.poll import AsyncPoll, Poll
from .resources.routes import AsyncRoutes, Routes
from .resources.schedules import AsyncSchedules, Schedules
from .resources.tickets import AsyncTickets, Tickets
from .resources.weather import AsyncWeather, Weather
from .resources.webhooks import AsyncWebhooks, Webhooks
__all__ = ["AsyncSkyLink", "SkyLink"]
class SkyLink(SyncAPIClient):
"""Blocking SkyLink API client.
Example::
from skylink_api import SkyLink
with SkyLink(api_key="...") as sky: # RapidAPI by default
data = sky.request("GET", "/weather/metar/KJFK")
Args:
api_key: API key. Falls back to the environment — ``RAPIDAPI_KEY`` and then
``SKYLINK_API_KEY`` on the rapidapi channel, ``SKYLINK_API_KEY`` on the
direct one. Required unless ``base_url`` is given.
provider: ``"rapidapi"`` (default, ``https://skylink-api.p.rapidapi.com``, no
version prefix) or ``"direct"`` (``https://data.skylinkapi.com/v3.1``).
base_url: Override the endpoint entirely — used verbatim, no version is
appended. With an explicit ``base_url`` a missing key is not an error,
so staging instances running ``DISABLE_AUTH=true`` just work.
timeout: Seconds or an :class:`httpx.Timeout`; ``None`` disables timeouts.
Default: connect 5s, read/write 30s, pool 5s.
max_retries: Retries for 429/500/502/503/504 and transport failures
(default 3).
history_plan: ``"ultra"`` (default) or ``"mega"`` — selects the
``/{plan}/history`` URL prefix; can be overridden per call.
default_headers: Extra headers merged into every request.
cache: Opt-in response cache — see
:class:`~skylink_api.helpers.cache.MemoryCache`. Only successful GETs
are cached, and only for operations with a non-zero TTL, so a cache
without rules changes nothing.
http_client: Bring your own httpx client (proxies, custom transport).
sleep: Backoff sleep function — injection point for tests.
environ: Environment mapping used for key lookup (defaults to ``os.environ``).
"""
def __init__(
self,
*,
api_key: str | None = None,
provider: Provider | None = None,
base_url: str | None = None,
timeout: NotGivenOr[float | httpx.Timeout | None] = NOT_GIVEN,
max_retries: int | None = None,
history_plan: HistoryPlan | None = None,
default_headers: Mapping[str, str] | None = None,
cache: CacheProtocol | None = None,
http_client: httpx.Client | None = None,
sleep: Callable[[float], None] = time.sleep,
environ: Mapping[str, str] | None = None,
) -> None:
config = resolve_config(
api_key=api_key,
provider=provider,
base_url=base_url,
timeout=timeout,
max_retries=max_retries,
history_plan=history_plan,
default_headers=default_headers,
environ=environ,
)
super().__init__(config, http_client=http_client, sleep=sleep, cache=cache)
# An explicit timeout must win even over a caller-supplied http_client's
# own configuration — otherwise it would be silently ignored.
if not isinstance(timeout, NotGiven):
self._apply_config_timeout = True
@property
def api_key(self) -> str | None:
return self._config.api_key
# ── alternative constructors ─────────────────────────────────────────────
@classmethod
def from_env(
cls,
*,
provider: Provider | None = None,
base_url: str | None = None,
timeout: NotGivenOr[float | httpx.Timeout | None] = NOT_GIVEN,
max_retries: int | None = None,
history_plan: HistoryPlan | None = None,
default_headers: Mapping[str, str] | None = None,
cache: CacheProtocol | None = None,
http_client: httpx.Client | None = None,
sleep: Callable[[float], None] = time.sleep,
environ: Mapping[str, str] | None = None,
) -> SkyLink:
"""Build a client whose key comes from the environment — and says so::
sky = SkyLink.from_env() # RAPIDAPI_KEY / SKYLINK_API_KEY
sky = SkyLink.from_env(provider="direct") # SKYLINK_API_KEY
Same behaviour as ``SkyLink()`` with no ``api_key``, minus the ambiguity:
there is no ``api_key`` argument to accidentally pass ``None`` to, so a
reader can see at a glance where the credential comes from. Everything
else may still be overridden. A missing variable raises
:class:`~skylink_api.AuthenticationError` (unless ``base_url`` is given).
"""
return cls(
provider=provider,
base_url=base_url,
timeout=timeout,
max_retries=max_retries,
history_plan=history_plan,
default_headers=default_headers,
cache=cache,
http_client=http_client,
sleep=sleep,
environ=environ,
)
def with_options(
self,
*,
timeout: NotGivenOr[float | httpx.Timeout | None] = NOT_GIVEN,
max_retries: NotGivenOr[int] = NOT_GIVEN,
history_plan: NotGivenOr[HistoryPlan] = NOT_GIVEN,
default_headers: NotGivenOr[Mapping[str, str]] = NOT_GIVEN,
cache: NotGivenOr[CacheProtocol | None] = NOT_GIVEN,
) -> SkyLink:
"""A clone with some settings changed, sharing this client's connections::
patient = sky.with_options(timeout=120.0, max_retries=0)
archive = sky.with_options(history_plan="mega")
The clone **reuses the same** :class:`httpx.Client`, so no second
connection pool is opened, and it starts with fresh namespaces (nothing
is carried over from ``sky.weather`` & co.). Registered quota hooks are
copied as a snapshot; later ``on_rate_limit`` calls on either client do
not reach the other.
Ownership of the transport stays with the original: closing the clone
(``close()`` or leaving its ``with`` block) leaves the pool open, and
closing the original closes it for both. Keep the original alive for as
long as any clone is in use.
``default_headers`` replaces the mapping rather than merging into it, so a
clone can also drop a header. Passing ``cache=None`` disables caching for
the clone; omitting it keeps this client's cache (shared, not copied).
"""
config = self._config.with_overrides(
timeout=timeout,
max_retries=max_retries,
history_plan=history_plan,
default_headers=default_headers,
)
cls = type(self)
clone = cls.__new__(cls)
SyncAPIClient.__init__(
clone,
config,
http_client=self._http_client,
sleep=self._sleep,
cache=self._cache if isinstance(cache, NotGiven) else cache,
owns_transport=False,
)
# The clone shares this client's pool, whose baked-in timeout would
# otherwise silently override the clone's — send the config value
# per-request whenever the parent did, or a timeout was just given.
clone._apply_config_timeout = self._apply_config_timeout or not isinstance(
timeout, NotGiven
)
clone._copy_hooks_from(self)
return clone
# ── namespaces ───────────────────────────────────────────────────────────
@cached_property
def weather(self) -> Weather:
"""METAR, TAF, winds aloft, PIREPs and AIRMET/SIGMET (``/weather/*``)."""
return Weather(self)
@cached_property
def airports(self) -> Airports:
"""Airport lookup by code, radius, text or client IP (``/airports/*``)."""
return Airports(self)
@cached_property
def airlines(self) -> Airlines:
"""Airline lookup by IATA/ICAO code, name or country (``/airlines/search``)."""
return Airlines(self)
@cached_property
def navaids(self) -> Navaids:
"""VOR/NDB/DME navigation aid search (``/navaids``)."""
return Navaids(self)
@cached_property
def geo(self) -> Geo:
"""Country and region reference data (``/countries``, ``/regions``)."""
return Geo(self)
@cached_property
def adsb(self) -> Adsb:
"""Live ADS-B positions, feed statistics and health (``/adsb/*``)."""
return Adsb(self)
@cached_property
def aircraft(self) -> Aircraft:
"""Airframe registry, type performance and database stats (``/aircraft/*``)."""
return Aircraft(self)
@cached_property
def charts(self) -> Charts:
"""Aerodrome chart links grouped by category (``/charts/*``)."""
return Charts(self)
@cached_property
def delays(self) -> Delays:
"""Live FAA NAS status — ground stops, ground delays, closures."""
return Delays(self)
@cached_property
def notams(self) -> Notams:
"""NOTAMs from the FAA SWIM feed (``/notams/{icao}``)."""
return Notams(self)
@cached_property
def schedules(self) -> Schedules:
"""Airport departure and arrival boards (``/schedules/{direction}``)."""
return Schedules(self)
@cached_property
def ml(self) -> Ml:
"""Model-backed predictions, e.g. block time (``/ml/flight-time``)."""
return Ml(self)
@cached_property
def carbon(self) -> Carbon:
"""CO2 emission estimates per passenger and cabin (``/carbon/estimate``)."""
return Carbon(self)
@cached_property
def briefing(self) -> Briefing:
"""Pre-flight briefings as JSON, text or PDF (``/briefing/*``)."""
return Briefing(self)
@cached_property
def routes(self) -> Routes:
"""Callsign to route resolution and route network data (``/routes/*``)."""
return Routes(self)
@cached_property
def tickets(self) -> Tickets:
"""Ticket availability and pricing (``/tickets/search``)."""
return Tickets(self)
@cached_property
def webhooks(self) -> Webhooks:
"""Push subscriptions for flight status changes (``/webhooks/*``)."""
return Webhooks(self)
@cached_property
def history(self) -> History:
"""Archived ADS-B flights, tracks and positions (``/{plan}/history/*``)."""
return History(self)
@cached_property
def batch(self) -> Batch:
"""The same call for many identifiers, bounded and failure tolerant.
``sky.batch.metars([...])`` and friends return
``{identifier: model | SkyLinkError}`` — see
:class:`~skylink_api.resources.batch.Batch`.
"""
return Batch(self)
@cached_property
def poll(self) -> Poll:
"""Endpoints on a timer, as iterators.
``sky.poll.flight_status("BA123")`` yields status changes until the
flight lands; ``sky.poll.adsb(bbox=...)`` yields feed diffs for a live
map. Both survive 429/5xx and take an injectable ``sleep`` — see
:class:`~skylink_api.resources.poll.Poll`.
"""
return Poll(self)
@cached_property
def compose(self) -> Compose:
"""Multi-endpoint aggregates: whole pages in one call.
``sky.compose.airport_brief("EGLL")`` fetches eight endpoints in
parallel and hands back one object where every failed part is ``None``
with its error in ``errors`` — see
:class:`~skylink_api.resources.compose.Compose`.
"""
return Compose(self)
# ── one-method namespaces, exposed as client methods ─────────────────────
@cached_property
def _flight_status(self) -> FlightStatus:
return FlightStatus(self)
@cached_property
def _distance(self) -> Distance:
return Distance(self)
def flight_status(
self,
flight_number: str,
*,
request_options: RequestOptions | None = None,
) -> FlightStatusResponse:
"""Status of one flight — ``GET /flight_status/{flight_number}``::
status = sky.flight_status("BA123")
Args:
flight_number: IATA (``"BA123"``) or ICAO (``"BAW123"``) form, 2-10
characters; the API upper-cases and strips it.
Note:
The payload is scraped: every field is an optional string, empty
values arrive as ``""`` or ``"--"``, and ``departure``/``arrival``
are **not** the same shape. See
:meth:`~skylink_api.resources.flight_status.FlightStatus.get`.
"""
return self._flight_status.get(flight_number, request_options=request_options)
def distance(
self,
*,
from_icao: str | None = None,
to_icao: str | None = None,
from_lat: float | None = None,
from_lon: float | None = None,
to_lat: float | None = None,
to_lon: float | None = None,
unit: DistanceUnit = "nm",
request_options: RequestOptions | None = None,
) -> DistanceResponse:
"""Great-circle distance and initial bearing — ``GET /distance``::
leg = sky.distance(from_icao="KJFK", to_icao="EGLL")
leg = sky.distance(from_lat=40.64, from_lon=-73.78, to_icao="EGLL", unit="km")
Each endpoint is given **either** as an airport code **or** as a
latitude/longitude pair, and the two styles mix freely. See
:meth:`~skylink_api.resources.distance.Distance.calculate` for the full
documentation.
"""
return self._distance.calculate(
from_icao=from_icao,
to_icao=to_icao,
from_lat=from_lat,
from_lon=from_lon,
to_lat=to_lat,
to_lon=to_lon,
unit=unit,
request_options=request_options,
)
# ── escape hatch ─────────────────────────────────────────────────────────
def request(
self,
method: str,
path: str,
*,
query: Mapping[str, Any] | None = None,
json_body: Any | None = None,
headers: Mapping[str, str] | None = None,
response_kind: ResponseKind = "json",
cast_to: Any = None,
options: RequestOptions | None = None,
) -> Any:
"""Escape hatch for endpoints this SDK does not model yet.
Applies the same auth, retry and error handling as the typed methods::
sky.request("GET", "/weather/metar/KJFK", query={"parsed": True})
"""
spec = RequestSpec(
method=method.upper(),
path=path,
query=query,
json_body=json_body,
headers=headers,
response_kind=response_kind,
cast_to=cast_to,
)
return self.execute(spec, options)
class AsyncSkyLink(AsyncAPIClient):
"""Asyncio SkyLink API client.
Example::
from skylink_api import AsyncSkyLink
async with AsyncSkyLink(api_key="...") as sky:
data = await sky.request("GET", "/weather/metar/KJFK")
Takes the same arguments as :class:`SkyLink`, except ``http_client`` is an
:class:`httpx.AsyncClient` and ``sleep`` is an awaitable callable.
"""
def __init__(
self,
*,
api_key: str | None = None,
provider: Provider | None = None,
base_url: str | None = None,
timeout: NotGivenOr[float | httpx.Timeout | None] = NOT_GIVEN,
max_retries: int | None = None,
history_plan: HistoryPlan | None = None,
default_headers: Mapping[str, str] | None = None,
cache: CacheProtocol | None = None,
http_client: httpx.AsyncClient | None = None,
sleep: Callable[[float], Awaitable[None]] = _default_async_sleep,
environ: Mapping[str, str] | None = None,
) -> None:
config = resolve_config(
api_key=api_key,
provider=provider,
base_url=base_url,
timeout=timeout,
max_retries=max_retries,
history_plan=history_plan,
default_headers=default_headers,
environ=environ,
)
super().__init__(config, http_client=http_client, sleep=sleep, cache=cache)
# An explicit timeout must win even over a caller-supplied http_client's
# own configuration — otherwise it would be silently ignored.
if not isinstance(timeout, NotGiven):
self._apply_config_timeout = True
@property
def api_key(self) -> str | None:
return self._config.api_key
# ── alternative constructors ─────────────────────────────────────────────
@classmethod
def from_env(
cls,
*,
provider: Provider | None = None,
base_url: str | None = None,
timeout: NotGivenOr[float | httpx.Timeout | None] = NOT_GIVEN,
max_retries: int | None = None,
history_plan: HistoryPlan | None = None,
default_headers: Mapping[str, str] | None = None,
cache: CacheProtocol | None = None,
http_client: httpx.AsyncClient | None = None,
sleep: Callable[[float], Awaitable[None]] = _default_async_sleep,
environ: Mapping[str, str] | None = None,
) -> AsyncSkyLink:
"""Build a client whose key comes from the environment — see
:meth:`SkyLink.from_env`::
async with AsyncSkyLink.from_env() as sky:
...
"""
return cls(
provider=provider,
base_url=base_url,
timeout=timeout,
max_retries=max_retries,
history_plan=history_plan,
default_headers=default_headers,
cache=cache,
http_client=http_client,
sleep=sleep,
environ=environ,
)
def with_options(
self,
*,
timeout: NotGivenOr[float | httpx.Timeout | None] = NOT_GIVEN,
max_retries: NotGivenOr[int] = NOT_GIVEN,
history_plan: NotGivenOr[HistoryPlan] = NOT_GIVEN,
default_headers: NotGivenOr[Mapping[str, str]] = NOT_GIVEN,
cache: NotGivenOr[CacheProtocol | None] = NOT_GIVEN,
) -> AsyncSkyLink:
"""A clone with some settings changed, sharing this client's connections.
Not a coroutine — the clone is built in place::
archive = sky.with_options(history_plan="mega")
flights = await archive.history.flights(icao24="4ca7b3")
Same semantics as :meth:`SkyLink.with_options`: the
:class:`httpx.AsyncClient` is reused, namespaces are not inherited, quota
hooks are copied as a snapshot, and the clone does not own the transport —
``await clone.aclose()`` leaves the original's pool open.
"""
config = self._config.with_overrides(
timeout=timeout,
max_retries=max_retries,
history_plan=history_plan,
default_headers=default_headers,
)
cls = type(self)
clone = cls.__new__(cls)
AsyncAPIClient.__init__(
clone,
config,
http_client=self._http_client,
sleep=self._sleep,
cache=self._cache if isinstance(cache, NotGiven) else cache,
owns_transport=False,
)
# See SkyLink.with_options: the shared pool's baked-in timeout must not
# silently override the clone's configured one.
clone._apply_config_timeout = self._apply_config_timeout or not isinstance(
timeout, NotGiven
)
clone._copy_hooks_from(self)
return clone
# ── namespaces ───────────────────────────────────────────────────────────
@cached_property
def weather(self) -> AsyncWeather:
"""METAR, TAF, winds aloft, PIREPs and AIRMET/SIGMET (``/weather/*``)."""
return AsyncWeather(self)
@cached_property
def airports(self) -> AsyncAirports:
"""Airport lookup by code, radius, text or client IP (``/airports/*``)."""
return AsyncAirports(self)
@cached_property
def airlines(self) -> AsyncAirlines:
"""Airline lookup by IATA/ICAO code, name or country (``/airlines/search``)."""
return AsyncAirlines(self)
@cached_property
def navaids(self) -> AsyncNavaids:
"""VOR/NDB/DME navigation aid search (``/navaids``)."""
return AsyncNavaids(self)
@cached_property
def geo(self) -> AsyncGeo:
"""Country and region reference data (``/countries``, ``/regions``)."""
return AsyncGeo(self)
@cached_property
def adsb(self) -> AsyncAdsb:
"""Live ADS-B positions, feed statistics and health (``/adsb/*``)."""
return AsyncAdsb(self)
@cached_property
def aircraft(self) -> AsyncAircraft:
"""Airframe registry, type performance and database stats (``/aircraft/*``)."""
return AsyncAircraft(self)
@cached_property
def charts(self) -> AsyncCharts:
"""Aerodrome chart links grouped by category (``/charts/*``)."""
return AsyncCharts(self)
@cached_property
def delays(self) -> AsyncDelays:
"""Live FAA NAS status — ground stops, ground delays, closures."""
return AsyncDelays(self)
@cached_property
def notams(self) -> AsyncNotams:
"""NOTAMs from the FAA SWIM feed (``/notams/{icao}``)."""
return AsyncNotams(self)
@cached_property
def schedules(self) -> AsyncSchedules:
"""Airport departure and arrival boards (``/schedules/{direction}``)."""
return AsyncSchedules(self)
@cached_property
def ml(self) -> AsyncMl:
"""Model-backed predictions, e.g. block time (``/ml/flight-time``)."""
return AsyncMl(self)
@cached_property
def carbon(self) -> AsyncCarbon:
"""CO2 emission estimates per passenger and cabin (``/carbon/estimate``)."""
return AsyncCarbon(self)
@cached_property
def briefing(self) -> AsyncBriefing:
"""Pre-flight briefings as JSON, text or PDF (``/briefing/*``)."""
return AsyncBriefing(self)
@cached_property
def routes(self) -> AsyncRoutes:
"""Callsign to route resolution and route network data (``/routes/*``)."""
return AsyncRoutes(self)
@cached_property
def tickets(self) -> AsyncTickets:
"""Ticket availability and pricing (``/tickets/search``)."""
return AsyncTickets(self)
@cached_property
def webhooks(self) -> AsyncWebhooks:
"""Push subscriptions for flight status changes (``/webhooks/*``)."""
return AsyncWebhooks(self)
@cached_property
def history(self) -> AsyncHistory:
"""Archived ADS-B flights, tracks and positions (``/{plan}/history/*``)."""
return AsyncHistory(self)
@cached_property
def batch(self) -> AsyncBatch:
"""The same call for many identifiers, bounded and failure tolerant.
``await sky.batch.metars([...])`` returns
``{identifier: model | SkyLinkError}`` — see
:class:`~skylink_api.resources.batch.AsyncBatch`.
"""
return AsyncBatch(self)
@cached_property
def poll(self) -> AsyncPoll:
"""Endpoints on a timer, as async iterators.
``async for status in sky.poll.flight_status("BA123")`` — see
:class:`~skylink_api.resources.poll.AsyncPoll`.
"""
return AsyncPoll(self)
@cached_property
def compose(self) -> AsyncCompose:
"""Multi-endpoint aggregates: whole pages in one call.
``await sky.compose.airport_brief("EGLL")`` — see
:class:`~skylink_api.resources.compose.AsyncCompose`.
"""
return AsyncCompose(self)
# ── one-method namespaces, exposed as client methods ─────────────────────
@cached_property
def _flight_status(self) -> AsyncFlightStatus:
return AsyncFlightStatus(self)
@cached_property
def _distance(self) -> AsyncDistance:
return AsyncDistance(self)
async def flight_status(
self,
flight_number: str,
*,
request_options: RequestOptions | None = None,
) -> FlightStatusResponse:
"""Status of one flight — ``GET /flight_status/{flight_number}``::
status = await sky.flight_status("BA123")
See :meth:`SkyLink.flight_status` for the argument and payload notes.
"""
return await self._flight_status.get(flight_number, request_options=request_options)
async def distance(
self,
*,
from_icao: str | None = None,
to_icao: str | None = None,
from_lat: float | None = None,
from_lon: float | None = None,
to_lat: float | None = None,
to_lon: float | None = None,
unit: DistanceUnit = "nm",
request_options: RequestOptions | None = None,
) -> DistanceResponse:
"""Great-circle distance and initial bearing — ``GET /distance``::
leg = await sky.distance(from_icao="KJFK", to_icao="EGLL")
See :meth:`SkyLink.distance` for the full documentation.
"""
return await self._distance.calculate(
from_icao=from_icao,
to_icao=to_icao,
from_lat=from_lat,
from_lon=from_lon,
to_lat=to_lat,
to_lon=to_lon,
unit=unit,
request_options=request_options,
)
# ── escape hatch ─────────────────────────────────────────────────────────
async def request(
self,
method: str,
path: str,
*,
query: Mapping[str, Any] | None = None,
json_body: Any | None = None,
headers: Mapping[str, str] | None = None,
response_kind: ResponseKind = "json",
cast_to: Any = None,
options: RequestOptions | None = None,
) -> Any:
"""Escape hatch for endpoints this SDK does not model yet."""
spec = RequestSpec(
method=method.upper(),
path=path,
query=query,
json_body=json_body,
headers=headers,
response_kind=response_kind,
cast_to=cast_to,
)
return await self.execute(spec, options)