|
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 pages, emails, project, documents |
25 | 25 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
26 | 26 | from ._exceptions import UnlayerError, APIStatusError |
27 | 27 | from ._base_client import ( |
|
30 | 30 | AsyncAPIClient, |
31 | 31 | ) |
32 | 32 |
|
| 33 | +if TYPE_CHECKING: |
| 34 | + from .resources import pages, emails, project, documents |
| 35 | + from .resources.pages import PagesResource, AsyncPagesResource |
| 36 | + from .resources.emails import EmailsResource, AsyncEmailsResource |
| 37 | + from .resources.project import ProjectResource, AsyncProjectResource |
| 38 | + from .resources.documents import DocumentsResource, AsyncDocumentsResource |
| 39 | + |
33 | 40 | __all__ = [ |
34 | 41 | "ENVIRONMENTS", |
35 | 42 | "Timeout", |
|
50 | 57 |
|
51 | 58 |
|
52 | 59 | class Unlayer(SyncAPIClient): |
53 | | - project: project.ProjectResource |
54 | | - emails: emails.EmailsResource |
55 | | - pages: pages.PagesResource |
56 | | - documents: documents.DocumentsResource |
57 | | - with_raw_response: UnlayerWithRawResponse |
58 | | - with_streaming_response: UnlayerWithStreamedResponse |
59 | | - |
60 | 60 | # client options |
61 | 61 | api_key: str |
62 | 62 |
|
@@ -135,12 +135,37 @@ def __init__( |
135 | 135 | _strict_response_validation=_strict_response_validation, |
136 | 136 | ) |
137 | 137 |
|
138 | | - self.project = project.ProjectResource(self) |
139 | | - self.emails = emails.EmailsResource(self) |
140 | | - self.pages = pages.PagesResource(self) |
141 | | - self.documents = documents.DocumentsResource(self) |
142 | | - self.with_raw_response = UnlayerWithRawResponse(self) |
143 | | - self.with_streaming_response = UnlayerWithStreamedResponse(self) |
| 138 | + @cached_property |
| 139 | + def project(self) -> ProjectResource: |
| 140 | + from .resources.project import ProjectResource |
| 141 | + |
| 142 | + return ProjectResource(self) |
| 143 | + |
| 144 | + @cached_property |
| 145 | + def emails(self) -> EmailsResource: |
| 146 | + from .resources.emails import EmailsResource |
| 147 | + |
| 148 | + return EmailsResource(self) |
| 149 | + |
| 150 | + @cached_property |
| 151 | + def pages(self) -> PagesResource: |
| 152 | + from .resources.pages import PagesResource |
| 153 | + |
| 154 | + return PagesResource(self) |
| 155 | + |
| 156 | + @cached_property |
| 157 | + def documents(self) -> DocumentsResource: |
| 158 | + from .resources.documents import DocumentsResource |
| 159 | + |
| 160 | + return DocumentsResource(self) |
| 161 | + |
| 162 | + @cached_property |
| 163 | + def with_raw_response(self) -> UnlayerWithRawResponse: |
| 164 | + return UnlayerWithRawResponse(self) |
| 165 | + |
| 166 | + @cached_property |
| 167 | + def with_streaming_response(self) -> UnlayerWithStreamedResponse: |
| 168 | + return UnlayerWithStreamedResponse(self) |
144 | 169 |
|
145 | 170 | @property |
146 | 171 | @override |
@@ -250,13 +275,6 @@ def _make_status_error( |
250 | 275 |
|
251 | 276 |
|
252 | 277 | class AsyncUnlayer(AsyncAPIClient): |
253 | | - project: project.AsyncProjectResource |
254 | | - emails: emails.AsyncEmailsResource |
255 | | - pages: pages.AsyncPagesResource |
256 | | - documents: documents.AsyncDocumentsResource |
257 | | - with_raw_response: AsyncUnlayerWithRawResponse |
258 | | - with_streaming_response: AsyncUnlayerWithStreamedResponse |
259 | | - |
260 | 278 | # client options |
261 | 279 | api_key: str |
262 | 280 |
|
@@ -335,12 +353,37 @@ def __init__( |
335 | 353 | _strict_response_validation=_strict_response_validation, |
336 | 354 | ) |
337 | 355 |
|
338 | | - self.project = project.AsyncProjectResource(self) |
339 | | - self.emails = emails.AsyncEmailsResource(self) |
340 | | - self.pages = pages.AsyncPagesResource(self) |
341 | | - self.documents = documents.AsyncDocumentsResource(self) |
342 | | - self.with_raw_response = AsyncUnlayerWithRawResponse(self) |
343 | | - self.with_streaming_response = AsyncUnlayerWithStreamedResponse(self) |
| 356 | + @cached_property |
| 357 | + def project(self) -> AsyncProjectResource: |
| 358 | + from .resources.project import AsyncProjectResource |
| 359 | + |
| 360 | + return AsyncProjectResource(self) |
| 361 | + |
| 362 | + @cached_property |
| 363 | + def emails(self) -> AsyncEmailsResource: |
| 364 | + from .resources.emails import AsyncEmailsResource |
| 365 | + |
| 366 | + return AsyncEmailsResource(self) |
| 367 | + |
| 368 | + @cached_property |
| 369 | + def pages(self) -> AsyncPagesResource: |
| 370 | + from .resources.pages import AsyncPagesResource |
| 371 | + |
| 372 | + return AsyncPagesResource(self) |
| 373 | + |
| 374 | + @cached_property |
| 375 | + def documents(self) -> AsyncDocumentsResource: |
| 376 | + from .resources.documents import AsyncDocumentsResource |
| 377 | + |
| 378 | + return AsyncDocumentsResource(self) |
| 379 | + |
| 380 | + @cached_property |
| 381 | + def with_raw_response(self) -> AsyncUnlayerWithRawResponse: |
| 382 | + return AsyncUnlayerWithRawResponse(self) |
| 383 | + |
| 384 | + @cached_property |
| 385 | + def with_streaming_response(self) -> AsyncUnlayerWithStreamedResponse: |
| 386 | + return AsyncUnlayerWithStreamedResponse(self) |
344 | 387 |
|
345 | 388 | @property |
346 | 389 | @override |
@@ -450,35 +493,127 @@ def _make_status_error( |
450 | 493 |
|
451 | 494 |
|
452 | 495 | class UnlayerWithRawResponse: |
| 496 | + _client: Unlayer |
| 497 | + |
453 | 498 | def __init__(self, client: Unlayer) -> None: |
454 | | - self.project = project.ProjectResourceWithRawResponse(client.project) |
455 | | - self.emails = emails.EmailsResourceWithRawResponse(client.emails) |
456 | | - self.pages = pages.PagesResourceWithRawResponse(client.pages) |
457 | | - self.documents = documents.DocumentsResourceWithRawResponse(client.documents) |
| 499 | + self._client = client |
| 500 | + |
| 501 | + @cached_property |
| 502 | + def project(self) -> project.ProjectResourceWithRawResponse: |
| 503 | + from .resources.project import ProjectResourceWithRawResponse |
| 504 | + |
| 505 | + return ProjectResourceWithRawResponse(self._client.project) |
| 506 | + |
| 507 | + @cached_property |
| 508 | + def emails(self) -> emails.EmailsResourceWithRawResponse: |
| 509 | + from .resources.emails import EmailsResourceWithRawResponse |
| 510 | + |
| 511 | + return EmailsResourceWithRawResponse(self._client.emails) |
| 512 | + |
| 513 | + @cached_property |
| 514 | + def pages(self) -> pages.PagesResourceWithRawResponse: |
| 515 | + from .resources.pages import PagesResourceWithRawResponse |
| 516 | + |
| 517 | + return PagesResourceWithRawResponse(self._client.pages) |
| 518 | + |
| 519 | + @cached_property |
| 520 | + def documents(self) -> documents.DocumentsResourceWithRawResponse: |
| 521 | + from .resources.documents import DocumentsResourceWithRawResponse |
| 522 | + |
| 523 | + return DocumentsResourceWithRawResponse(self._client.documents) |
458 | 524 |
|
459 | 525 |
|
460 | 526 | class AsyncUnlayerWithRawResponse: |
| 527 | + _client: AsyncUnlayer |
| 528 | + |
461 | 529 | def __init__(self, client: AsyncUnlayer) -> None: |
462 | | - self.project = project.AsyncProjectResourceWithRawResponse(client.project) |
463 | | - self.emails = emails.AsyncEmailsResourceWithRawResponse(client.emails) |
464 | | - self.pages = pages.AsyncPagesResourceWithRawResponse(client.pages) |
465 | | - self.documents = documents.AsyncDocumentsResourceWithRawResponse(client.documents) |
| 530 | + self._client = client |
| 531 | + |
| 532 | + @cached_property |
| 533 | + def project(self) -> project.AsyncProjectResourceWithRawResponse: |
| 534 | + from .resources.project import AsyncProjectResourceWithRawResponse |
| 535 | + |
| 536 | + return AsyncProjectResourceWithRawResponse(self._client.project) |
| 537 | + |
| 538 | + @cached_property |
| 539 | + def emails(self) -> emails.AsyncEmailsResourceWithRawResponse: |
| 540 | + from .resources.emails import AsyncEmailsResourceWithRawResponse |
| 541 | + |
| 542 | + return AsyncEmailsResourceWithRawResponse(self._client.emails) |
| 543 | + |
| 544 | + @cached_property |
| 545 | + def pages(self) -> pages.AsyncPagesResourceWithRawResponse: |
| 546 | + from .resources.pages import AsyncPagesResourceWithRawResponse |
| 547 | + |
| 548 | + return AsyncPagesResourceWithRawResponse(self._client.pages) |
| 549 | + |
| 550 | + @cached_property |
| 551 | + def documents(self) -> documents.AsyncDocumentsResourceWithRawResponse: |
| 552 | + from .resources.documents import AsyncDocumentsResourceWithRawResponse |
| 553 | + |
| 554 | + return AsyncDocumentsResourceWithRawResponse(self._client.documents) |
466 | 555 |
|
467 | 556 |
|
468 | 557 | class UnlayerWithStreamedResponse: |
| 558 | + _client: Unlayer |
| 559 | + |
469 | 560 | def __init__(self, client: Unlayer) -> None: |
470 | | - self.project = project.ProjectResourceWithStreamingResponse(client.project) |
471 | | - self.emails = emails.EmailsResourceWithStreamingResponse(client.emails) |
472 | | - self.pages = pages.PagesResourceWithStreamingResponse(client.pages) |
473 | | - self.documents = documents.DocumentsResourceWithStreamingResponse(client.documents) |
| 561 | + self._client = client |
| 562 | + |
| 563 | + @cached_property |
| 564 | + def project(self) -> project.ProjectResourceWithStreamingResponse: |
| 565 | + from .resources.project import ProjectResourceWithStreamingResponse |
| 566 | + |
| 567 | + return ProjectResourceWithStreamingResponse(self._client.project) |
| 568 | + |
| 569 | + @cached_property |
| 570 | + def emails(self) -> emails.EmailsResourceWithStreamingResponse: |
| 571 | + from .resources.emails import EmailsResourceWithStreamingResponse |
| 572 | + |
| 573 | + return EmailsResourceWithStreamingResponse(self._client.emails) |
| 574 | + |
| 575 | + @cached_property |
| 576 | + def pages(self) -> pages.PagesResourceWithStreamingResponse: |
| 577 | + from .resources.pages import PagesResourceWithStreamingResponse |
| 578 | + |
| 579 | + return PagesResourceWithStreamingResponse(self._client.pages) |
| 580 | + |
| 581 | + @cached_property |
| 582 | + def documents(self) -> documents.DocumentsResourceWithStreamingResponse: |
| 583 | + from .resources.documents import DocumentsResourceWithStreamingResponse |
| 584 | + |
| 585 | + return DocumentsResourceWithStreamingResponse(self._client.documents) |
474 | 586 |
|
475 | 587 |
|
476 | 588 | class AsyncUnlayerWithStreamedResponse: |
| 589 | + _client: AsyncUnlayer |
| 590 | + |
477 | 591 | def __init__(self, client: AsyncUnlayer) -> None: |
478 | | - self.project = project.AsyncProjectResourceWithStreamingResponse(client.project) |
479 | | - self.emails = emails.AsyncEmailsResourceWithStreamingResponse(client.emails) |
480 | | - self.pages = pages.AsyncPagesResourceWithStreamingResponse(client.pages) |
481 | | - self.documents = documents.AsyncDocumentsResourceWithStreamingResponse(client.documents) |
| 592 | + self._client = client |
| 593 | + |
| 594 | + @cached_property |
| 595 | + def project(self) -> project.AsyncProjectResourceWithStreamingResponse: |
| 596 | + from .resources.project import AsyncProjectResourceWithStreamingResponse |
| 597 | + |
| 598 | + return AsyncProjectResourceWithStreamingResponse(self._client.project) |
| 599 | + |
| 600 | + @cached_property |
| 601 | + def emails(self) -> emails.AsyncEmailsResourceWithStreamingResponse: |
| 602 | + from .resources.emails import AsyncEmailsResourceWithStreamingResponse |
| 603 | + |
| 604 | + return AsyncEmailsResourceWithStreamingResponse(self._client.emails) |
| 605 | + |
| 606 | + @cached_property |
| 607 | + def pages(self) -> pages.AsyncPagesResourceWithStreamingResponse: |
| 608 | + from .resources.pages import AsyncPagesResourceWithStreamingResponse |
| 609 | + |
| 610 | + return AsyncPagesResourceWithStreamingResponse(self._client.pages) |
| 611 | + |
| 612 | + @cached_property |
| 613 | + def documents(self) -> documents.AsyncDocumentsResourceWithStreamingResponse: |
| 614 | + from .resources.documents import AsyncDocumentsResourceWithStreamingResponse |
| 615 | + |
| 616 | + return AsyncDocumentsResourceWithStreamingResponse(self._client.documents) |
482 | 617 |
|
483 | 618 |
|
484 | 619 | Client = Unlayer |
|
0 commit comments