Skip to content

Commit 088bf48

Browse files
chore: speedup initial import
1 parent 8c1dda0 commit 088bf48

File tree

1 file changed

+216
-52
lines changed

1 file changed

+216
-52
lines changed

src/supermemory/_client.py

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

99
import httpx
@@ -31,14 +31,14 @@
3131
get_async_library,
3232
async_maybe_transform,
3333
)
34+
from ._compat import cached_property
3435
from ._version import __version__
3536
from ._response import (
3637
to_raw_response_wrapper,
3738
to_streamed_response_wrapper,
3839
async_to_raw_response_wrapper,
3940
async_to_streamed_response_wrapper,
4041
)
41-
from .resources import search, memories, settings, documents, connections
4242
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
4343
from ._exceptions import APIStatusError, SupermemoryError
4444
from ._base_client import (
@@ -50,6 +50,14 @@
5050
from .types.add_response import AddResponse
5151
from .types.profile_response import ProfileResponse
5252

53+
if TYPE_CHECKING:
54+
from .resources import search, memories, settings, documents, connections
55+
from .resources.search import SearchResource, AsyncSearchResource
56+
from .resources.memories import MemoriesResource, AsyncMemoriesResource
57+
from .resources.settings import SettingsResource, AsyncSettingsResource
58+
from .resources.documents import DocumentsResource, AsyncDocumentsResource
59+
from .resources.connections import ConnectionsResource, AsyncConnectionsResource
60+
5361
__all__ = [
5462
"Timeout",
5563
"Transport",
@@ -63,14 +71,6 @@
6371

6472

6573
class Supermemory(SyncAPIClient):
66-
memories: memories.MemoriesResource
67-
documents: documents.DocumentsResource
68-
search: search.SearchResource
69-
settings: settings.SettingsResource
70-
connections: connections.ConnectionsResource
71-
with_raw_response: SupermemoryWithRawResponse
72-
with_streaming_response: SupermemoryWithStreamedResponse
73-
7474
# client options
7575
api_key: str
7676

@@ -125,13 +125,43 @@ def __init__(
125125
_strict_response_validation=_strict_response_validation,
126126
)
127127

128-
self.memories = memories.MemoriesResource(self)
129-
self.documents = documents.DocumentsResource(self)
130-
self.search = search.SearchResource(self)
131-
self.settings = settings.SettingsResource(self)
132-
self.connections = connections.ConnectionsResource(self)
133-
self.with_raw_response = SupermemoryWithRawResponse(self)
134-
self.with_streaming_response = SupermemoryWithStreamedResponse(self)
128+
@cached_property
129+
def memories(self) -> MemoriesResource:
130+
from .resources.memories import MemoriesResource
131+
132+
return MemoriesResource(self)
133+
134+
@cached_property
135+
def documents(self) -> DocumentsResource:
136+
from .resources.documents import DocumentsResource
137+
138+
return DocumentsResource(self)
139+
140+
@cached_property
141+
def search(self) -> SearchResource:
142+
from .resources.search import SearchResource
143+
144+
return SearchResource(self)
145+
146+
@cached_property
147+
def settings(self) -> SettingsResource:
148+
from .resources.settings import SettingsResource
149+
150+
return SettingsResource(self)
151+
152+
@cached_property
153+
def connections(self) -> ConnectionsResource:
154+
from .resources.connections import ConnectionsResource
155+
156+
return ConnectionsResource(self)
157+
158+
@cached_property
159+
def with_raw_response(self) -> SupermemoryWithRawResponse:
160+
return SupermemoryWithRawResponse(self)
161+
162+
@cached_property
163+
def with_streaming_response(self) -> SupermemoryWithStreamedResponse:
164+
return SupermemoryWithStreamedResponse(self)
135165

136166
@property
137167
@override
@@ -339,14 +369,6 @@ def _make_status_error(
339369

340370

341371
class AsyncSupermemory(AsyncAPIClient):
342-
memories: memories.AsyncMemoriesResource
343-
documents: documents.AsyncDocumentsResource
344-
search: search.AsyncSearchResource
345-
settings: settings.AsyncSettingsResource
346-
connections: connections.AsyncConnectionsResource
347-
with_raw_response: AsyncSupermemoryWithRawResponse
348-
with_streaming_response: AsyncSupermemoryWithStreamedResponse
349-
350372
# client options
351373
api_key: str
352374

@@ -401,13 +423,43 @@ def __init__(
401423
_strict_response_validation=_strict_response_validation,
402424
)
403425

404-
self.memories = memories.AsyncMemoriesResource(self)
405-
self.documents = documents.AsyncDocumentsResource(self)
406-
self.search = search.AsyncSearchResource(self)
407-
self.settings = settings.AsyncSettingsResource(self)
408-
self.connections = connections.AsyncConnectionsResource(self)
409-
self.with_raw_response = AsyncSupermemoryWithRawResponse(self)
410-
self.with_streaming_response = AsyncSupermemoryWithStreamedResponse(self)
426+
@cached_property
427+
def memories(self) -> AsyncMemoriesResource:
428+
from .resources.memories import AsyncMemoriesResource
429+
430+
return AsyncMemoriesResource(self)
431+
432+
@cached_property
433+
def documents(self) -> AsyncDocumentsResource:
434+
from .resources.documents import AsyncDocumentsResource
435+
436+
return AsyncDocumentsResource(self)
437+
438+
@cached_property
439+
def search(self) -> AsyncSearchResource:
440+
from .resources.search import AsyncSearchResource
441+
442+
return AsyncSearchResource(self)
443+
444+
@cached_property
445+
def settings(self) -> AsyncSettingsResource:
446+
from .resources.settings import AsyncSettingsResource
447+
448+
return AsyncSettingsResource(self)
449+
450+
@cached_property
451+
def connections(self) -> AsyncConnectionsResource:
452+
from .resources.connections import AsyncConnectionsResource
453+
454+
return AsyncConnectionsResource(self)
455+
456+
@cached_property
457+
def with_raw_response(self) -> AsyncSupermemoryWithRawResponse:
458+
return AsyncSupermemoryWithRawResponse(self)
459+
460+
@cached_property
461+
def with_streaming_response(self) -> AsyncSupermemoryWithStreamedResponse:
462+
return AsyncSupermemoryWithStreamedResponse(self)
411463

412464
@property
413465
@override
@@ -615,12 +667,10 @@ def _make_status_error(
615667

616668

617669
class SupermemoryWithRawResponse:
670+
_client: Supermemory
671+
618672
def __init__(self, client: Supermemory) -> None:
619-
self.memories = memories.MemoriesResourceWithRawResponse(client.memories)
620-
self.documents = documents.DocumentsResourceWithRawResponse(client.documents)
621-
self.search = search.SearchResourceWithRawResponse(client.search)
622-
self.settings = settings.SettingsResourceWithRawResponse(client.settings)
623-
self.connections = connections.ConnectionsResourceWithRawResponse(client.connections)
673+
self._client = client
624674

625675
self.add = to_raw_response_wrapper(
626676
client.add,
@@ -629,14 +679,42 @@ def __init__(self, client: Supermemory) -> None:
629679
client.profile,
630680
)
631681

682+
@cached_property
683+
def memories(self) -> memories.MemoriesResourceWithRawResponse:
684+
from .resources.memories import MemoriesResourceWithRawResponse
685+
686+
return MemoriesResourceWithRawResponse(self._client.memories)
687+
688+
@cached_property
689+
def documents(self) -> documents.DocumentsResourceWithRawResponse:
690+
from .resources.documents import DocumentsResourceWithRawResponse
691+
692+
return DocumentsResourceWithRawResponse(self._client.documents)
693+
694+
@cached_property
695+
def search(self) -> search.SearchResourceWithRawResponse:
696+
from .resources.search import SearchResourceWithRawResponse
697+
698+
return SearchResourceWithRawResponse(self._client.search)
699+
700+
@cached_property
701+
def settings(self) -> settings.SettingsResourceWithRawResponse:
702+
from .resources.settings import SettingsResourceWithRawResponse
703+
704+
return SettingsResourceWithRawResponse(self._client.settings)
705+
706+
@cached_property
707+
def connections(self) -> connections.ConnectionsResourceWithRawResponse:
708+
from .resources.connections import ConnectionsResourceWithRawResponse
709+
710+
return ConnectionsResourceWithRawResponse(self._client.connections)
711+
632712

633713
class AsyncSupermemoryWithRawResponse:
714+
_client: AsyncSupermemory
715+
634716
def __init__(self, client: AsyncSupermemory) -> None:
635-
self.memories = memories.AsyncMemoriesResourceWithRawResponse(client.memories)
636-
self.documents = documents.AsyncDocumentsResourceWithRawResponse(client.documents)
637-
self.search = search.AsyncSearchResourceWithRawResponse(client.search)
638-
self.settings = settings.AsyncSettingsResourceWithRawResponse(client.settings)
639-
self.connections = connections.AsyncConnectionsResourceWithRawResponse(client.connections)
717+
self._client = client
640718

641719
self.add = async_to_raw_response_wrapper(
642720
client.add,
@@ -645,14 +723,42 @@ def __init__(self, client: AsyncSupermemory) -> None:
645723
client.profile,
646724
)
647725

726+
@cached_property
727+
def memories(self) -> memories.AsyncMemoriesResourceWithRawResponse:
728+
from .resources.memories import AsyncMemoriesResourceWithRawResponse
729+
730+
return AsyncMemoriesResourceWithRawResponse(self._client.memories)
731+
732+
@cached_property
733+
def documents(self) -> documents.AsyncDocumentsResourceWithRawResponse:
734+
from .resources.documents import AsyncDocumentsResourceWithRawResponse
735+
736+
return AsyncDocumentsResourceWithRawResponse(self._client.documents)
737+
738+
@cached_property
739+
def search(self) -> search.AsyncSearchResourceWithRawResponse:
740+
from .resources.search import AsyncSearchResourceWithRawResponse
741+
742+
return AsyncSearchResourceWithRawResponse(self._client.search)
743+
744+
@cached_property
745+
def settings(self) -> settings.AsyncSettingsResourceWithRawResponse:
746+
from .resources.settings import AsyncSettingsResourceWithRawResponse
747+
748+
return AsyncSettingsResourceWithRawResponse(self._client.settings)
749+
750+
@cached_property
751+
def connections(self) -> connections.AsyncConnectionsResourceWithRawResponse:
752+
from .resources.connections import AsyncConnectionsResourceWithRawResponse
753+
754+
return AsyncConnectionsResourceWithRawResponse(self._client.connections)
755+
648756

649757
class SupermemoryWithStreamedResponse:
758+
_client: Supermemory
759+
650760
def __init__(self, client: Supermemory) -> None:
651-
self.memories = memories.MemoriesResourceWithStreamingResponse(client.memories)
652-
self.documents = documents.DocumentsResourceWithStreamingResponse(client.documents)
653-
self.search = search.SearchResourceWithStreamingResponse(client.search)
654-
self.settings = settings.SettingsResourceWithStreamingResponse(client.settings)
655-
self.connections = connections.ConnectionsResourceWithStreamingResponse(client.connections)
761+
self._client = client
656762

657763
self.add = to_streamed_response_wrapper(
658764
client.add,
@@ -661,14 +767,42 @@ def __init__(self, client: Supermemory) -> None:
661767
client.profile,
662768
)
663769

770+
@cached_property
771+
def memories(self) -> memories.MemoriesResourceWithStreamingResponse:
772+
from .resources.memories import MemoriesResourceWithStreamingResponse
773+
774+
return MemoriesResourceWithStreamingResponse(self._client.memories)
775+
776+
@cached_property
777+
def documents(self) -> documents.DocumentsResourceWithStreamingResponse:
778+
from .resources.documents import DocumentsResourceWithStreamingResponse
779+
780+
return DocumentsResourceWithStreamingResponse(self._client.documents)
781+
782+
@cached_property
783+
def search(self) -> search.SearchResourceWithStreamingResponse:
784+
from .resources.search import SearchResourceWithStreamingResponse
785+
786+
return SearchResourceWithStreamingResponse(self._client.search)
787+
788+
@cached_property
789+
def settings(self) -> settings.SettingsResourceWithStreamingResponse:
790+
from .resources.settings import SettingsResourceWithStreamingResponse
791+
792+
return SettingsResourceWithStreamingResponse(self._client.settings)
793+
794+
@cached_property
795+
def connections(self) -> connections.ConnectionsResourceWithStreamingResponse:
796+
from .resources.connections import ConnectionsResourceWithStreamingResponse
797+
798+
return ConnectionsResourceWithStreamingResponse(self._client.connections)
799+
664800

665801
class AsyncSupermemoryWithStreamedResponse:
802+
_client: AsyncSupermemory
803+
666804
def __init__(self, client: AsyncSupermemory) -> None:
667-
self.memories = memories.AsyncMemoriesResourceWithStreamingResponse(client.memories)
668-
self.documents = documents.AsyncDocumentsResourceWithStreamingResponse(client.documents)
669-
self.search = search.AsyncSearchResourceWithStreamingResponse(client.search)
670-
self.settings = settings.AsyncSettingsResourceWithStreamingResponse(client.settings)
671-
self.connections = connections.AsyncConnectionsResourceWithStreamingResponse(client.connections)
805+
self._client = client
672806

673807
self.add = async_to_streamed_response_wrapper(
674808
client.add,
@@ -677,6 +811,36 @@ def __init__(self, client: AsyncSupermemory) -> None:
677811
client.profile,
678812
)
679813

814+
@cached_property
815+
def memories(self) -> memories.AsyncMemoriesResourceWithStreamingResponse:
816+
from .resources.memories import AsyncMemoriesResourceWithStreamingResponse
817+
818+
return AsyncMemoriesResourceWithStreamingResponse(self._client.memories)
819+
820+
@cached_property
821+
def documents(self) -> documents.AsyncDocumentsResourceWithStreamingResponse:
822+
from .resources.documents import AsyncDocumentsResourceWithStreamingResponse
823+
824+
return AsyncDocumentsResourceWithStreamingResponse(self._client.documents)
825+
826+
@cached_property
827+
def search(self) -> search.AsyncSearchResourceWithStreamingResponse:
828+
from .resources.search import AsyncSearchResourceWithStreamingResponse
829+
830+
return AsyncSearchResourceWithStreamingResponse(self._client.search)
831+
832+
@cached_property
833+
def settings(self) -> settings.AsyncSettingsResourceWithStreamingResponse:
834+
from .resources.settings import AsyncSettingsResourceWithStreamingResponse
835+
836+
return AsyncSettingsResourceWithStreamingResponse(self._client.settings)
837+
838+
@cached_property
839+
def connections(self) -> connections.AsyncConnectionsResourceWithStreamingResponse:
840+
from .resources.connections import AsyncConnectionsResourceWithStreamingResponse
841+
842+
return AsyncConnectionsResourceWithStreamingResponse(self._client.connections)
843+
680844

681845
Client = Supermemory
682846

0 commit comments

Comments
 (0)