Skip to content

Commit c6fa047

Browse files
chore: speedup initial import
1 parent 041d054 commit c6fa047

File tree

1 file changed

+68
-20
lines changed

1 file changed

+68
-20
lines changed

src/warp_sdk/_client.py

Lines changed: 68 additions & 20 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,6 +20,7 @@
2020
not_given,
2121
)
2222
from ._utils import is_given, get_async_library
23+
from ._compat import cached_property
2324
from ._version import __version__
2425
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2526
from ._exceptions import WarpAPIError, APIStatusError
@@ -28,16 +29,15 @@
2829
SyncAPIClient,
2930
AsyncAPIClient,
3031
)
31-
from .resources.agent import agent
32+
33+
if TYPE_CHECKING:
34+
from .resources import agent
35+
from .resources.agent.agent import AgentResource, AsyncAgentResource
3236

3337
__all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "WarpAPI", "AsyncWarpAPI", "Client", "AsyncClient"]
3438

3539

3640
class WarpAPI(SyncAPIClient):
37-
agent: agent.AgentResource
38-
with_raw_response: WarpAPIWithRawResponse
39-
with_streaming_response: WarpAPIWithStreamedResponse
40-
4141
# client options
4242
api_key: str
4343

@@ -92,9 +92,19 @@ def __init__(
9292
_strict_response_validation=_strict_response_validation,
9393
)
9494

95-
self.agent = agent.AgentResource(self)
96-
self.with_raw_response = WarpAPIWithRawResponse(self)
97-
self.with_streaming_response = WarpAPIWithStreamedResponse(self)
95+
@cached_property
96+
def agent(self) -> AgentResource:
97+
from .resources.agent import AgentResource
98+
99+
return AgentResource(self)
100+
101+
@cached_property
102+
def with_raw_response(self) -> WarpAPIWithRawResponse:
103+
return WarpAPIWithRawResponse(self)
104+
105+
@cached_property
106+
def with_streaming_response(self) -> WarpAPIWithStreamedResponse:
107+
return WarpAPIWithStreamedResponse(self)
98108

99109
@property
100110
@override
@@ -202,10 +212,6 @@ def _make_status_error(
202212

203213

204214
class AsyncWarpAPI(AsyncAPIClient):
205-
agent: agent.AsyncAgentResource
206-
with_raw_response: AsyncWarpAPIWithRawResponse
207-
with_streaming_response: AsyncWarpAPIWithStreamedResponse
208-
209215
# client options
210216
api_key: str
211217

@@ -260,9 +266,19 @@ def __init__(
260266
_strict_response_validation=_strict_response_validation,
261267
)
262268

263-
self.agent = agent.AsyncAgentResource(self)
264-
self.with_raw_response = AsyncWarpAPIWithRawResponse(self)
265-
self.with_streaming_response = AsyncWarpAPIWithStreamedResponse(self)
269+
@cached_property
270+
def agent(self) -> AsyncAgentResource:
271+
from .resources.agent import AsyncAgentResource
272+
273+
return AsyncAgentResource(self)
274+
275+
@cached_property
276+
def with_raw_response(self) -> AsyncWarpAPIWithRawResponse:
277+
return AsyncWarpAPIWithRawResponse(self)
278+
279+
@cached_property
280+
def with_streaming_response(self) -> AsyncWarpAPIWithStreamedResponse:
281+
return AsyncWarpAPIWithStreamedResponse(self)
266282

267283
@property
268284
@override
@@ -370,23 +386,55 @@ def _make_status_error(
370386

371387

372388
class WarpAPIWithRawResponse:
389+
_client: WarpAPI
390+
373391
def __init__(self, client: WarpAPI) -> None:
374-
self.agent = agent.AgentResourceWithRawResponse(client.agent)
392+
self._client = client
393+
394+
@cached_property
395+
def agent(self) -> agent.AgentResourceWithRawResponse:
396+
from .resources.agent import AgentResourceWithRawResponse
397+
398+
return AgentResourceWithRawResponse(self._client.agent)
375399

376400

377401
class AsyncWarpAPIWithRawResponse:
402+
_client: AsyncWarpAPI
403+
378404
def __init__(self, client: AsyncWarpAPI) -> None:
379-
self.agent = agent.AsyncAgentResourceWithRawResponse(client.agent)
405+
self._client = client
406+
407+
@cached_property
408+
def agent(self) -> agent.AsyncAgentResourceWithRawResponse:
409+
from .resources.agent import AsyncAgentResourceWithRawResponse
410+
411+
return AsyncAgentResourceWithRawResponse(self._client.agent)
380412

381413

382414
class WarpAPIWithStreamedResponse:
415+
_client: WarpAPI
416+
383417
def __init__(self, client: WarpAPI) -> None:
384-
self.agent = agent.AgentResourceWithStreamingResponse(client.agent)
418+
self._client = client
419+
420+
@cached_property
421+
def agent(self) -> agent.AgentResourceWithStreamingResponse:
422+
from .resources.agent import AgentResourceWithStreamingResponse
423+
424+
return AgentResourceWithStreamingResponse(self._client.agent)
385425

386426

387427
class AsyncWarpAPIWithStreamedResponse:
428+
_client: AsyncWarpAPI
429+
388430
def __init__(self, client: AsyncWarpAPI) -> None:
389-
self.agent = agent.AsyncAgentResourceWithStreamingResponse(client.agent)
431+
self._client = client
432+
433+
@cached_property
434+
def agent(self) -> agent.AsyncAgentResourceWithStreamingResponse:
435+
from .resources.agent import AsyncAgentResourceWithStreamingResponse
436+
437+
return AsyncAgentResourceWithStreamingResponse(self._client.agent)
390438

391439

392440
Client = WarpAPI

0 commit comments

Comments
 (0)