|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import os |
6 | | -from typing import Any, Mapping |
| 6 | +from typing import TYPE_CHECKING, Any, Mapping |
7 | 7 | from typing_extensions import Self, override |
8 | 8 |
|
9 | 9 | import httpx |
|
21 | 21 | not_given, |
22 | 22 | ) |
23 | 23 | from ._utils import is_given, get_async_library |
| 24 | +from ._compat import cached_property |
24 | 25 | from ._version import __version__ |
25 | | -from .resources import address_verification, intl_address_verification |
26 | 26 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
27 | 27 | from ._exceptions import APIStatusError |
28 | 28 | from ._base_client import ( |
29 | 29 | DEFAULT_MAX_RETRIES, |
30 | 30 | SyncAPIClient, |
31 | 31 | AsyncAPIClient, |
32 | 32 | ) |
33 | | -from .resources.print_mail import print_mail |
| 33 | + |
| 34 | +if TYPE_CHECKING: |
| 35 | + from .resources import print_mail, address_verification, intl_address_verification |
| 36 | + from .resources.address_verification import AddressVerificationResource, AsyncAddressVerificationResource |
| 37 | + from .resources.print_mail.print_mail import PrintMailResource, AsyncPrintMailResource |
| 38 | + from .resources.intl_address_verification import ( |
| 39 | + IntlAddressVerificationResource, |
| 40 | + AsyncIntlAddressVerificationResource, |
| 41 | + ) |
34 | 42 |
|
35 | 43 | __all__ = [ |
36 | 44 | "Timeout", |
|
45 | 53 |
|
46 | 54 |
|
47 | 55 | class PostGrid(SyncAPIClient): |
48 | | - address_verification: address_verification.AddressVerificationResource |
49 | | - intl_address_verification: intl_address_verification.IntlAddressVerificationResource |
50 | | - print_mail: print_mail.PrintMailResource |
51 | | - with_raw_response: PostGridWithRawResponse |
52 | | - with_streaming_response: PostGridWithStreamedResponse |
53 | | - |
54 | 56 | # client options |
55 | 57 | address_verification_api_key: str | None |
56 | 58 | print_mail_api_key: str | None |
@@ -109,11 +111,31 @@ def __init__( |
109 | 111 | _strict_response_validation=_strict_response_validation, |
110 | 112 | ) |
111 | 113 |
|
112 | | - self.address_verification = address_verification.AddressVerificationResource(self) |
113 | | - self.intl_address_verification = intl_address_verification.IntlAddressVerificationResource(self) |
114 | | - self.print_mail = print_mail.PrintMailResource(self) |
115 | | - self.with_raw_response = PostGridWithRawResponse(self) |
116 | | - self.with_streaming_response = PostGridWithStreamedResponse(self) |
| 114 | + @cached_property |
| 115 | + def address_verification(self) -> AddressVerificationResource: |
| 116 | + from .resources.address_verification import AddressVerificationResource |
| 117 | + |
| 118 | + return AddressVerificationResource(self) |
| 119 | + |
| 120 | + @cached_property |
| 121 | + def intl_address_verification(self) -> IntlAddressVerificationResource: |
| 122 | + from .resources.intl_address_verification import IntlAddressVerificationResource |
| 123 | + |
| 124 | + return IntlAddressVerificationResource(self) |
| 125 | + |
| 126 | + @cached_property |
| 127 | + def print_mail(self) -> PrintMailResource: |
| 128 | + from .resources.print_mail import PrintMailResource |
| 129 | + |
| 130 | + return PrintMailResource(self) |
| 131 | + |
| 132 | + @cached_property |
| 133 | + def with_raw_response(self) -> PostGridWithRawResponse: |
| 134 | + return PostGridWithRawResponse(self) |
| 135 | + |
| 136 | + @cached_property |
| 137 | + def with_streaming_response(self) -> PostGridWithStreamedResponse: |
| 138 | + return PostGridWithStreamedResponse(self) |
117 | 139 |
|
118 | 140 | @override |
119 | 141 | def _prepare_request( |
@@ -266,12 +288,6 @@ def _make_status_error( |
266 | 288 |
|
267 | 289 |
|
268 | 290 | class AsyncPostGrid(AsyncAPIClient): |
269 | | - address_verification: address_verification.AsyncAddressVerificationResource |
270 | | - intl_address_verification: intl_address_verification.AsyncIntlAddressVerificationResource |
271 | | - print_mail: print_mail.AsyncPrintMailResource |
272 | | - with_raw_response: AsyncPostGridWithRawResponse |
273 | | - with_streaming_response: AsyncPostGridWithStreamedResponse |
274 | | - |
275 | 291 | # client options |
276 | 292 | address_verification_api_key: str | None |
277 | 293 | print_mail_api_key: str | None |
@@ -330,11 +346,31 @@ def __init__( |
330 | 346 | _strict_response_validation=_strict_response_validation, |
331 | 347 | ) |
332 | 348 |
|
333 | | - self.address_verification = address_verification.AsyncAddressVerificationResource(self) |
334 | | - self.intl_address_verification = intl_address_verification.AsyncIntlAddressVerificationResource(self) |
335 | | - self.print_mail = print_mail.AsyncPrintMailResource(self) |
336 | | - self.with_raw_response = AsyncPostGridWithRawResponse(self) |
337 | | - self.with_streaming_response = AsyncPostGridWithStreamedResponse(self) |
| 349 | + @cached_property |
| 350 | + def address_verification(self) -> AsyncAddressVerificationResource: |
| 351 | + from .resources.address_verification import AsyncAddressVerificationResource |
| 352 | + |
| 353 | + return AsyncAddressVerificationResource(self) |
| 354 | + |
| 355 | + @cached_property |
| 356 | + def intl_address_verification(self) -> AsyncIntlAddressVerificationResource: |
| 357 | + from .resources.intl_address_verification import AsyncIntlAddressVerificationResource |
| 358 | + |
| 359 | + return AsyncIntlAddressVerificationResource(self) |
| 360 | + |
| 361 | + @cached_property |
| 362 | + def print_mail(self) -> AsyncPrintMailResource: |
| 363 | + from .resources.print_mail import AsyncPrintMailResource |
| 364 | + |
| 365 | + return AsyncPrintMailResource(self) |
| 366 | + |
| 367 | + @cached_property |
| 368 | + def with_raw_response(self) -> AsyncPostGridWithRawResponse: |
| 369 | + return AsyncPostGridWithRawResponse(self) |
| 370 | + |
| 371 | + @cached_property |
| 372 | + def with_streaming_response(self) -> AsyncPostGridWithStreamedResponse: |
| 373 | + return AsyncPostGridWithStreamedResponse(self) |
338 | 374 |
|
339 | 375 | @override |
340 | 376 | async def _prepare_request( |
@@ -487,49 +523,109 @@ def _make_status_error( |
487 | 523 |
|
488 | 524 |
|
489 | 525 | class PostGridWithRawResponse: |
| 526 | + _client: PostGrid |
| 527 | + |
490 | 528 | def __init__(self, client: PostGrid) -> None: |
491 | | - self.address_verification = address_verification.AddressVerificationResourceWithRawResponse( |
492 | | - client.address_verification |
493 | | - ) |
494 | | - self.intl_address_verification = intl_address_verification.IntlAddressVerificationResourceWithRawResponse( |
495 | | - client.intl_address_verification |
496 | | - ) |
497 | | - self.print_mail = print_mail.PrintMailResourceWithRawResponse(client.print_mail) |
| 529 | + self._client = client |
| 530 | + |
| 531 | + @cached_property |
| 532 | + def address_verification(self) -> address_verification.AddressVerificationResourceWithRawResponse: |
| 533 | + from .resources.address_verification import AddressVerificationResourceWithRawResponse |
| 534 | + |
| 535 | + return AddressVerificationResourceWithRawResponse(self._client.address_verification) |
| 536 | + |
| 537 | + @cached_property |
| 538 | + def intl_address_verification(self) -> intl_address_verification.IntlAddressVerificationResourceWithRawResponse: |
| 539 | + from .resources.intl_address_verification import IntlAddressVerificationResourceWithRawResponse |
| 540 | + |
| 541 | + return IntlAddressVerificationResourceWithRawResponse(self._client.intl_address_verification) |
| 542 | + |
| 543 | + @cached_property |
| 544 | + def print_mail(self) -> print_mail.PrintMailResourceWithRawResponse: |
| 545 | + from .resources.print_mail import PrintMailResourceWithRawResponse |
| 546 | + |
| 547 | + return PrintMailResourceWithRawResponse(self._client.print_mail) |
498 | 548 |
|
499 | 549 |
|
500 | 550 | class AsyncPostGridWithRawResponse: |
| 551 | + _client: AsyncPostGrid |
| 552 | + |
501 | 553 | def __init__(self, client: AsyncPostGrid) -> None: |
502 | | - self.address_verification = address_verification.AsyncAddressVerificationResourceWithRawResponse( |
503 | | - client.address_verification |
504 | | - ) |
505 | | - self.intl_address_verification = intl_address_verification.AsyncIntlAddressVerificationResourceWithRawResponse( |
506 | | - client.intl_address_verification |
507 | | - ) |
508 | | - self.print_mail = print_mail.AsyncPrintMailResourceWithRawResponse(client.print_mail) |
| 554 | + self._client = client |
| 555 | + |
| 556 | + @cached_property |
| 557 | + def address_verification(self) -> address_verification.AsyncAddressVerificationResourceWithRawResponse: |
| 558 | + from .resources.address_verification import AsyncAddressVerificationResourceWithRawResponse |
| 559 | + |
| 560 | + return AsyncAddressVerificationResourceWithRawResponse(self._client.address_verification) |
| 561 | + |
| 562 | + @cached_property |
| 563 | + def intl_address_verification( |
| 564 | + self, |
| 565 | + ) -> intl_address_verification.AsyncIntlAddressVerificationResourceWithRawResponse: |
| 566 | + from .resources.intl_address_verification import AsyncIntlAddressVerificationResourceWithRawResponse |
| 567 | + |
| 568 | + return AsyncIntlAddressVerificationResourceWithRawResponse(self._client.intl_address_verification) |
| 569 | + |
| 570 | + @cached_property |
| 571 | + def print_mail(self) -> print_mail.AsyncPrintMailResourceWithRawResponse: |
| 572 | + from .resources.print_mail import AsyncPrintMailResourceWithRawResponse |
| 573 | + |
| 574 | + return AsyncPrintMailResourceWithRawResponse(self._client.print_mail) |
509 | 575 |
|
510 | 576 |
|
511 | 577 | class PostGridWithStreamedResponse: |
| 578 | + _client: PostGrid |
| 579 | + |
512 | 580 | def __init__(self, client: PostGrid) -> None: |
513 | | - self.address_verification = address_verification.AddressVerificationResourceWithStreamingResponse( |
514 | | - client.address_verification |
515 | | - ) |
516 | | - self.intl_address_verification = intl_address_verification.IntlAddressVerificationResourceWithStreamingResponse( |
517 | | - client.intl_address_verification |
518 | | - ) |
519 | | - self.print_mail = print_mail.PrintMailResourceWithStreamingResponse(client.print_mail) |
| 581 | + self._client = client |
| 582 | + |
| 583 | + @cached_property |
| 584 | + def address_verification(self) -> address_verification.AddressVerificationResourceWithStreamingResponse: |
| 585 | + from .resources.address_verification import AddressVerificationResourceWithStreamingResponse |
| 586 | + |
| 587 | + return AddressVerificationResourceWithStreamingResponse(self._client.address_verification) |
| 588 | + |
| 589 | + @cached_property |
| 590 | + def intl_address_verification( |
| 591 | + self, |
| 592 | + ) -> intl_address_verification.IntlAddressVerificationResourceWithStreamingResponse: |
| 593 | + from .resources.intl_address_verification import IntlAddressVerificationResourceWithStreamingResponse |
| 594 | + |
| 595 | + return IntlAddressVerificationResourceWithStreamingResponse(self._client.intl_address_verification) |
| 596 | + |
| 597 | + @cached_property |
| 598 | + def print_mail(self) -> print_mail.PrintMailResourceWithStreamingResponse: |
| 599 | + from .resources.print_mail import PrintMailResourceWithStreamingResponse |
| 600 | + |
| 601 | + return PrintMailResourceWithStreamingResponse(self._client.print_mail) |
520 | 602 |
|
521 | 603 |
|
522 | 604 | class AsyncPostGridWithStreamedResponse: |
| 605 | + _client: AsyncPostGrid |
| 606 | + |
523 | 607 | def __init__(self, client: AsyncPostGrid) -> None: |
524 | | - self.address_verification = address_verification.AsyncAddressVerificationResourceWithStreamingResponse( |
525 | | - client.address_verification |
526 | | - ) |
527 | | - self.intl_address_verification = ( |
528 | | - intl_address_verification.AsyncIntlAddressVerificationResourceWithStreamingResponse( |
529 | | - client.intl_address_verification |
530 | | - ) |
531 | | - ) |
532 | | - self.print_mail = print_mail.AsyncPrintMailResourceWithStreamingResponse(client.print_mail) |
| 608 | + self._client = client |
| 609 | + |
| 610 | + @cached_property |
| 611 | + def address_verification(self) -> address_verification.AsyncAddressVerificationResourceWithStreamingResponse: |
| 612 | + from .resources.address_verification import AsyncAddressVerificationResourceWithStreamingResponse |
| 613 | + |
| 614 | + return AsyncAddressVerificationResourceWithStreamingResponse(self._client.address_verification) |
| 615 | + |
| 616 | + @cached_property |
| 617 | + def intl_address_verification( |
| 618 | + self, |
| 619 | + ) -> intl_address_verification.AsyncIntlAddressVerificationResourceWithStreamingResponse: |
| 620 | + from .resources.intl_address_verification import AsyncIntlAddressVerificationResourceWithStreamingResponse |
| 621 | + |
| 622 | + return AsyncIntlAddressVerificationResourceWithStreamingResponse(self._client.intl_address_verification) |
| 623 | + |
| 624 | + @cached_property |
| 625 | + def print_mail(self) -> print_mail.AsyncPrintMailResourceWithStreamingResponse: |
| 626 | + from .resources.print_mail import AsyncPrintMailResourceWithStreamingResponse |
| 627 | + |
| 628 | + return AsyncPrintMailResourceWithStreamingResponse(self._client.print_mail) |
533 | 629 |
|
534 | 630 |
|
535 | 631 | Client = PostGrid |
|
0 commit comments