|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import os |
6 | | -from typing import Any, Dict, Mapping, cast |
| 6 | +from typing import TYPE_CHECKING, Any, Dict, Mapping, cast |
7 | 7 | from typing_extensions import Self, Literal, override |
8 | 8 |
|
9 | 9 | import httpx |
|
20 | 20 | not_given, |
21 | 21 | ) |
22 | 22 | from ._utils import is_given, get_async_library |
| 23 | +from ._compat import cached_property |
23 | 24 | from ._version import __version__ |
24 | | -from .resources import quote, available |
25 | 25 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
26 | 26 | from ._exceptions import BrapiError, APIStatusError |
27 | 27 | from ._base_client import ( |
28 | 28 | DEFAULT_MAX_RETRIES, |
29 | 29 | SyncAPIClient, |
30 | 30 | AsyncAPIClient, |
31 | 31 | ) |
32 | | -from .resources.v2 import v2 |
| 32 | + |
| 33 | +if TYPE_CHECKING: |
| 34 | + from .resources import v2, quote, available |
| 35 | + from .resources.quote import QuoteResource, AsyncQuoteResource |
| 36 | + from .resources.v2.v2 import V2Resource, AsyncV2Resource |
| 37 | + from .resources.available import AvailableResource, AsyncAvailableResource |
33 | 38 |
|
34 | 39 | __all__ = [ |
35 | 40 | "ENVIRONMENTS", |
|
50 | 55 |
|
51 | 56 |
|
52 | 57 | class Brapi(SyncAPIClient): |
53 | | - quote: quote.QuoteResource |
54 | | - available: available.AvailableResource |
55 | | - v2: v2.V2Resource |
56 | | - with_raw_response: BrapiWithRawResponse |
57 | | - with_streaming_response: BrapiWithStreamedResponse |
58 | | - |
59 | 58 | # client options |
60 | 59 | api_key: str |
61 | 60 |
|
@@ -134,11 +133,31 @@ def __init__( |
134 | 133 | _strict_response_validation=_strict_response_validation, |
135 | 134 | ) |
136 | 135 |
|
137 | | - self.quote = quote.QuoteResource(self) |
138 | | - self.available = available.AvailableResource(self) |
139 | | - self.v2 = v2.V2Resource(self) |
140 | | - self.with_raw_response = BrapiWithRawResponse(self) |
141 | | - self.with_streaming_response = BrapiWithStreamedResponse(self) |
| 136 | + @cached_property |
| 137 | + def quote(self) -> QuoteResource: |
| 138 | + from .resources.quote import QuoteResource |
| 139 | + |
| 140 | + return QuoteResource(self) |
| 141 | + |
| 142 | + @cached_property |
| 143 | + def available(self) -> AvailableResource: |
| 144 | + from .resources.available import AvailableResource |
| 145 | + |
| 146 | + return AvailableResource(self) |
| 147 | + |
| 148 | + @cached_property |
| 149 | + def v2(self) -> V2Resource: |
| 150 | + from .resources.v2 import V2Resource |
| 151 | + |
| 152 | + return V2Resource(self) |
| 153 | + |
| 154 | + @cached_property |
| 155 | + def with_raw_response(self) -> BrapiWithRawResponse: |
| 156 | + return BrapiWithRawResponse(self) |
| 157 | + |
| 158 | + @cached_property |
| 159 | + def with_streaming_response(self) -> BrapiWithStreamedResponse: |
| 160 | + return BrapiWithStreamedResponse(self) |
142 | 161 |
|
143 | 162 | @property |
144 | 163 | @override |
@@ -248,12 +267,6 @@ def _make_status_error( |
248 | 267 |
|
249 | 268 |
|
250 | 269 | class AsyncBrapi(AsyncAPIClient): |
251 | | - quote: quote.AsyncQuoteResource |
252 | | - available: available.AsyncAvailableResource |
253 | | - v2: v2.AsyncV2Resource |
254 | | - with_raw_response: AsyncBrapiWithRawResponse |
255 | | - with_streaming_response: AsyncBrapiWithStreamedResponse |
256 | | - |
257 | 270 | # client options |
258 | 271 | api_key: str |
259 | 272 |
|
@@ -332,11 +345,31 @@ def __init__( |
332 | 345 | _strict_response_validation=_strict_response_validation, |
333 | 346 | ) |
334 | 347 |
|
335 | | - self.quote = quote.AsyncQuoteResource(self) |
336 | | - self.available = available.AsyncAvailableResource(self) |
337 | | - self.v2 = v2.AsyncV2Resource(self) |
338 | | - self.with_raw_response = AsyncBrapiWithRawResponse(self) |
339 | | - self.with_streaming_response = AsyncBrapiWithStreamedResponse(self) |
| 348 | + @cached_property |
| 349 | + def quote(self) -> AsyncQuoteResource: |
| 350 | + from .resources.quote import AsyncQuoteResource |
| 351 | + |
| 352 | + return AsyncQuoteResource(self) |
| 353 | + |
| 354 | + @cached_property |
| 355 | + def available(self) -> AsyncAvailableResource: |
| 356 | + from .resources.available import AsyncAvailableResource |
| 357 | + |
| 358 | + return AsyncAvailableResource(self) |
| 359 | + |
| 360 | + @cached_property |
| 361 | + def v2(self) -> AsyncV2Resource: |
| 362 | + from .resources.v2 import AsyncV2Resource |
| 363 | + |
| 364 | + return AsyncV2Resource(self) |
| 365 | + |
| 366 | + @cached_property |
| 367 | + def with_raw_response(self) -> AsyncBrapiWithRawResponse: |
| 368 | + return AsyncBrapiWithRawResponse(self) |
| 369 | + |
| 370 | + @cached_property |
| 371 | + def with_streaming_response(self) -> AsyncBrapiWithStreamedResponse: |
| 372 | + return AsyncBrapiWithStreamedResponse(self) |
340 | 373 |
|
341 | 374 | @property |
342 | 375 | @override |
@@ -446,31 +479,103 @@ def _make_status_error( |
446 | 479 |
|
447 | 480 |
|
448 | 481 | class BrapiWithRawResponse: |
| 482 | + _client: Brapi |
| 483 | + |
449 | 484 | def __init__(self, client: Brapi) -> None: |
450 | | - self.quote = quote.QuoteResourceWithRawResponse(client.quote) |
451 | | - self.available = available.AvailableResourceWithRawResponse(client.available) |
452 | | - self.v2 = v2.V2ResourceWithRawResponse(client.v2) |
| 485 | + self._client = client |
| 486 | + |
| 487 | + @cached_property |
| 488 | + def quote(self) -> quote.QuoteResourceWithRawResponse: |
| 489 | + from .resources.quote import QuoteResourceWithRawResponse |
| 490 | + |
| 491 | + return QuoteResourceWithRawResponse(self._client.quote) |
| 492 | + |
| 493 | + @cached_property |
| 494 | + def available(self) -> available.AvailableResourceWithRawResponse: |
| 495 | + from .resources.available import AvailableResourceWithRawResponse |
| 496 | + |
| 497 | + return AvailableResourceWithRawResponse(self._client.available) |
| 498 | + |
| 499 | + @cached_property |
| 500 | + def v2(self) -> v2.V2ResourceWithRawResponse: |
| 501 | + from .resources.v2 import V2ResourceWithRawResponse |
| 502 | + |
| 503 | + return V2ResourceWithRawResponse(self._client.v2) |
453 | 504 |
|
454 | 505 |
|
455 | 506 | class AsyncBrapiWithRawResponse: |
| 507 | + _client: AsyncBrapi |
| 508 | + |
456 | 509 | def __init__(self, client: AsyncBrapi) -> None: |
457 | | - self.quote = quote.AsyncQuoteResourceWithRawResponse(client.quote) |
458 | | - self.available = available.AsyncAvailableResourceWithRawResponse(client.available) |
459 | | - self.v2 = v2.AsyncV2ResourceWithRawResponse(client.v2) |
| 510 | + self._client = client |
| 511 | + |
| 512 | + @cached_property |
| 513 | + def quote(self) -> quote.AsyncQuoteResourceWithRawResponse: |
| 514 | + from .resources.quote import AsyncQuoteResourceWithRawResponse |
| 515 | + |
| 516 | + return AsyncQuoteResourceWithRawResponse(self._client.quote) |
| 517 | + |
| 518 | + @cached_property |
| 519 | + def available(self) -> available.AsyncAvailableResourceWithRawResponse: |
| 520 | + from .resources.available import AsyncAvailableResourceWithRawResponse |
| 521 | + |
| 522 | + return AsyncAvailableResourceWithRawResponse(self._client.available) |
| 523 | + |
| 524 | + @cached_property |
| 525 | + def v2(self) -> v2.AsyncV2ResourceWithRawResponse: |
| 526 | + from .resources.v2 import AsyncV2ResourceWithRawResponse |
| 527 | + |
| 528 | + return AsyncV2ResourceWithRawResponse(self._client.v2) |
460 | 529 |
|
461 | 530 |
|
462 | 531 | class BrapiWithStreamedResponse: |
| 532 | + _client: Brapi |
| 533 | + |
463 | 534 | def __init__(self, client: Brapi) -> None: |
464 | | - self.quote = quote.QuoteResourceWithStreamingResponse(client.quote) |
465 | | - self.available = available.AvailableResourceWithStreamingResponse(client.available) |
466 | | - self.v2 = v2.V2ResourceWithStreamingResponse(client.v2) |
| 535 | + self._client = client |
| 536 | + |
| 537 | + @cached_property |
| 538 | + def quote(self) -> quote.QuoteResourceWithStreamingResponse: |
| 539 | + from .resources.quote import QuoteResourceWithStreamingResponse |
| 540 | + |
| 541 | + return QuoteResourceWithStreamingResponse(self._client.quote) |
| 542 | + |
| 543 | + @cached_property |
| 544 | + def available(self) -> available.AvailableResourceWithStreamingResponse: |
| 545 | + from .resources.available import AvailableResourceWithStreamingResponse |
| 546 | + |
| 547 | + return AvailableResourceWithStreamingResponse(self._client.available) |
| 548 | + |
| 549 | + @cached_property |
| 550 | + def v2(self) -> v2.V2ResourceWithStreamingResponse: |
| 551 | + from .resources.v2 import V2ResourceWithStreamingResponse |
| 552 | + |
| 553 | + return V2ResourceWithStreamingResponse(self._client.v2) |
467 | 554 |
|
468 | 555 |
|
469 | 556 | class AsyncBrapiWithStreamedResponse: |
| 557 | + _client: AsyncBrapi |
| 558 | + |
470 | 559 | def __init__(self, client: AsyncBrapi) -> None: |
471 | | - self.quote = quote.AsyncQuoteResourceWithStreamingResponse(client.quote) |
472 | | - self.available = available.AsyncAvailableResourceWithStreamingResponse(client.available) |
473 | | - self.v2 = v2.AsyncV2ResourceWithStreamingResponse(client.v2) |
| 560 | + self._client = client |
| 561 | + |
| 562 | + @cached_property |
| 563 | + def quote(self) -> quote.AsyncQuoteResourceWithStreamingResponse: |
| 564 | + from .resources.quote import AsyncQuoteResourceWithStreamingResponse |
| 565 | + |
| 566 | + return AsyncQuoteResourceWithStreamingResponse(self._client.quote) |
| 567 | + |
| 568 | + @cached_property |
| 569 | + def available(self) -> available.AsyncAvailableResourceWithStreamingResponse: |
| 570 | + from .resources.available import AsyncAvailableResourceWithStreamingResponse |
| 571 | + |
| 572 | + return AsyncAvailableResourceWithStreamingResponse(self._client.available) |
| 573 | + |
| 574 | + @cached_property |
| 575 | + def v2(self) -> v2.AsyncV2ResourceWithStreamingResponse: |
| 576 | + from .resources.v2 import AsyncV2ResourceWithStreamingResponse |
| 577 | + |
| 578 | + return AsyncV2ResourceWithStreamingResponse(self._client.v2) |
474 | 579 |
|
475 | 580 |
|
476 | 581 | Client = Brapi |
|
0 commit comments