|
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 |
|
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 auth, vaults, evaluate, memories, connections |
25 | 25 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
26 | 26 | from ._exceptions import APIStatusError, HyperspellError |
27 | 27 | from ._base_client import ( |
28 | 28 | DEFAULT_MAX_RETRIES, |
29 | 29 | SyncAPIClient, |
30 | 30 | AsyncAPIClient, |
31 | 31 | ) |
32 | | -from .resources.integrations import integrations |
| 32 | + |
| 33 | +if TYPE_CHECKING: |
| 34 | + from .resources import auth, vaults, evaluate, memories, connections, integrations |
| 35 | + from .resources.auth import AuthResource, AsyncAuthResource |
| 36 | + from .resources.vaults import VaultsResource, AsyncVaultsResource |
| 37 | + from .resources.evaluate import EvaluateResource, AsyncEvaluateResource |
| 38 | + from .resources.memories import MemoriesResource, AsyncMemoriesResource |
| 39 | + from .resources.connections import ConnectionsResource, AsyncConnectionsResource |
| 40 | + from .resources.integrations.integrations import IntegrationsResource, AsyncIntegrationsResource |
33 | 41 |
|
34 | 42 | __all__ = [ |
35 | 43 | "Timeout", |
|
44 | 52 |
|
45 | 53 |
|
46 | 54 | class Hyperspell(SyncAPIClient): |
47 | | - connections: connections.ConnectionsResource |
48 | | - integrations: integrations.IntegrationsResource |
49 | | - memories: memories.MemoriesResource |
50 | | - evaluate: evaluate.EvaluateResource |
51 | | - vaults: vaults.VaultsResource |
52 | | - auth: auth.AuthResource |
53 | | - with_raw_response: HyperspellWithRawResponse |
54 | | - with_streaming_response: HyperspellWithStreamedResponse |
55 | | - |
56 | 55 | # client options |
57 | 56 | api_key: str |
58 | 57 | user_id: str | None |
@@ -111,14 +110,49 @@ def __init__( |
111 | 110 | _strict_response_validation=_strict_response_validation, |
112 | 111 | ) |
113 | 112 |
|
114 | | - self.connections = connections.ConnectionsResource(self) |
115 | | - self.integrations = integrations.IntegrationsResource(self) |
116 | | - self.memories = memories.MemoriesResource(self) |
117 | | - self.evaluate = evaluate.EvaluateResource(self) |
118 | | - self.vaults = vaults.VaultsResource(self) |
119 | | - self.auth = auth.AuthResource(self) |
120 | | - self.with_raw_response = HyperspellWithRawResponse(self) |
121 | | - self.with_streaming_response = HyperspellWithStreamedResponse(self) |
| 113 | + @cached_property |
| 114 | + def connections(self) -> ConnectionsResource: |
| 115 | + from .resources.connections import ConnectionsResource |
| 116 | + |
| 117 | + return ConnectionsResource(self) |
| 118 | + |
| 119 | + @cached_property |
| 120 | + def integrations(self) -> IntegrationsResource: |
| 121 | + from .resources.integrations import IntegrationsResource |
| 122 | + |
| 123 | + return IntegrationsResource(self) |
| 124 | + |
| 125 | + @cached_property |
| 126 | + def memories(self) -> MemoriesResource: |
| 127 | + from .resources.memories import MemoriesResource |
| 128 | + |
| 129 | + return MemoriesResource(self) |
| 130 | + |
| 131 | + @cached_property |
| 132 | + def evaluate(self) -> EvaluateResource: |
| 133 | + from .resources.evaluate import EvaluateResource |
| 134 | + |
| 135 | + return EvaluateResource(self) |
| 136 | + |
| 137 | + @cached_property |
| 138 | + def vaults(self) -> VaultsResource: |
| 139 | + from .resources.vaults import VaultsResource |
| 140 | + |
| 141 | + return VaultsResource(self) |
| 142 | + |
| 143 | + @cached_property |
| 144 | + def auth(self) -> AuthResource: |
| 145 | + from .resources.auth import AuthResource |
| 146 | + |
| 147 | + return AuthResource(self) |
| 148 | + |
| 149 | + @cached_property |
| 150 | + def with_raw_response(self) -> HyperspellWithRawResponse: |
| 151 | + return HyperspellWithRawResponse(self) |
| 152 | + |
| 153 | + @cached_property |
| 154 | + def with_streaming_response(self) -> HyperspellWithStreamedResponse: |
| 155 | + return HyperspellWithStreamedResponse(self) |
122 | 156 |
|
123 | 157 | @property |
124 | 158 | @override |
@@ -239,15 +273,6 @@ def _make_status_error( |
239 | 273 |
|
240 | 274 |
|
241 | 275 | class AsyncHyperspell(AsyncAPIClient): |
242 | | - connections: connections.AsyncConnectionsResource |
243 | | - integrations: integrations.AsyncIntegrationsResource |
244 | | - memories: memories.AsyncMemoriesResource |
245 | | - evaluate: evaluate.AsyncEvaluateResource |
246 | | - vaults: vaults.AsyncVaultsResource |
247 | | - auth: auth.AsyncAuthResource |
248 | | - with_raw_response: AsyncHyperspellWithRawResponse |
249 | | - with_streaming_response: AsyncHyperspellWithStreamedResponse |
250 | | - |
251 | 276 | # client options |
252 | 277 | api_key: str |
253 | 278 | user_id: str | None |
@@ -306,14 +331,49 @@ def __init__( |
306 | 331 | _strict_response_validation=_strict_response_validation, |
307 | 332 | ) |
308 | 333 |
|
309 | | - self.connections = connections.AsyncConnectionsResource(self) |
310 | | - self.integrations = integrations.AsyncIntegrationsResource(self) |
311 | | - self.memories = memories.AsyncMemoriesResource(self) |
312 | | - self.evaluate = evaluate.AsyncEvaluateResource(self) |
313 | | - self.vaults = vaults.AsyncVaultsResource(self) |
314 | | - self.auth = auth.AsyncAuthResource(self) |
315 | | - self.with_raw_response = AsyncHyperspellWithRawResponse(self) |
316 | | - self.with_streaming_response = AsyncHyperspellWithStreamedResponse(self) |
| 334 | + @cached_property |
| 335 | + def connections(self) -> AsyncConnectionsResource: |
| 336 | + from .resources.connections import AsyncConnectionsResource |
| 337 | + |
| 338 | + return AsyncConnectionsResource(self) |
| 339 | + |
| 340 | + @cached_property |
| 341 | + def integrations(self) -> AsyncIntegrationsResource: |
| 342 | + from .resources.integrations import AsyncIntegrationsResource |
| 343 | + |
| 344 | + return AsyncIntegrationsResource(self) |
| 345 | + |
| 346 | + @cached_property |
| 347 | + def memories(self) -> AsyncMemoriesResource: |
| 348 | + from .resources.memories import AsyncMemoriesResource |
| 349 | + |
| 350 | + return AsyncMemoriesResource(self) |
| 351 | + |
| 352 | + @cached_property |
| 353 | + def evaluate(self) -> AsyncEvaluateResource: |
| 354 | + from .resources.evaluate import AsyncEvaluateResource |
| 355 | + |
| 356 | + return AsyncEvaluateResource(self) |
| 357 | + |
| 358 | + @cached_property |
| 359 | + def vaults(self) -> AsyncVaultsResource: |
| 360 | + from .resources.vaults import AsyncVaultsResource |
| 361 | + |
| 362 | + return AsyncVaultsResource(self) |
| 363 | + |
| 364 | + @cached_property |
| 365 | + def auth(self) -> AsyncAuthResource: |
| 366 | + from .resources.auth import AsyncAuthResource |
| 367 | + |
| 368 | + return AsyncAuthResource(self) |
| 369 | + |
| 370 | + @cached_property |
| 371 | + def with_raw_response(self) -> AsyncHyperspellWithRawResponse: |
| 372 | + return AsyncHyperspellWithRawResponse(self) |
| 373 | + |
| 374 | + @cached_property |
| 375 | + def with_streaming_response(self) -> AsyncHyperspellWithStreamedResponse: |
| 376 | + return AsyncHyperspellWithStreamedResponse(self) |
317 | 377 |
|
318 | 378 | @property |
319 | 379 | @override |
@@ -434,43 +494,175 @@ def _make_status_error( |
434 | 494 |
|
435 | 495 |
|
436 | 496 | class HyperspellWithRawResponse: |
| 497 | + _client: Hyperspell |
| 498 | + |
437 | 499 | def __init__(self, client: Hyperspell) -> None: |
438 | | - self.connections = connections.ConnectionsResourceWithRawResponse(client.connections) |
439 | | - self.integrations = integrations.IntegrationsResourceWithRawResponse(client.integrations) |
440 | | - self.memories = memories.MemoriesResourceWithRawResponse(client.memories) |
441 | | - self.evaluate = evaluate.EvaluateResourceWithRawResponse(client.evaluate) |
442 | | - self.vaults = vaults.VaultsResourceWithRawResponse(client.vaults) |
443 | | - self.auth = auth.AuthResourceWithRawResponse(client.auth) |
| 500 | + self._client = client |
| 501 | + |
| 502 | + @cached_property |
| 503 | + def connections(self) -> connections.ConnectionsResourceWithRawResponse: |
| 504 | + from .resources.connections import ConnectionsResourceWithRawResponse |
| 505 | + |
| 506 | + return ConnectionsResourceWithRawResponse(self._client.connections) |
| 507 | + |
| 508 | + @cached_property |
| 509 | + def integrations(self) -> integrations.IntegrationsResourceWithRawResponse: |
| 510 | + from .resources.integrations import IntegrationsResourceWithRawResponse |
| 511 | + |
| 512 | + return IntegrationsResourceWithRawResponse(self._client.integrations) |
| 513 | + |
| 514 | + @cached_property |
| 515 | + def memories(self) -> memories.MemoriesResourceWithRawResponse: |
| 516 | + from .resources.memories import MemoriesResourceWithRawResponse |
| 517 | + |
| 518 | + return MemoriesResourceWithRawResponse(self._client.memories) |
| 519 | + |
| 520 | + @cached_property |
| 521 | + def evaluate(self) -> evaluate.EvaluateResourceWithRawResponse: |
| 522 | + from .resources.evaluate import EvaluateResourceWithRawResponse |
| 523 | + |
| 524 | + return EvaluateResourceWithRawResponse(self._client.evaluate) |
| 525 | + |
| 526 | + @cached_property |
| 527 | + def vaults(self) -> vaults.VaultsResourceWithRawResponse: |
| 528 | + from .resources.vaults import VaultsResourceWithRawResponse |
| 529 | + |
| 530 | + return VaultsResourceWithRawResponse(self._client.vaults) |
| 531 | + |
| 532 | + @cached_property |
| 533 | + def auth(self) -> auth.AuthResourceWithRawResponse: |
| 534 | + from .resources.auth import AuthResourceWithRawResponse |
| 535 | + |
| 536 | + return AuthResourceWithRawResponse(self._client.auth) |
444 | 537 |
|
445 | 538 |
|
446 | 539 | class AsyncHyperspellWithRawResponse: |
| 540 | + _client: AsyncHyperspell |
| 541 | + |
447 | 542 | def __init__(self, client: AsyncHyperspell) -> None: |
448 | | - self.connections = connections.AsyncConnectionsResourceWithRawResponse(client.connections) |
449 | | - self.integrations = integrations.AsyncIntegrationsResourceWithRawResponse(client.integrations) |
450 | | - self.memories = memories.AsyncMemoriesResourceWithRawResponse(client.memories) |
451 | | - self.evaluate = evaluate.AsyncEvaluateResourceWithRawResponse(client.evaluate) |
452 | | - self.vaults = vaults.AsyncVaultsResourceWithRawResponse(client.vaults) |
453 | | - self.auth = auth.AsyncAuthResourceWithRawResponse(client.auth) |
| 543 | + self._client = client |
| 544 | + |
| 545 | + @cached_property |
| 546 | + def connections(self) -> connections.AsyncConnectionsResourceWithRawResponse: |
| 547 | + from .resources.connections import AsyncConnectionsResourceWithRawResponse |
| 548 | + |
| 549 | + return AsyncConnectionsResourceWithRawResponse(self._client.connections) |
| 550 | + |
| 551 | + @cached_property |
| 552 | + def integrations(self) -> integrations.AsyncIntegrationsResourceWithRawResponse: |
| 553 | + from .resources.integrations import AsyncIntegrationsResourceWithRawResponse |
| 554 | + |
| 555 | + return AsyncIntegrationsResourceWithRawResponse(self._client.integrations) |
| 556 | + |
| 557 | + @cached_property |
| 558 | + def memories(self) -> memories.AsyncMemoriesResourceWithRawResponse: |
| 559 | + from .resources.memories import AsyncMemoriesResourceWithRawResponse |
| 560 | + |
| 561 | + return AsyncMemoriesResourceWithRawResponse(self._client.memories) |
| 562 | + |
| 563 | + @cached_property |
| 564 | + def evaluate(self) -> evaluate.AsyncEvaluateResourceWithRawResponse: |
| 565 | + from .resources.evaluate import AsyncEvaluateResourceWithRawResponse |
| 566 | + |
| 567 | + return AsyncEvaluateResourceWithRawResponse(self._client.evaluate) |
| 568 | + |
| 569 | + @cached_property |
| 570 | + def vaults(self) -> vaults.AsyncVaultsResourceWithRawResponse: |
| 571 | + from .resources.vaults import AsyncVaultsResourceWithRawResponse |
| 572 | + |
| 573 | + return AsyncVaultsResourceWithRawResponse(self._client.vaults) |
| 574 | + |
| 575 | + @cached_property |
| 576 | + def auth(self) -> auth.AsyncAuthResourceWithRawResponse: |
| 577 | + from .resources.auth import AsyncAuthResourceWithRawResponse |
| 578 | + |
| 579 | + return AsyncAuthResourceWithRawResponse(self._client.auth) |
454 | 580 |
|
455 | 581 |
|
456 | 582 | class HyperspellWithStreamedResponse: |
| 583 | + _client: Hyperspell |
| 584 | + |
457 | 585 | def __init__(self, client: Hyperspell) -> None: |
458 | | - self.connections = connections.ConnectionsResourceWithStreamingResponse(client.connections) |
459 | | - self.integrations = integrations.IntegrationsResourceWithStreamingResponse(client.integrations) |
460 | | - self.memories = memories.MemoriesResourceWithStreamingResponse(client.memories) |
461 | | - self.evaluate = evaluate.EvaluateResourceWithStreamingResponse(client.evaluate) |
462 | | - self.vaults = vaults.VaultsResourceWithStreamingResponse(client.vaults) |
463 | | - self.auth = auth.AuthResourceWithStreamingResponse(client.auth) |
| 586 | + self._client = client |
| 587 | + |
| 588 | + @cached_property |
| 589 | + def connections(self) -> connections.ConnectionsResourceWithStreamingResponse: |
| 590 | + from .resources.connections import ConnectionsResourceWithStreamingResponse |
| 591 | + |
| 592 | + return ConnectionsResourceWithStreamingResponse(self._client.connections) |
| 593 | + |
| 594 | + @cached_property |
| 595 | + def integrations(self) -> integrations.IntegrationsResourceWithStreamingResponse: |
| 596 | + from .resources.integrations import IntegrationsResourceWithStreamingResponse |
| 597 | + |
| 598 | + return IntegrationsResourceWithStreamingResponse(self._client.integrations) |
| 599 | + |
| 600 | + @cached_property |
| 601 | + def memories(self) -> memories.MemoriesResourceWithStreamingResponse: |
| 602 | + from .resources.memories import MemoriesResourceWithStreamingResponse |
| 603 | + |
| 604 | + return MemoriesResourceWithStreamingResponse(self._client.memories) |
| 605 | + |
| 606 | + @cached_property |
| 607 | + def evaluate(self) -> evaluate.EvaluateResourceWithStreamingResponse: |
| 608 | + from .resources.evaluate import EvaluateResourceWithStreamingResponse |
| 609 | + |
| 610 | + return EvaluateResourceWithStreamingResponse(self._client.evaluate) |
| 611 | + |
| 612 | + @cached_property |
| 613 | + def vaults(self) -> vaults.VaultsResourceWithStreamingResponse: |
| 614 | + from .resources.vaults import VaultsResourceWithStreamingResponse |
| 615 | + |
| 616 | + return VaultsResourceWithStreamingResponse(self._client.vaults) |
| 617 | + |
| 618 | + @cached_property |
| 619 | + def auth(self) -> auth.AuthResourceWithStreamingResponse: |
| 620 | + from .resources.auth import AuthResourceWithStreamingResponse |
| 621 | + |
| 622 | + return AuthResourceWithStreamingResponse(self._client.auth) |
464 | 623 |
|
465 | 624 |
|
466 | 625 | class AsyncHyperspellWithStreamedResponse: |
| 626 | + _client: AsyncHyperspell |
| 627 | + |
467 | 628 | def __init__(self, client: AsyncHyperspell) -> None: |
468 | | - self.connections = connections.AsyncConnectionsResourceWithStreamingResponse(client.connections) |
469 | | - self.integrations = integrations.AsyncIntegrationsResourceWithStreamingResponse(client.integrations) |
470 | | - self.memories = memories.AsyncMemoriesResourceWithStreamingResponse(client.memories) |
471 | | - self.evaluate = evaluate.AsyncEvaluateResourceWithStreamingResponse(client.evaluate) |
472 | | - self.vaults = vaults.AsyncVaultsResourceWithStreamingResponse(client.vaults) |
473 | | - self.auth = auth.AsyncAuthResourceWithStreamingResponse(client.auth) |
| 629 | + self._client = client |
| 630 | + |
| 631 | + @cached_property |
| 632 | + def connections(self) -> connections.AsyncConnectionsResourceWithStreamingResponse: |
| 633 | + from .resources.connections import AsyncConnectionsResourceWithStreamingResponse |
| 634 | + |
| 635 | + return AsyncConnectionsResourceWithStreamingResponse(self._client.connections) |
| 636 | + |
| 637 | + @cached_property |
| 638 | + def integrations(self) -> integrations.AsyncIntegrationsResourceWithStreamingResponse: |
| 639 | + from .resources.integrations import AsyncIntegrationsResourceWithStreamingResponse |
| 640 | + |
| 641 | + return AsyncIntegrationsResourceWithStreamingResponse(self._client.integrations) |
| 642 | + |
| 643 | + @cached_property |
| 644 | + def memories(self) -> memories.AsyncMemoriesResourceWithStreamingResponse: |
| 645 | + from .resources.memories import AsyncMemoriesResourceWithStreamingResponse |
| 646 | + |
| 647 | + return AsyncMemoriesResourceWithStreamingResponse(self._client.memories) |
| 648 | + |
| 649 | + @cached_property |
| 650 | + def evaluate(self) -> evaluate.AsyncEvaluateResourceWithStreamingResponse: |
| 651 | + from .resources.evaluate import AsyncEvaluateResourceWithStreamingResponse |
| 652 | + |
| 653 | + return AsyncEvaluateResourceWithStreamingResponse(self._client.evaluate) |
| 654 | + |
| 655 | + @cached_property |
| 656 | + def vaults(self) -> vaults.AsyncVaultsResourceWithStreamingResponse: |
| 657 | + from .resources.vaults import AsyncVaultsResourceWithStreamingResponse |
| 658 | + |
| 659 | + return AsyncVaultsResourceWithStreamingResponse(self._client.vaults) |
| 660 | + |
| 661 | + @cached_property |
| 662 | + def auth(self) -> auth.AsyncAuthResourceWithStreamingResponse: |
| 663 | + from .resources.auth import AsyncAuthResourceWithStreamingResponse |
| 664 | + |
| 665 | + return AsyncAuthResourceWithStreamingResponse(self._client.auth) |
474 | 666 |
|
475 | 667 |
|
476 | 668 | Client = Hyperspell |
|
0 commit comments