Skip to content

Commit 2d500ed

Browse files
chore: speedup initial import
1 parent 669f50a commit 2d500ed

1 file changed

Lines changed: 179 additions & 46 deletions

File tree

src/isaacus/_client.py

Lines changed: 179 additions & 46 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, Mapping
6+
from typing import TYPE_CHECKING, Any, Mapping
77
from typing_extensions import Self, override
88

99
import httpx
@@ -20,29 +20,27 @@
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 embeddings, rerankings
2525
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2626
from ._exceptions import IsaacusError, APIStatusError
2727
from ._base_client import (
2828
DEFAULT_MAX_RETRIES,
2929
SyncAPIClient,
3030
AsyncAPIClient,
3131
)
32-
from .resources.extractions import extractions
33-
from .resources.classifications import classifications
32+
33+
if TYPE_CHECKING:
34+
from .resources import embeddings, rerankings, extractions, classifications
35+
from .resources.embeddings import EmbeddingsResource, AsyncEmbeddingsResource
36+
from .resources.rerankings import RerankingsResource, AsyncRerankingsResource
37+
from .resources.extractions.extractions import ExtractionsResource, AsyncExtractionsResource
38+
from .resources.classifications.classifications import ClassificationsResource, AsyncClassificationsResource
3439

3540
__all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Isaacus", "AsyncIsaacus", "Client", "AsyncClient"]
3641

3742

3843
class Isaacus(SyncAPIClient):
39-
embeddings: embeddings.EmbeddingsResource
40-
classifications: classifications.ClassificationsResource
41-
rerankings: rerankings.RerankingsResource
42-
extractions: extractions.ExtractionsResource
43-
with_raw_response: IsaacusWithRawResponse
44-
with_streaming_response: IsaacusWithStreamedResponse
45-
4644
# client options
4745
api_key: str
4846

@@ -97,12 +95,37 @@ def __init__(
9795
_strict_response_validation=_strict_response_validation,
9896
)
9997

100-
self.embeddings = embeddings.EmbeddingsResource(self)
101-
self.classifications = classifications.ClassificationsResource(self)
102-
self.rerankings = rerankings.RerankingsResource(self)
103-
self.extractions = extractions.ExtractionsResource(self)
104-
self.with_raw_response = IsaacusWithRawResponse(self)
105-
self.with_streaming_response = IsaacusWithStreamedResponse(self)
98+
@cached_property
99+
def embeddings(self) -> EmbeddingsResource:
100+
from .resources.embeddings import EmbeddingsResource
101+
102+
return EmbeddingsResource(self)
103+
104+
@cached_property
105+
def classifications(self) -> ClassificationsResource:
106+
from .resources.classifications import ClassificationsResource
107+
108+
return ClassificationsResource(self)
109+
110+
@cached_property
111+
def rerankings(self) -> RerankingsResource:
112+
from .resources.rerankings import RerankingsResource
113+
114+
return RerankingsResource(self)
115+
116+
@cached_property
117+
def extractions(self) -> ExtractionsResource:
118+
from .resources.extractions import ExtractionsResource
119+
120+
return ExtractionsResource(self)
121+
122+
@cached_property
123+
def with_raw_response(self) -> IsaacusWithRawResponse:
124+
return IsaacusWithRawResponse(self)
125+
126+
@cached_property
127+
def with_streaming_response(self) -> IsaacusWithStreamedResponse:
128+
return IsaacusWithStreamedResponse(self)
106129

107130
@property
108131
@override
@@ -210,13 +233,6 @@ def _make_status_error(
210233

211234

212235
class AsyncIsaacus(AsyncAPIClient):
213-
embeddings: embeddings.AsyncEmbeddingsResource
214-
classifications: classifications.AsyncClassificationsResource
215-
rerankings: rerankings.AsyncRerankingsResource
216-
extractions: extractions.AsyncExtractionsResource
217-
with_raw_response: AsyncIsaacusWithRawResponse
218-
with_streaming_response: AsyncIsaacusWithStreamedResponse
219-
220236
# client options
221237
api_key: str
222238

@@ -271,12 +287,37 @@ def __init__(
271287
_strict_response_validation=_strict_response_validation,
272288
)
273289

274-
self.embeddings = embeddings.AsyncEmbeddingsResource(self)
275-
self.classifications = classifications.AsyncClassificationsResource(self)
276-
self.rerankings = rerankings.AsyncRerankingsResource(self)
277-
self.extractions = extractions.AsyncExtractionsResource(self)
278-
self.with_raw_response = AsyncIsaacusWithRawResponse(self)
279-
self.with_streaming_response = AsyncIsaacusWithStreamedResponse(self)
290+
@cached_property
291+
def embeddings(self) -> AsyncEmbeddingsResource:
292+
from .resources.embeddings import AsyncEmbeddingsResource
293+
294+
return AsyncEmbeddingsResource(self)
295+
296+
@cached_property
297+
def classifications(self) -> AsyncClassificationsResource:
298+
from .resources.classifications import AsyncClassificationsResource
299+
300+
return AsyncClassificationsResource(self)
301+
302+
@cached_property
303+
def rerankings(self) -> AsyncRerankingsResource:
304+
from .resources.rerankings import AsyncRerankingsResource
305+
306+
return AsyncRerankingsResource(self)
307+
308+
@cached_property
309+
def extractions(self) -> AsyncExtractionsResource:
310+
from .resources.extractions import AsyncExtractionsResource
311+
312+
return AsyncExtractionsResource(self)
313+
314+
@cached_property
315+
def with_raw_response(self) -> AsyncIsaacusWithRawResponse:
316+
return AsyncIsaacusWithRawResponse(self)
317+
318+
@cached_property
319+
def with_streaming_response(self) -> AsyncIsaacusWithStreamedResponse:
320+
return AsyncIsaacusWithStreamedResponse(self)
280321

281322
@property
282323
@override
@@ -384,35 +425,127 @@ def _make_status_error(
384425

385426

386427
class IsaacusWithRawResponse:
428+
_client: Isaacus
429+
387430
def __init__(self, client: Isaacus) -> None:
388-
self.embeddings = embeddings.EmbeddingsResourceWithRawResponse(client.embeddings)
389-
self.classifications = classifications.ClassificationsResourceWithRawResponse(client.classifications)
390-
self.rerankings = rerankings.RerankingsResourceWithRawResponse(client.rerankings)
391-
self.extractions = extractions.ExtractionsResourceWithRawResponse(client.extractions)
431+
self._client = client
432+
433+
@cached_property
434+
def embeddings(self) -> embeddings.EmbeddingsResourceWithRawResponse:
435+
from .resources.embeddings import EmbeddingsResourceWithRawResponse
436+
437+
return EmbeddingsResourceWithRawResponse(self._client.embeddings)
438+
439+
@cached_property
440+
def classifications(self) -> classifications.ClassificationsResourceWithRawResponse:
441+
from .resources.classifications import ClassificationsResourceWithRawResponse
442+
443+
return ClassificationsResourceWithRawResponse(self._client.classifications)
444+
445+
@cached_property
446+
def rerankings(self) -> rerankings.RerankingsResourceWithRawResponse:
447+
from .resources.rerankings import RerankingsResourceWithRawResponse
448+
449+
return RerankingsResourceWithRawResponse(self._client.rerankings)
450+
451+
@cached_property
452+
def extractions(self) -> extractions.ExtractionsResourceWithRawResponse:
453+
from .resources.extractions import ExtractionsResourceWithRawResponse
454+
455+
return ExtractionsResourceWithRawResponse(self._client.extractions)
392456

393457

394458
class AsyncIsaacusWithRawResponse:
459+
_client: AsyncIsaacus
460+
395461
def __init__(self, client: AsyncIsaacus) -> None:
396-
self.embeddings = embeddings.AsyncEmbeddingsResourceWithRawResponse(client.embeddings)
397-
self.classifications = classifications.AsyncClassificationsResourceWithRawResponse(client.classifications)
398-
self.rerankings = rerankings.AsyncRerankingsResourceWithRawResponse(client.rerankings)
399-
self.extractions = extractions.AsyncExtractionsResourceWithRawResponse(client.extractions)
462+
self._client = client
463+
464+
@cached_property
465+
def embeddings(self) -> embeddings.AsyncEmbeddingsResourceWithRawResponse:
466+
from .resources.embeddings import AsyncEmbeddingsResourceWithRawResponse
467+
468+
return AsyncEmbeddingsResourceWithRawResponse(self._client.embeddings)
469+
470+
@cached_property
471+
def classifications(self) -> classifications.AsyncClassificationsResourceWithRawResponse:
472+
from .resources.classifications import AsyncClassificationsResourceWithRawResponse
473+
474+
return AsyncClassificationsResourceWithRawResponse(self._client.classifications)
475+
476+
@cached_property
477+
def rerankings(self) -> rerankings.AsyncRerankingsResourceWithRawResponse:
478+
from .resources.rerankings import AsyncRerankingsResourceWithRawResponse
479+
480+
return AsyncRerankingsResourceWithRawResponse(self._client.rerankings)
481+
482+
@cached_property
483+
def extractions(self) -> extractions.AsyncExtractionsResourceWithRawResponse:
484+
from .resources.extractions import AsyncExtractionsResourceWithRawResponse
485+
486+
return AsyncExtractionsResourceWithRawResponse(self._client.extractions)
400487

401488

402489
class IsaacusWithStreamedResponse:
490+
_client: Isaacus
491+
403492
def __init__(self, client: Isaacus) -> None:
404-
self.embeddings = embeddings.EmbeddingsResourceWithStreamingResponse(client.embeddings)
405-
self.classifications = classifications.ClassificationsResourceWithStreamingResponse(client.classifications)
406-
self.rerankings = rerankings.RerankingsResourceWithStreamingResponse(client.rerankings)
407-
self.extractions = extractions.ExtractionsResourceWithStreamingResponse(client.extractions)
493+
self._client = client
494+
495+
@cached_property
496+
def embeddings(self) -> embeddings.EmbeddingsResourceWithStreamingResponse:
497+
from .resources.embeddings import EmbeddingsResourceWithStreamingResponse
498+
499+
return EmbeddingsResourceWithStreamingResponse(self._client.embeddings)
500+
501+
@cached_property
502+
def classifications(self) -> classifications.ClassificationsResourceWithStreamingResponse:
503+
from .resources.classifications import ClassificationsResourceWithStreamingResponse
504+
505+
return ClassificationsResourceWithStreamingResponse(self._client.classifications)
506+
507+
@cached_property
508+
def rerankings(self) -> rerankings.RerankingsResourceWithStreamingResponse:
509+
from .resources.rerankings import RerankingsResourceWithStreamingResponse
510+
511+
return RerankingsResourceWithStreamingResponse(self._client.rerankings)
512+
513+
@cached_property
514+
def extractions(self) -> extractions.ExtractionsResourceWithStreamingResponse:
515+
from .resources.extractions import ExtractionsResourceWithStreamingResponse
516+
517+
return ExtractionsResourceWithStreamingResponse(self._client.extractions)
408518

409519

410520
class AsyncIsaacusWithStreamedResponse:
521+
_client: AsyncIsaacus
522+
411523
def __init__(self, client: AsyncIsaacus) -> None:
412-
self.embeddings = embeddings.AsyncEmbeddingsResourceWithStreamingResponse(client.embeddings)
413-
self.classifications = classifications.AsyncClassificationsResourceWithStreamingResponse(client.classifications)
414-
self.rerankings = rerankings.AsyncRerankingsResourceWithStreamingResponse(client.rerankings)
415-
self.extractions = extractions.AsyncExtractionsResourceWithStreamingResponse(client.extractions)
524+
self._client = client
525+
526+
@cached_property
527+
def embeddings(self) -> embeddings.AsyncEmbeddingsResourceWithStreamingResponse:
528+
from .resources.embeddings import AsyncEmbeddingsResourceWithStreamingResponse
529+
530+
return AsyncEmbeddingsResourceWithStreamingResponse(self._client.embeddings)
531+
532+
@cached_property
533+
def classifications(self) -> classifications.AsyncClassificationsResourceWithStreamingResponse:
534+
from .resources.classifications import AsyncClassificationsResourceWithStreamingResponse
535+
536+
return AsyncClassificationsResourceWithStreamingResponse(self._client.classifications)
537+
538+
@cached_property
539+
def rerankings(self) -> rerankings.AsyncRerankingsResourceWithStreamingResponse:
540+
from .resources.rerankings import AsyncRerankingsResourceWithStreamingResponse
541+
542+
return AsyncRerankingsResourceWithStreamingResponse(self._client.rerankings)
543+
544+
@cached_property
545+
def extractions(self) -> extractions.AsyncExtractionsResourceWithStreamingResponse:
546+
from .resources.extractions import AsyncExtractionsResourceWithStreamingResponse
547+
548+
return AsyncExtractionsResourceWithStreamingResponse(self._client.extractions)
416549

417550

418551
Client = Isaacus

0 commit comments

Comments
 (0)