Skip to content

Commit 4ebe231

Browse files
chore: speedup initial import
1 parent 1d7820f commit 4ebe231

File tree

1 file changed

+192
-50
lines changed

1 file changed

+192
-50
lines changed

src/miru_server_sdk/_client.py

Lines changed: 192 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import Any, Dict, Mapping, cast
6+
from typing import TYPE_CHECKING, Any, Dict, Mapping, cast
77
from typing_extensions import Self, Literal, override
88

99
import httpx
@@ -20,8 +20,8 @@
2020
not_given,
2121
)
2222
from ._utils import is_given, get_async_library
23+
from ._compat import cached_property
2324
from ._version import __version__
24-
from .resources import devices, releases, webhooks, deployments, config_instances
2525
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2626
from ._exceptions import MiruError, APIStatusError
2727
from ._base_client import (
@@ -30,6 +30,14 @@
3030
AsyncAPIClient,
3131
)
3232

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+
3341
__all__ = [
3442
"ENVIRONMENTS",
3543
"Timeout",
@@ -51,14 +59,6 @@
5159

5260

5361
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-
6262
# client options
6363
api_key: str
6464
host: str
@@ -152,13 +152,43 @@ def __init__(
152152
_strict_response_validation=_strict_response_validation,
153153
)
154154

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)
162192

163193
@property
164194
@override
@@ -272,14 +302,6 @@ def _make_status_error(
272302

273303

274304
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-
283305
# client options
284306
api_key: str
285307
host: str
@@ -373,13 +395,43 @@ def __init__(
373395
_strict_response_validation=_strict_response_validation,
374396
)
375397

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)
383435

384436
@property
385437
@override
@@ -493,37 +545,127 @@ def _make_status_error(
493545

494546

495547
class MiruWithRawResponse:
548+
_client: Miru
549+
496550
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)
501576

502577

503578
class AsyncMiruWithRawResponse:
579+
_client: AsyncMiru
580+
504581
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)
509607

510608

511609
class MiruWithStreamedResponse:
610+
_client: Miru
611+
512612
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)
517638

518639

519640
class AsyncMiruWithStreamedResponse:
641+
_client: AsyncMiru
642+
520643
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)
527669

528670

529671
Client = Miru

0 commit comments

Comments
 (0)