|
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 devices, releases, webhooks, deployments, config_instances |
25 | 25 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
26 | 26 | from ._exceptions import MiruError, APIStatusError |
27 | 27 | from ._base_client import ( |
|
30 | 30 | AsyncAPIClient, |
31 | 31 | ) |
32 | 32 |
|
| 33 | +if TYPE_CHECKING: |
| 34 | + from .resources import devices, releases, deployments, config_instances |
| 35 | + from .resources.devices import DevicesResource, AsyncDevicesResource |
| 36 | + from .resources.releases import ReleasesResource, AsyncReleasesResource |
| 37 | + from .resources.webhooks import WebhooksResource, AsyncWebhooksResource |
| 38 | + from .resources.deployments import DeploymentsResource, AsyncDeploymentsResource |
| 39 | + from .resources.config_instances import ConfigInstancesResource, AsyncConfigInstancesResource |
| 40 | + |
33 | 41 | __all__ = [ |
34 | 42 | "ENVIRONMENTS", |
35 | 43 | "Timeout", |
|
51 | 59 |
|
52 | 60 |
|
53 | 61 | class Miru(SyncAPIClient): |
54 | | - config_instances: config_instances.ConfigInstancesResource |
55 | | - deployments: deployments.DeploymentsResource |
56 | | - devices: devices.DevicesResource |
57 | | - releases: releases.ReleasesResource |
58 | | - webhooks: webhooks.WebhooksResource |
59 | | - with_raw_response: MiruWithRawResponse |
60 | | - with_streaming_response: MiruWithStreamedResponse |
61 | | - |
62 | 62 | # client options |
63 | 63 | api_key: str |
64 | 64 | host: str |
@@ -152,13 +152,43 @@ def __init__( |
152 | 152 | _strict_response_validation=_strict_response_validation, |
153 | 153 | ) |
154 | 154 |
|
155 | | - self.config_instances = config_instances.ConfigInstancesResource(self) |
156 | | - self.deployments = deployments.DeploymentsResource(self) |
157 | | - self.devices = devices.DevicesResource(self) |
158 | | - self.releases = releases.ReleasesResource(self) |
159 | | - self.webhooks = webhooks.WebhooksResource(self) |
160 | | - self.with_raw_response = MiruWithRawResponse(self) |
161 | | - self.with_streaming_response = MiruWithStreamedResponse(self) |
| 155 | + @cached_property |
| 156 | + def config_instances(self) -> ConfigInstancesResource: |
| 157 | + from .resources.config_instances import ConfigInstancesResource |
| 158 | + |
| 159 | + return ConfigInstancesResource(self) |
| 160 | + |
| 161 | + @cached_property |
| 162 | + def deployments(self) -> DeploymentsResource: |
| 163 | + from .resources.deployments import DeploymentsResource |
| 164 | + |
| 165 | + return DeploymentsResource(self) |
| 166 | + |
| 167 | + @cached_property |
| 168 | + def devices(self) -> DevicesResource: |
| 169 | + from .resources.devices import DevicesResource |
| 170 | + |
| 171 | + return DevicesResource(self) |
| 172 | + |
| 173 | + @cached_property |
| 174 | + def releases(self) -> ReleasesResource: |
| 175 | + from .resources.releases import ReleasesResource |
| 176 | + |
| 177 | + return ReleasesResource(self) |
| 178 | + |
| 179 | + @cached_property |
| 180 | + def webhooks(self) -> WebhooksResource: |
| 181 | + from .resources.webhooks import WebhooksResource |
| 182 | + |
| 183 | + return WebhooksResource(self) |
| 184 | + |
| 185 | + @cached_property |
| 186 | + def with_raw_response(self) -> MiruWithRawResponse: |
| 187 | + return MiruWithRawResponse(self) |
| 188 | + |
| 189 | + @cached_property |
| 190 | + def with_streaming_response(self) -> MiruWithStreamedResponse: |
| 191 | + return MiruWithStreamedResponse(self) |
162 | 192 |
|
163 | 193 | @property |
164 | 194 | @override |
@@ -272,14 +302,6 @@ def _make_status_error( |
272 | 302 |
|
273 | 303 |
|
274 | 304 | class AsyncMiru(AsyncAPIClient): |
275 | | - config_instances: config_instances.AsyncConfigInstancesResource |
276 | | - deployments: deployments.AsyncDeploymentsResource |
277 | | - devices: devices.AsyncDevicesResource |
278 | | - releases: releases.AsyncReleasesResource |
279 | | - webhooks: webhooks.AsyncWebhooksResource |
280 | | - with_raw_response: AsyncMiruWithRawResponse |
281 | | - with_streaming_response: AsyncMiruWithStreamedResponse |
282 | | - |
283 | 305 | # client options |
284 | 306 | api_key: str |
285 | 307 | host: str |
@@ -373,13 +395,43 @@ def __init__( |
373 | 395 | _strict_response_validation=_strict_response_validation, |
374 | 396 | ) |
375 | 397 |
|
376 | | - self.config_instances = config_instances.AsyncConfigInstancesResource(self) |
377 | | - self.deployments = deployments.AsyncDeploymentsResource(self) |
378 | | - self.devices = devices.AsyncDevicesResource(self) |
379 | | - self.releases = releases.AsyncReleasesResource(self) |
380 | | - self.webhooks = webhooks.AsyncWebhooksResource(self) |
381 | | - self.with_raw_response = AsyncMiruWithRawResponse(self) |
382 | | - self.with_streaming_response = AsyncMiruWithStreamedResponse(self) |
| 398 | + @cached_property |
| 399 | + def config_instances(self) -> AsyncConfigInstancesResource: |
| 400 | + from .resources.config_instances import AsyncConfigInstancesResource |
| 401 | + |
| 402 | + return AsyncConfigInstancesResource(self) |
| 403 | + |
| 404 | + @cached_property |
| 405 | + def deployments(self) -> AsyncDeploymentsResource: |
| 406 | + from .resources.deployments import AsyncDeploymentsResource |
| 407 | + |
| 408 | + return AsyncDeploymentsResource(self) |
| 409 | + |
| 410 | + @cached_property |
| 411 | + def devices(self) -> AsyncDevicesResource: |
| 412 | + from .resources.devices import AsyncDevicesResource |
| 413 | + |
| 414 | + return AsyncDevicesResource(self) |
| 415 | + |
| 416 | + @cached_property |
| 417 | + def releases(self) -> AsyncReleasesResource: |
| 418 | + from .resources.releases import AsyncReleasesResource |
| 419 | + |
| 420 | + return AsyncReleasesResource(self) |
| 421 | + |
| 422 | + @cached_property |
| 423 | + def webhooks(self) -> AsyncWebhooksResource: |
| 424 | + from .resources.webhooks import AsyncWebhooksResource |
| 425 | + |
| 426 | + return AsyncWebhooksResource(self) |
| 427 | + |
| 428 | + @cached_property |
| 429 | + def with_raw_response(self) -> AsyncMiruWithRawResponse: |
| 430 | + return AsyncMiruWithRawResponse(self) |
| 431 | + |
| 432 | + @cached_property |
| 433 | + def with_streaming_response(self) -> AsyncMiruWithStreamedResponse: |
| 434 | + return AsyncMiruWithStreamedResponse(self) |
383 | 435 |
|
384 | 436 | @property |
385 | 437 | @override |
@@ -493,37 +545,127 @@ def _make_status_error( |
493 | 545 |
|
494 | 546 |
|
495 | 547 | class MiruWithRawResponse: |
| 548 | + _client: Miru |
| 549 | + |
496 | 550 | def __init__(self, client: Miru) -> None: |
497 | | - self.config_instances = config_instances.ConfigInstancesResourceWithRawResponse(client.config_instances) |
498 | | - self.deployments = deployments.DeploymentsResourceWithRawResponse(client.deployments) |
499 | | - self.devices = devices.DevicesResourceWithRawResponse(client.devices) |
500 | | - self.releases = releases.ReleasesResourceWithRawResponse(client.releases) |
| 551 | + self._client = client |
| 552 | + |
| 553 | + @cached_property |
| 554 | + def config_instances(self) -> config_instances.ConfigInstancesResourceWithRawResponse: |
| 555 | + from .resources.config_instances import ConfigInstancesResourceWithRawResponse |
| 556 | + |
| 557 | + return ConfigInstancesResourceWithRawResponse(self._client.config_instances) |
| 558 | + |
| 559 | + @cached_property |
| 560 | + def deployments(self) -> deployments.DeploymentsResourceWithRawResponse: |
| 561 | + from .resources.deployments import DeploymentsResourceWithRawResponse |
| 562 | + |
| 563 | + return DeploymentsResourceWithRawResponse(self._client.deployments) |
| 564 | + |
| 565 | + @cached_property |
| 566 | + def devices(self) -> devices.DevicesResourceWithRawResponse: |
| 567 | + from .resources.devices import DevicesResourceWithRawResponse |
| 568 | + |
| 569 | + return DevicesResourceWithRawResponse(self._client.devices) |
| 570 | + |
| 571 | + @cached_property |
| 572 | + def releases(self) -> releases.ReleasesResourceWithRawResponse: |
| 573 | + from .resources.releases import ReleasesResourceWithRawResponse |
| 574 | + |
| 575 | + return ReleasesResourceWithRawResponse(self._client.releases) |
501 | 576 |
|
502 | 577 |
|
503 | 578 | class AsyncMiruWithRawResponse: |
| 579 | + _client: AsyncMiru |
| 580 | + |
504 | 581 | def __init__(self, client: AsyncMiru) -> None: |
505 | | - self.config_instances = config_instances.AsyncConfigInstancesResourceWithRawResponse(client.config_instances) |
506 | | - self.deployments = deployments.AsyncDeploymentsResourceWithRawResponse(client.deployments) |
507 | | - self.devices = devices.AsyncDevicesResourceWithRawResponse(client.devices) |
508 | | - self.releases = releases.AsyncReleasesResourceWithRawResponse(client.releases) |
| 582 | + self._client = client |
| 583 | + |
| 584 | + @cached_property |
| 585 | + def config_instances(self) -> config_instances.AsyncConfigInstancesResourceWithRawResponse: |
| 586 | + from .resources.config_instances import AsyncConfigInstancesResourceWithRawResponse |
| 587 | + |
| 588 | + return AsyncConfigInstancesResourceWithRawResponse(self._client.config_instances) |
| 589 | + |
| 590 | + @cached_property |
| 591 | + def deployments(self) -> deployments.AsyncDeploymentsResourceWithRawResponse: |
| 592 | + from .resources.deployments import AsyncDeploymentsResourceWithRawResponse |
| 593 | + |
| 594 | + return AsyncDeploymentsResourceWithRawResponse(self._client.deployments) |
| 595 | + |
| 596 | + @cached_property |
| 597 | + def devices(self) -> devices.AsyncDevicesResourceWithRawResponse: |
| 598 | + from .resources.devices import AsyncDevicesResourceWithRawResponse |
| 599 | + |
| 600 | + return AsyncDevicesResourceWithRawResponse(self._client.devices) |
| 601 | + |
| 602 | + @cached_property |
| 603 | + def releases(self) -> releases.AsyncReleasesResourceWithRawResponse: |
| 604 | + from .resources.releases import AsyncReleasesResourceWithRawResponse |
| 605 | + |
| 606 | + return AsyncReleasesResourceWithRawResponse(self._client.releases) |
509 | 607 |
|
510 | 608 |
|
511 | 609 | class MiruWithStreamedResponse: |
| 610 | + _client: Miru |
| 611 | + |
512 | 612 | def __init__(self, client: Miru) -> None: |
513 | | - self.config_instances = config_instances.ConfigInstancesResourceWithStreamingResponse(client.config_instances) |
514 | | - self.deployments = deployments.DeploymentsResourceWithStreamingResponse(client.deployments) |
515 | | - self.devices = devices.DevicesResourceWithStreamingResponse(client.devices) |
516 | | - self.releases = releases.ReleasesResourceWithStreamingResponse(client.releases) |
| 613 | + self._client = client |
| 614 | + |
| 615 | + @cached_property |
| 616 | + def config_instances(self) -> config_instances.ConfigInstancesResourceWithStreamingResponse: |
| 617 | + from .resources.config_instances import ConfigInstancesResourceWithStreamingResponse |
| 618 | + |
| 619 | + return ConfigInstancesResourceWithStreamingResponse(self._client.config_instances) |
| 620 | + |
| 621 | + @cached_property |
| 622 | + def deployments(self) -> deployments.DeploymentsResourceWithStreamingResponse: |
| 623 | + from .resources.deployments import DeploymentsResourceWithStreamingResponse |
| 624 | + |
| 625 | + return DeploymentsResourceWithStreamingResponse(self._client.deployments) |
| 626 | + |
| 627 | + @cached_property |
| 628 | + def devices(self) -> devices.DevicesResourceWithStreamingResponse: |
| 629 | + from .resources.devices import DevicesResourceWithStreamingResponse |
| 630 | + |
| 631 | + return DevicesResourceWithStreamingResponse(self._client.devices) |
| 632 | + |
| 633 | + @cached_property |
| 634 | + def releases(self) -> releases.ReleasesResourceWithStreamingResponse: |
| 635 | + from .resources.releases import ReleasesResourceWithStreamingResponse |
| 636 | + |
| 637 | + return ReleasesResourceWithStreamingResponse(self._client.releases) |
517 | 638 |
|
518 | 639 |
|
519 | 640 | class AsyncMiruWithStreamedResponse: |
| 641 | + _client: AsyncMiru |
| 642 | + |
520 | 643 | def __init__(self, client: AsyncMiru) -> None: |
521 | | - self.config_instances = config_instances.AsyncConfigInstancesResourceWithStreamingResponse( |
522 | | - client.config_instances |
523 | | - ) |
524 | | - self.deployments = deployments.AsyncDeploymentsResourceWithStreamingResponse(client.deployments) |
525 | | - self.devices = devices.AsyncDevicesResourceWithStreamingResponse(client.devices) |
526 | | - self.releases = releases.AsyncReleasesResourceWithStreamingResponse(client.releases) |
| 644 | + self._client = client |
| 645 | + |
| 646 | + @cached_property |
| 647 | + def config_instances(self) -> config_instances.AsyncConfigInstancesResourceWithStreamingResponse: |
| 648 | + from .resources.config_instances import AsyncConfigInstancesResourceWithStreamingResponse |
| 649 | + |
| 650 | + return AsyncConfigInstancesResourceWithStreamingResponse(self._client.config_instances) |
| 651 | + |
| 652 | + @cached_property |
| 653 | + def deployments(self) -> deployments.AsyncDeploymentsResourceWithStreamingResponse: |
| 654 | + from .resources.deployments import AsyncDeploymentsResourceWithStreamingResponse |
| 655 | + |
| 656 | + return AsyncDeploymentsResourceWithStreamingResponse(self._client.deployments) |
| 657 | + |
| 658 | + @cached_property |
| 659 | + def devices(self) -> devices.AsyncDevicesResourceWithStreamingResponse: |
| 660 | + from .resources.devices import AsyncDevicesResourceWithStreamingResponse |
| 661 | + |
| 662 | + return AsyncDevicesResourceWithStreamingResponse(self._client.devices) |
| 663 | + |
| 664 | + @cached_property |
| 665 | + def releases(self) -> releases.AsyncReleasesResourceWithStreamingResponse: |
| 666 | + from .resources.releases import AsyncReleasesResourceWithStreamingResponse |
| 667 | + |
| 668 | + return AsyncReleasesResourceWithStreamingResponse(self._client.releases) |
527 | 669 |
|
528 | 670 |
|
529 | 671 | Client = Miru |
|
0 commit comments