|
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 |
|
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 health |
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.users import users |
34 | | -from .resources.projects import projects |
35 | | -from .resources.organizations import organizations |
| 33 | + |
| 34 | +if TYPE_CHECKING: |
| 35 | + from .resources import users, health, projects, organizations |
| 36 | + from .resources.health import HealthResource, AsyncHealthResource |
| 37 | + from .resources.users.users import UsersResource, AsyncUsersResource |
| 38 | + from .resources.projects.projects import ProjectsResource, AsyncProjectsResource |
| 39 | + from .resources.organizations.organizations import OrganizationsResource, AsyncOrganizationsResource |
36 | 40 |
|
37 | 41 | __all__ = [ |
38 | 42 | "ENVIRONMENTS", |
|
54 | 58 |
|
55 | 59 |
|
56 | 60 | class Codex(SyncAPIClient): |
57 | | - health: health.HealthResource |
58 | | - organizations: organizations.OrganizationsResource |
59 | | - users: users.UsersResource |
60 | | - projects: projects.ProjectsResource |
61 | | - with_raw_response: CodexWithRawResponse |
62 | | - with_streaming_response: CodexWithStreamedResponse |
63 | | - |
64 | 61 | # client options |
65 | 62 | auth_token: str | None |
66 | 63 | api_key: str | None |
@@ -138,12 +135,37 @@ def __init__( |
138 | 135 | _strict_response_validation=_strict_response_validation, |
139 | 136 | ) |
140 | 137 |
|
141 | | - self.health = health.HealthResource(self) |
142 | | - self.organizations = organizations.OrganizationsResource(self) |
143 | | - self.users = users.UsersResource(self) |
144 | | - self.projects = projects.ProjectsResource(self) |
145 | | - self.with_raw_response = CodexWithRawResponse(self) |
146 | | - self.with_streaming_response = CodexWithStreamedResponse(self) |
| 138 | + @cached_property |
| 139 | + def health(self) -> HealthResource: |
| 140 | + from .resources.health import HealthResource |
| 141 | + |
| 142 | + return HealthResource(self) |
| 143 | + |
| 144 | + @cached_property |
| 145 | + def organizations(self) -> OrganizationsResource: |
| 146 | + from .resources.organizations import OrganizationsResource |
| 147 | + |
| 148 | + return OrganizationsResource(self) |
| 149 | + |
| 150 | + @cached_property |
| 151 | + def users(self) -> UsersResource: |
| 152 | + from .resources.users import UsersResource |
| 153 | + |
| 154 | + return UsersResource(self) |
| 155 | + |
| 156 | + @cached_property |
| 157 | + def projects(self) -> ProjectsResource: |
| 158 | + from .resources.projects import ProjectsResource |
| 159 | + |
| 160 | + return ProjectsResource(self) |
| 161 | + |
| 162 | + @cached_property |
| 163 | + def with_raw_response(self) -> CodexWithRawResponse: |
| 164 | + return CodexWithRawResponse(self) |
| 165 | + |
| 166 | + @cached_property |
| 167 | + def with_streaming_response(self) -> CodexWithStreamedResponse: |
| 168 | + return CodexWithStreamedResponse(self) |
147 | 169 |
|
148 | 170 | @property |
149 | 171 | @override |
@@ -298,13 +320,6 @@ def _make_status_error( |
298 | 320 |
|
299 | 321 |
|
300 | 322 | class AsyncCodex(AsyncAPIClient): |
301 | | - health: health.AsyncHealthResource |
302 | | - organizations: organizations.AsyncOrganizationsResource |
303 | | - users: users.AsyncUsersResource |
304 | | - projects: projects.AsyncProjectsResource |
305 | | - with_raw_response: AsyncCodexWithRawResponse |
306 | | - with_streaming_response: AsyncCodexWithStreamedResponse |
307 | | - |
308 | 323 | # client options |
309 | 324 | auth_token: str | None |
310 | 325 | api_key: str | None |
@@ -382,12 +397,37 @@ def __init__( |
382 | 397 | _strict_response_validation=_strict_response_validation, |
383 | 398 | ) |
384 | 399 |
|
385 | | - self.health = health.AsyncHealthResource(self) |
386 | | - self.organizations = organizations.AsyncOrganizationsResource(self) |
387 | | - self.users = users.AsyncUsersResource(self) |
388 | | - self.projects = projects.AsyncProjectsResource(self) |
389 | | - self.with_raw_response = AsyncCodexWithRawResponse(self) |
390 | | - self.with_streaming_response = AsyncCodexWithStreamedResponse(self) |
| 400 | + @cached_property |
| 401 | + def health(self) -> AsyncHealthResource: |
| 402 | + from .resources.health import AsyncHealthResource |
| 403 | + |
| 404 | + return AsyncHealthResource(self) |
| 405 | + |
| 406 | + @cached_property |
| 407 | + def organizations(self) -> AsyncOrganizationsResource: |
| 408 | + from .resources.organizations import AsyncOrganizationsResource |
| 409 | + |
| 410 | + return AsyncOrganizationsResource(self) |
| 411 | + |
| 412 | + @cached_property |
| 413 | + def users(self) -> AsyncUsersResource: |
| 414 | + from .resources.users import AsyncUsersResource |
| 415 | + |
| 416 | + return AsyncUsersResource(self) |
| 417 | + |
| 418 | + @cached_property |
| 419 | + def projects(self) -> AsyncProjectsResource: |
| 420 | + from .resources.projects import AsyncProjectsResource |
| 421 | + |
| 422 | + return AsyncProjectsResource(self) |
| 423 | + |
| 424 | + @cached_property |
| 425 | + def with_raw_response(self) -> AsyncCodexWithRawResponse: |
| 426 | + return AsyncCodexWithRawResponse(self) |
| 427 | + |
| 428 | + @cached_property |
| 429 | + def with_streaming_response(self) -> AsyncCodexWithStreamedResponse: |
| 430 | + return AsyncCodexWithStreamedResponse(self) |
391 | 431 |
|
392 | 432 | @property |
393 | 433 | @override |
@@ -542,35 +582,127 @@ def _make_status_error( |
542 | 582 |
|
543 | 583 |
|
544 | 584 | class CodexWithRawResponse: |
| 585 | + _client: Codex |
| 586 | + |
545 | 587 | def __init__(self, client: Codex) -> None: |
546 | | - self.health = health.HealthResourceWithRawResponse(client.health) |
547 | | - self.organizations = organizations.OrganizationsResourceWithRawResponse(client.organizations) |
548 | | - self.users = users.UsersResourceWithRawResponse(client.users) |
549 | | - self.projects = projects.ProjectsResourceWithRawResponse(client.projects) |
| 588 | + self._client = client |
| 589 | + |
| 590 | + @cached_property |
| 591 | + def health(self) -> health.HealthResourceWithRawResponse: |
| 592 | + from .resources.health import HealthResourceWithRawResponse |
| 593 | + |
| 594 | + return HealthResourceWithRawResponse(self._client.health) |
| 595 | + |
| 596 | + @cached_property |
| 597 | + def organizations(self) -> organizations.OrganizationsResourceWithRawResponse: |
| 598 | + from .resources.organizations import OrganizationsResourceWithRawResponse |
| 599 | + |
| 600 | + return OrganizationsResourceWithRawResponse(self._client.organizations) |
| 601 | + |
| 602 | + @cached_property |
| 603 | + def users(self) -> users.UsersResourceWithRawResponse: |
| 604 | + from .resources.users import UsersResourceWithRawResponse |
| 605 | + |
| 606 | + return UsersResourceWithRawResponse(self._client.users) |
| 607 | + |
| 608 | + @cached_property |
| 609 | + def projects(self) -> projects.ProjectsResourceWithRawResponse: |
| 610 | + from .resources.projects import ProjectsResourceWithRawResponse |
| 611 | + |
| 612 | + return ProjectsResourceWithRawResponse(self._client.projects) |
550 | 613 |
|
551 | 614 |
|
552 | 615 | class AsyncCodexWithRawResponse: |
| 616 | + _client: AsyncCodex |
| 617 | + |
553 | 618 | def __init__(self, client: AsyncCodex) -> None: |
554 | | - self.health = health.AsyncHealthResourceWithRawResponse(client.health) |
555 | | - self.organizations = organizations.AsyncOrganizationsResourceWithRawResponse(client.organizations) |
556 | | - self.users = users.AsyncUsersResourceWithRawResponse(client.users) |
557 | | - self.projects = projects.AsyncProjectsResourceWithRawResponse(client.projects) |
| 619 | + self._client = client |
| 620 | + |
| 621 | + @cached_property |
| 622 | + def health(self) -> health.AsyncHealthResourceWithRawResponse: |
| 623 | + from .resources.health import AsyncHealthResourceWithRawResponse |
| 624 | + |
| 625 | + return AsyncHealthResourceWithRawResponse(self._client.health) |
| 626 | + |
| 627 | + @cached_property |
| 628 | + def organizations(self) -> organizations.AsyncOrganizationsResourceWithRawResponse: |
| 629 | + from .resources.organizations import AsyncOrganizationsResourceWithRawResponse |
| 630 | + |
| 631 | + return AsyncOrganizationsResourceWithRawResponse(self._client.organizations) |
| 632 | + |
| 633 | + @cached_property |
| 634 | + def users(self) -> users.AsyncUsersResourceWithRawResponse: |
| 635 | + from .resources.users import AsyncUsersResourceWithRawResponse |
| 636 | + |
| 637 | + return AsyncUsersResourceWithRawResponse(self._client.users) |
| 638 | + |
| 639 | + @cached_property |
| 640 | + def projects(self) -> projects.AsyncProjectsResourceWithRawResponse: |
| 641 | + from .resources.projects import AsyncProjectsResourceWithRawResponse |
| 642 | + |
| 643 | + return AsyncProjectsResourceWithRawResponse(self._client.projects) |
558 | 644 |
|
559 | 645 |
|
560 | 646 | class CodexWithStreamedResponse: |
| 647 | + _client: Codex |
| 648 | + |
561 | 649 | def __init__(self, client: Codex) -> None: |
562 | | - self.health = health.HealthResourceWithStreamingResponse(client.health) |
563 | | - self.organizations = organizations.OrganizationsResourceWithStreamingResponse(client.organizations) |
564 | | - self.users = users.UsersResourceWithStreamingResponse(client.users) |
565 | | - self.projects = projects.ProjectsResourceWithStreamingResponse(client.projects) |
| 650 | + self._client = client |
| 651 | + |
| 652 | + @cached_property |
| 653 | + def health(self) -> health.HealthResourceWithStreamingResponse: |
| 654 | + from .resources.health import HealthResourceWithStreamingResponse |
| 655 | + |
| 656 | + return HealthResourceWithStreamingResponse(self._client.health) |
| 657 | + |
| 658 | + @cached_property |
| 659 | + def organizations(self) -> organizations.OrganizationsResourceWithStreamingResponse: |
| 660 | + from .resources.organizations import OrganizationsResourceWithStreamingResponse |
| 661 | + |
| 662 | + return OrganizationsResourceWithStreamingResponse(self._client.organizations) |
| 663 | + |
| 664 | + @cached_property |
| 665 | + def users(self) -> users.UsersResourceWithStreamingResponse: |
| 666 | + from .resources.users import UsersResourceWithStreamingResponse |
| 667 | + |
| 668 | + return UsersResourceWithStreamingResponse(self._client.users) |
| 669 | + |
| 670 | + @cached_property |
| 671 | + def projects(self) -> projects.ProjectsResourceWithStreamingResponse: |
| 672 | + from .resources.projects import ProjectsResourceWithStreamingResponse |
| 673 | + |
| 674 | + return ProjectsResourceWithStreamingResponse(self._client.projects) |
566 | 675 |
|
567 | 676 |
|
568 | 677 | class AsyncCodexWithStreamedResponse: |
| 678 | + _client: AsyncCodex |
| 679 | + |
569 | 680 | def __init__(self, client: AsyncCodex) -> None: |
570 | | - self.health = health.AsyncHealthResourceWithStreamingResponse(client.health) |
571 | | - self.organizations = organizations.AsyncOrganizationsResourceWithStreamingResponse(client.organizations) |
572 | | - self.users = users.AsyncUsersResourceWithStreamingResponse(client.users) |
573 | | - self.projects = projects.AsyncProjectsResourceWithStreamingResponse(client.projects) |
| 681 | + self._client = client |
| 682 | + |
| 683 | + @cached_property |
| 684 | + def health(self) -> health.AsyncHealthResourceWithStreamingResponse: |
| 685 | + from .resources.health import AsyncHealthResourceWithStreamingResponse |
| 686 | + |
| 687 | + return AsyncHealthResourceWithStreamingResponse(self._client.health) |
| 688 | + |
| 689 | + @cached_property |
| 690 | + def organizations(self) -> organizations.AsyncOrganizationsResourceWithStreamingResponse: |
| 691 | + from .resources.organizations import AsyncOrganizationsResourceWithStreamingResponse |
| 692 | + |
| 693 | + return AsyncOrganizationsResourceWithStreamingResponse(self._client.organizations) |
| 694 | + |
| 695 | + @cached_property |
| 696 | + def users(self) -> users.AsyncUsersResourceWithStreamingResponse: |
| 697 | + from .resources.users import AsyncUsersResourceWithStreamingResponse |
| 698 | + |
| 699 | + return AsyncUsersResourceWithStreamingResponse(self._client.users) |
| 700 | + |
| 701 | + @cached_property |
| 702 | + def projects(self) -> projects.AsyncProjectsResourceWithStreamingResponse: |
| 703 | + from .resources.projects import AsyncProjectsResourceWithStreamingResponse |
| 704 | + |
| 705 | + return AsyncProjectsResourceWithStreamingResponse(self._client.projects) |
574 | 706 |
|
575 | 707 |
|
576 | 708 | Client = Codex |
|
0 commit comments