Skip to content

Commit f8b2fd2

Browse files
chore: speedup initial import
1 parent 7aa26f5 commit f8b2fd2

File tree

1 file changed

+182
-55
lines changed

1 file changed

+182
-55
lines changed

src/openlayer/_client.py

Lines changed: 182 additions & 55 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
@@ -21,6 +21,7 @@
2121
not_given,
2222
)
2323
from ._utils import is_given, get_async_library
24+
from ._compat import cached_property
2425
from ._version import __version__
2526
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2627
from ._exceptions import APIStatusError
@@ -29,10 +30,16 @@
2930
SyncAPIClient,
3031
AsyncAPIClient,
3132
)
32-
from .resources.commits import commits
33-
from .resources.storage import storage
34-
from .resources.projects import projects
35-
from .resources.inference_pipelines import inference_pipelines
33+
34+
if TYPE_CHECKING:
35+
from .resources import commits, storage, projects, inference_pipelines
36+
from .resources.commits.commits import CommitsResource, AsyncCommitsResource
37+
from .resources.storage.storage import StorageResource, AsyncStorageResource
38+
from .resources.projects.projects import ProjectsResource, AsyncProjectsResource
39+
from .resources.inference_pipelines.inference_pipelines import (
40+
InferencePipelinesResource,
41+
AsyncInferencePipelinesResource,
42+
)
3643

3744
__all__ = [
3845
"Timeout",
@@ -47,13 +54,6 @@
4754

4855

4956
class Openlayer(SyncAPIClient):
50-
projects: projects.ProjectsResource
51-
commits: commits.CommitsResource
52-
inference_pipelines: inference_pipelines.InferencePipelinesResource
53-
storage: storage.StorageResource
54-
with_raw_response: OpenlayerWithRawResponse
55-
with_streaming_response: OpenlayerWithStreamedResponse
56-
5757
# client options
5858
api_key: str | None
5959

@@ -104,12 +104,37 @@ def __init__(
104104
_strict_response_validation=_strict_response_validation,
105105
)
106106

107-
self.projects = projects.ProjectsResource(self)
108-
self.commits = commits.CommitsResource(self)
109-
self.inference_pipelines = inference_pipelines.InferencePipelinesResource(self)
110-
self.storage = storage.StorageResource(self)
111-
self.with_raw_response = OpenlayerWithRawResponse(self)
112-
self.with_streaming_response = OpenlayerWithStreamedResponse(self)
107+
@cached_property
108+
def projects(self) -> ProjectsResource:
109+
from .resources.projects import ProjectsResource
110+
111+
return ProjectsResource(self)
112+
113+
@cached_property
114+
def commits(self) -> CommitsResource:
115+
from .resources.commits import CommitsResource
116+
117+
return CommitsResource(self)
118+
119+
@cached_property
120+
def inference_pipelines(self) -> InferencePipelinesResource:
121+
from .resources.inference_pipelines import InferencePipelinesResource
122+
123+
return InferencePipelinesResource(self)
124+
125+
@cached_property
126+
def storage(self) -> StorageResource:
127+
from .resources.storage import StorageResource
128+
129+
return StorageResource(self)
130+
131+
@cached_property
132+
def with_raw_response(self) -> OpenlayerWithRawResponse:
133+
return OpenlayerWithRawResponse(self)
134+
135+
@cached_property
136+
def with_streaming_response(self) -> OpenlayerWithStreamedResponse:
137+
return OpenlayerWithStreamedResponse(self)
113138

114139
@property
115140
@override
@@ -230,13 +255,6 @@ def _make_status_error(
230255

231256

232257
class AsyncOpenlayer(AsyncAPIClient):
233-
projects: projects.AsyncProjectsResource
234-
commits: commits.AsyncCommitsResource
235-
inference_pipelines: inference_pipelines.AsyncInferencePipelinesResource
236-
storage: storage.AsyncStorageResource
237-
with_raw_response: AsyncOpenlayerWithRawResponse
238-
with_streaming_response: AsyncOpenlayerWithStreamedResponse
239-
240258
# client options
241259
api_key: str | None
242260

@@ -287,12 +305,37 @@ def __init__(
287305
_strict_response_validation=_strict_response_validation,
288306
)
289307

290-
self.projects = projects.AsyncProjectsResource(self)
291-
self.commits = commits.AsyncCommitsResource(self)
292-
self.inference_pipelines = inference_pipelines.AsyncInferencePipelinesResource(self)
293-
self.storage = storage.AsyncStorageResource(self)
294-
self.with_raw_response = AsyncOpenlayerWithRawResponse(self)
295-
self.with_streaming_response = AsyncOpenlayerWithStreamedResponse(self)
308+
@cached_property
309+
def projects(self) -> AsyncProjectsResource:
310+
from .resources.projects import AsyncProjectsResource
311+
312+
return AsyncProjectsResource(self)
313+
314+
@cached_property
315+
def commits(self) -> AsyncCommitsResource:
316+
from .resources.commits import AsyncCommitsResource
317+
318+
return AsyncCommitsResource(self)
319+
320+
@cached_property
321+
def inference_pipelines(self) -> AsyncInferencePipelinesResource:
322+
from .resources.inference_pipelines import AsyncInferencePipelinesResource
323+
324+
return AsyncInferencePipelinesResource(self)
325+
326+
@cached_property
327+
def storage(self) -> AsyncStorageResource:
328+
from .resources.storage import AsyncStorageResource
329+
330+
return AsyncStorageResource(self)
331+
332+
@cached_property
333+
def with_raw_response(self) -> AsyncOpenlayerWithRawResponse:
334+
return AsyncOpenlayerWithRawResponse(self)
335+
336+
@cached_property
337+
def with_streaming_response(self) -> AsyncOpenlayerWithStreamedResponse:
338+
return AsyncOpenlayerWithStreamedResponse(self)
296339

297340
@property
298341
@override
@@ -413,43 +456,127 @@ def _make_status_error(
413456

414457

415458
class OpenlayerWithRawResponse:
459+
_client: Openlayer
460+
416461
def __init__(self, client: Openlayer) -> None:
417-
self.projects = projects.ProjectsResourceWithRawResponse(client.projects)
418-
self.commits = commits.CommitsResourceWithRawResponse(client.commits)
419-
self.inference_pipelines = inference_pipelines.InferencePipelinesResourceWithRawResponse(
420-
client.inference_pipelines
421-
)
422-
self.storage = storage.StorageResourceWithRawResponse(client.storage)
462+
self._client = client
463+
464+
@cached_property
465+
def projects(self) -> projects.ProjectsResourceWithRawResponse:
466+
from .resources.projects import ProjectsResourceWithRawResponse
467+
468+
return ProjectsResourceWithRawResponse(self._client.projects)
469+
470+
@cached_property
471+
def commits(self) -> commits.CommitsResourceWithRawResponse:
472+
from .resources.commits import CommitsResourceWithRawResponse
473+
474+
return CommitsResourceWithRawResponse(self._client.commits)
475+
476+
@cached_property
477+
def inference_pipelines(self) -> inference_pipelines.InferencePipelinesResourceWithRawResponse:
478+
from .resources.inference_pipelines import InferencePipelinesResourceWithRawResponse
479+
480+
return InferencePipelinesResourceWithRawResponse(self._client.inference_pipelines)
481+
482+
@cached_property
483+
def storage(self) -> storage.StorageResourceWithRawResponse:
484+
from .resources.storage import StorageResourceWithRawResponse
485+
486+
return StorageResourceWithRawResponse(self._client.storage)
423487

424488

425489
class AsyncOpenlayerWithRawResponse:
490+
_client: AsyncOpenlayer
491+
426492
def __init__(self, client: AsyncOpenlayer) -> None:
427-
self.projects = projects.AsyncProjectsResourceWithRawResponse(client.projects)
428-
self.commits = commits.AsyncCommitsResourceWithRawResponse(client.commits)
429-
self.inference_pipelines = inference_pipelines.AsyncInferencePipelinesResourceWithRawResponse(
430-
client.inference_pipelines
431-
)
432-
self.storage = storage.AsyncStorageResourceWithRawResponse(client.storage)
493+
self._client = client
494+
495+
@cached_property
496+
def projects(self) -> projects.AsyncProjectsResourceWithRawResponse:
497+
from .resources.projects import AsyncProjectsResourceWithRawResponse
498+
499+
return AsyncProjectsResourceWithRawResponse(self._client.projects)
500+
501+
@cached_property
502+
def commits(self) -> commits.AsyncCommitsResourceWithRawResponse:
503+
from .resources.commits import AsyncCommitsResourceWithRawResponse
504+
505+
return AsyncCommitsResourceWithRawResponse(self._client.commits)
506+
507+
@cached_property
508+
def inference_pipelines(self) -> inference_pipelines.AsyncInferencePipelinesResourceWithRawResponse:
509+
from .resources.inference_pipelines import AsyncInferencePipelinesResourceWithRawResponse
510+
511+
return AsyncInferencePipelinesResourceWithRawResponse(self._client.inference_pipelines)
512+
513+
@cached_property
514+
def storage(self) -> storage.AsyncStorageResourceWithRawResponse:
515+
from .resources.storage import AsyncStorageResourceWithRawResponse
516+
517+
return AsyncStorageResourceWithRawResponse(self._client.storage)
433518

434519

435520
class OpenlayerWithStreamedResponse:
521+
_client: Openlayer
522+
436523
def __init__(self, client: Openlayer) -> None:
437-
self.projects = projects.ProjectsResourceWithStreamingResponse(client.projects)
438-
self.commits = commits.CommitsResourceWithStreamingResponse(client.commits)
439-
self.inference_pipelines = inference_pipelines.InferencePipelinesResourceWithStreamingResponse(
440-
client.inference_pipelines
441-
)
442-
self.storage = storage.StorageResourceWithStreamingResponse(client.storage)
524+
self._client = client
525+
526+
@cached_property
527+
def projects(self) -> projects.ProjectsResourceWithStreamingResponse:
528+
from .resources.projects import ProjectsResourceWithStreamingResponse
529+
530+
return ProjectsResourceWithStreamingResponse(self._client.projects)
531+
532+
@cached_property
533+
def commits(self) -> commits.CommitsResourceWithStreamingResponse:
534+
from .resources.commits import CommitsResourceWithStreamingResponse
535+
536+
return CommitsResourceWithStreamingResponse(self._client.commits)
537+
538+
@cached_property
539+
def inference_pipelines(self) -> inference_pipelines.InferencePipelinesResourceWithStreamingResponse:
540+
from .resources.inference_pipelines import InferencePipelinesResourceWithStreamingResponse
541+
542+
return InferencePipelinesResourceWithStreamingResponse(self._client.inference_pipelines)
543+
544+
@cached_property
545+
def storage(self) -> storage.StorageResourceWithStreamingResponse:
546+
from .resources.storage import StorageResourceWithStreamingResponse
547+
548+
return StorageResourceWithStreamingResponse(self._client.storage)
443549

444550

445551
class AsyncOpenlayerWithStreamedResponse:
552+
_client: AsyncOpenlayer
553+
446554
def __init__(self, client: AsyncOpenlayer) -> None:
447-
self.projects = projects.AsyncProjectsResourceWithStreamingResponse(client.projects)
448-
self.commits = commits.AsyncCommitsResourceWithStreamingResponse(client.commits)
449-
self.inference_pipelines = inference_pipelines.AsyncInferencePipelinesResourceWithStreamingResponse(
450-
client.inference_pipelines
451-
)
452-
self.storage = storage.AsyncStorageResourceWithStreamingResponse(client.storage)
555+
self._client = client
556+
557+
@cached_property
558+
def projects(self) -> projects.AsyncProjectsResourceWithStreamingResponse:
559+
from .resources.projects import AsyncProjectsResourceWithStreamingResponse
560+
561+
return AsyncProjectsResourceWithStreamingResponse(self._client.projects)
562+
563+
@cached_property
564+
def commits(self) -> commits.AsyncCommitsResourceWithStreamingResponse:
565+
from .resources.commits import AsyncCommitsResourceWithStreamingResponse
566+
567+
return AsyncCommitsResourceWithStreamingResponse(self._client.commits)
568+
569+
@cached_property
570+
def inference_pipelines(self) -> inference_pipelines.AsyncInferencePipelinesResourceWithStreamingResponse:
571+
from .resources.inference_pipelines import AsyncInferencePipelinesResourceWithStreamingResponse
572+
573+
return AsyncInferencePipelinesResourceWithStreamingResponse(self._client.inference_pipelines)
574+
575+
@cached_property
576+
def storage(self) -> storage.AsyncStorageResourceWithStreamingResponse:
577+
from .resources.storage import AsyncStorageResourceWithStreamingResponse
578+
579+
return AsyncStorageResourceWithStreamingResponse(self._client.storage)
453580

454581

455582
Client = Openlayer

0 commit comments

Comments
 (0)