|
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 |
|
21 | 21 | not_given, |
22 | 22 | ) |
23 | 23 | from ._utils import is_given, get_async_library |
| 24 | +from ._compat import cached_property |
24 | 25 | from ._version import __version__ |
25 | 26 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
26 | 27 | from ._exceptions import APIStatusError |
|
29 | 30 | SyncAPIClient, |
30 | 31 | AsyncAPIClient, |
31 | 32 | ) |
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 | + ) |
36 | 43 |
|
37 | 44 | __all__ = [ |
38 | 45 | "Timeout", |
|
47 | 54 |
|
48 | 55 |
|
49 | 56 | 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 | | - |
57 | 57 | # client options |
58 | 58 | api_key: str | None |
59 | 59 |
|
@@ -104,12 +104,37 @@ def __init__( |
104 | 104 | _strict_response_validation=_strict_response_validation, |
105 | 105 | ) |
106 | 106 |
|
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) |
113 | 138 |
|
114 | 139 | @property |
115 | 140 | @override |
@@ -230,13 +255,6 @@ def _make_status_error( |
230 | 255 |
|
231 | 256 |
|
232 | 257 | 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 | | - |
240 | 258 | # client options |
241 | 259 | api_key: str | None |
242 | 260 |
|
@@ -287,12 +305,37 @@ def __init__( |
287 | 305 | _strict_response_validation=_strict_response_validation, |
288 | 306 | ) |
289 | 307 |
|
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) |
296 | 339 |
|
297 | 340 | @property |
298 | 341 | @override |
@@ -413,43 +456,127 @@ def _make_status_error( |
413 | 456 |
|
414 | 457 |
|
415 | 458 | class OpenlayerWithRawResponse: |
| 459 | + _client: Openlayer |
| 460 | + |
416 | 461 | 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) |
423 | 487 |
|
424 | 488 |
|
425 | 489 | class AsyncOpenlayerWithRawResponse: |
| 490 | + _client: AsyncOpenlayer |
| 491 | + |
426 | 492 | 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) |
433 | 518 |
|
434 | 519 |
|
435 | 520 | class OpenlayerWithStreamedResponse: |
| 521 | + _client: Openlayer |
| 522 | + |
436 | 523 | 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) |
443 | 549 |
|
444 | 550 |
|
445 | 551 | class AsyncOpenlayerWithStreamedResponse: |
| 552 | + _client: AsyncOpenlayer |
| 553 | + |
446 | 554 | 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) |
453 | 580 |
|
454 | 581 |
|
455 | 582 | Client = Openlayer |
|
0 commit comments