Skip to content

Commit cb228f5

Browse files
chore: speedup initial import
1 parent 92b8e72 commit cb228f5

1 file changed

Lines changed: 216 additions & 53 deletions

File tree

src/steel/_client.py

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

99
import httpx
@@ -30,14 +30,14 @@
3030
get_async_library,
3131
async_maybe_transform,
3232
)
33+
from ._compat import cached_property
3334
from ._version import __version__
3435
from ._response import (
3536
to_raw_response_wrapper,
3637
to_streamed_response_wrapper,
3738
async_to_raw_response_wrapper,
3839
async_to_streamed_response_wrapper,
3940
)
40-
from .resources import files, profiles, extensions, credentials
4141
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
4242
from ._exceptions import APIStatusError
4343
from ._base_client import (
@@ -46,23 +46,22 @@
4646
AsyncAPIClient,
4747
make_request_options,
4848
)
49-
from .resources.sessions import sessions
5049
from .types.pdf_response import PdfResponse
5150
from .types.scrape_response import ScrapeResponse
5251
from .types.screenshot_response import ScreenshotResponse
5352

53+
if TYPE_CHECKING:
54+
from .resources import files, profiles, sessions, extensions, credentials
55+
from .resources.files import FilesResource, AsyncFilesResource
56+
from .resources.profiles import ProfilesResource, AsyncProfilesResource
57+
from .resources.extensions import ExtensionsResource, AsyncExtensionsResource
58+
from .resources.credentials import CredentialsResource, AsyncCredentialsResource
59+
from .resources.sessions.sessions import SessionsResource, AsyncSessionsResource
60+
5461
__all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Steel", "AsyncSteel", "Client", "AsyncClient"]
5562

5663

5764
class Steel(SyncAPIClient):
58-
credentials: credentials.CredentialsResource
59-
files: files.FilesResource
60-
sessions: sessions.SessionsResource
61-
extensions: extensions.ExtensionsResource
62-
profiles: profiles.ProfilesResource
63-
with_raw_response: SteelWithRawResponse
64-
with_streaming_response: SteelWithStreamedResponse
65-
6665
# client options
6766
steel_api_key: str | None
6867

@@ -113,13 +112,43 @@ def __init__(
113112
_strict_response_validation=_strict_response_validation,
114113
)
115114

116-
self.credentials = credentials.CredentialsResource(self)
117-
self.files = files.FilesResource(self)
118-
self.sessions = sessions.SessionsResource(self)
119-
self.extensions = extensions.ExtensionsResource(self)
120-
self.profiles = profiles.ProfilesResource(self)
121-
self.with_raw_response = SteelWithRawResponse(self)
122-
self.with_streaming_response = SteelWithStreamedResponse(self)
115+
@cached_property
116+
def credentials(self) -> CredentialsResource:
117+
from .resources.credentials import CredentialsResource
118+
119+
return CredentialsResource(self)
120+
121+
@cached_property
122+
def files(self) -> FilesResource:
123+
from .resources.files import FilesResource
124+
125+
return FilesResource(self)
126+
127+
@cached_property
128+
def sessions(self) -> SessionsResource:
129+
from .resources.sessions import SessionsResource
130+
131+
return SessionsResource(self)
132+
133+
@cached_property
134+
def extensions(self) -> ExtensionsResource:
135+
from .resources.extensions import ExtensionsResource
136+
137+
return ExtensionsResource(self)
138+
139+
@cached_property
140+
def profiles(self) -> ProfilesResource:
141+
from .resources.profiles import ProfilesResource
142+
143+
return ProfilesResource(self)
144+
145+
@cached_property
146+
def with_raw_response(self) -> SteelWithRawResponse:
147+
return SteelWithRawResponse(self)
148+
149+
@cached_property
150+
def with_streaming_response(self) -> SteelWithStreamedResponse:
151+
return SteelWithStreamedResponse(self)
123152

124153
@property
125154
@override
@@ -398,14 +427,6 @@ def _make_status_error(
398427

399428

400429
class AsyncSteel(AsyncAPIClient):
401-
credentials: credentials.AsyncCredentialsResource
402-
files: files.AsyncFilesResource
403-
sessions: sessions.AsyncSessionsResource
404-
extensions: extensions.AsyncExtensionsResource
405-
profiles: profiles.AsyncProfilesResource
406-
with_raw_response: AsyncSteelWithRawResponse
407-
with_streaming_response: AsyncSteelWithStreamedResponse
408-
409430
# client options
410431
steel_api_key: str | None
411432

@@ -456,13 +477,43 @@ def __init__(
456477
_strict_response_validation=_strict_response_validation,
457478
)
458479

459-
self.credentials = credentials.AsyncCredentialsResource(self)
460-
self.files = files.AsyncFilesResource(self)
461-
self.sessions = sessions.AsyncSessionsResource(self)
462-
self.extensions = extensions.AsyncExtensionsResource(self)
463-
self.profiles = profiles.AsyncProfilesResource(self)
464-
self.with_raw_response = AsyncSteelWithRawResponse(self)
465-
self.with_streaming_response = AsyncSteelWithStreamedResponse(self)
480+
@cached_property
481+
def credentials(self) -> AsyncCredentialsResource:
482+
from .resources.credentials import AsyncCredentialsResource
483+
484+
return AsyncCredentialsResource(self)
485+
486+
@cached_property
487+
def files(self) -> AsyncFilesResource:
488+
from .resources.files import AsyncFilesResource
489+
490+
return AsyncFilesResource(self)
491+
492+
@cached_property
493+
def sessions(self) -> AsyncSessionsResource:
494+
from .resources.sessions import AsyncSessionsResource
495+
496+
return AsyncSessionsResource(self)
497+
498+
@cached_property
499+
def extensions(self) -> AsyncExtensionsResource:
500+
from .resources.extensions import AsyncExtensionsResource
501+
502+
return AsyncExtensionsResource(self)
503+
504+
@cached_property
505+
def profiles(self) -> AsyncProfilesResource:
506+
from .resources.profiles import AsyncProfilesResource
507+
508+
return AsyncProfilesResource(self)
509+
510+
@cached_property
511+
def with_raw_response(self) -> AsyncSteelWithRawResponse:
512+
return AsyncSteelWithRawResponse(self)
513+
514+
@cached_property
515+
def with_streaming_response(self) -> AsyncSteelWithStreamedResponse:
516+
return AsyncSteelWithStreamedResponse(self)
466517

467518
@property
468519
@override
@@ -741,12 +792,10 @@ def _make_status_error(
741792

742793

743794
class SteelWithRawResponse:
795+
_client: Steel
796+
744797
def __init__(self, client: Steel) -> None:
745-
self.credentials = credentials.CredentialsResourceWithRawResponse(client.credentials)
746-
self.files = files.FilesResourceWithRawResponse(client.files)
747-
self.sessions = sessions.SessionsResourceWithRawResponse(client.sessions)
748-
self.extensions = extensions.ExtensionsResourceWithRawResponse(client.extensions)
749-
self.profiles = profiles.ProfilesResourceWithRawResponse(client.profiles)
798+
self._client = client
750799

751800
self.pdf = to_raw_response_wrapper(
752801
client.pdf,
@@ -758,14 +807,42 @@ def __init__(self, client: Steel) -> None:
758807
client.screenshot,
759808
)
760809

810+
@cached_property
811+
def credentials(self) -> credentials.CredentialsResourceWithRawResponse:
812+
from .resources.credentials import CredentialsResourceWithRawResponse
813+
814+
return CredentialsResourceWithRawResponse(self._client.credentials)
815+
816+
@cached_property
817+
def files(self) -> files.FilesResourceWithRawResponse:
818+
from .resources.files import FilesResourceWithRawResponse
819+
820+
return FilesResourceWithRawResponse(self._client.files)
821+
822+
@cached_property
823+
def sessions(self) -> sessions.SessionsResourceWithRawResponse:
824+
from .resources.sessions import SessionsResourceWithRawResponse
825+
826+
return SessionsResourceWithRawResponse(self._client.sessions)
827+
828+
@cached_property
829+
def extensions(self) -> extensions.ExtensionsResourceWithRawResponse:
830+
from .resources.extensions import ExtensionsResourceWithRawResponse
831+
832+
return ExtensionsResourceWithRawResponse(self._client.extensions)
833+
834+
@cached_property
835+
def profiles(self) -> profiles.ProfilesResourceWithRawResponse:
836+
from .resources.profiles import ProfilesResourceWithRawResponse
837+
838+
return ProfilesResourceWithRawResponse(self._client.profiles)
839+
761840

762841
class AsyncSteelWithRawResponse:
842+
_client: AsyncSteel
843+
763844
def __init__(self, client: AsyncSteel) -> None:
764-
self.credentials = credentials.AsyncCredentialsResourceWithRawResponse(client.credentials)
765-
self.files = files.AsyncFilesResourceWithRawResponse(client.files)
766-
self.sessions = sessions.AsyncSessionsResourceWithRawResponse(client.sessions)
767-
self.extensions = extensions.AsyncExtensionsResourceWithRawResponse(client.extensions)
768-
self.profiles = profiles.AsyncProfilesResourceWithRawResponse(client.profiles)
845+
self._client = client
769846

770847
self.pdf = async_to_raw_response_wrapper(
771848
client.pdf,
@@ -777,14 +854,42 @@ def __init__(self, client: AsyncSteel) -> None:
777854
client.screenshot,
778855
)
779856

857+
@cached_property
858+
def credentials(self) -> credentials.AsyncCredentialsResourceWithRawResponse:
859+
from .resources.credentials import AsyncCredentialsResourceWithRawResponse
860+
861+
return AsyncCredentialsResourceWithRawResponse(self._client.credentials)
862+
863+
@cached_property
864+
def files(self) -> files.AsyncFilesResourceWithRawResponse:
865+
from .resources.files import AsyncFilesResourceWithRawResponse
866+
867+
return AsyncFilesResourceWithRawResponse(self._client.files)
868+
869+
@cached_property
870+
def sessions(self) -> sessions.AsyncSessionsResourceWithRawResponse:
871+
from .resources.sessions import AsyncSessionsResourceWithRawResponse
872+
873+
return AsyncSessionsResourceWithRawResponse(self._client.sessions)
874+
875+
@cached_property
876+
def extensions(self) -> extensions.AsyncExtensionsResourceWithRawResponse:
877+
from .resources.extensions import AsyncExtensionsResourceWithRawResponse
878+
879+
return AsyncExtensionsResourceWithRawResponse(self._client.extensions)
880+
881+
@cached_property
882+
def profiles(self) -> profiles.AsyncProfilesResourceWithRawResponse:
883+
from .resources.profiles import AsyncProfilesResourceWithRawResponse
884+
885+
return AsyncProfilesResourceWithRawResponse(self._client.profiles)
886+
780887

781888
class SteelWithStreamedResponse:
889+
_client: Steel
890+
782891
def __init__(self, client: Steel) -> None:
783-
self.credentials = credentials.CredentialsResourceWithStreamingResponse(client.credentials)
784-
self.files = files.FilesResourceWithStreamingResponse(client.files)
785-
self.sessions = sessions.SessionsResourceWithStreamingResponse(client.sessions)
786-
self.extensions = extensions.ExtensionsResourceWithStreamingResponse(client.extensions)
787-
self.profiles = profiles.ProfilesResourceWithStreamingResponse(client.profiles)
892+
self._client = client
788893

789894
self.pdf = to_streamed_response_wrapper(
790895
client.pdf,
@@ -796,14 +901,42 @@ def __init__(self, client: Steel) -> None:
796901
client.screenshot,
797902
)
798903

904+
@cached_property
905+
def credentials(self) -> credentials.CredentialsResourceWithStreamingResponse:
906+
from .resources.credentials import CredentialsResourceWithStreamingResponse
907+
908+
return CredentialsResourceWithStreamingResponse(self._client.credentials)
909+
910+
@cached_property
911+
def files(self) -> files.FilesResourceWithStreamingResponse:
912+
from .resources.files import FilesResourceWithStreamingResponse
913+
914+
return FilesResourceWithStreamingResponse(self._client.files)
915+
916+
@cached_property
917+
def sessions(self) -> sessions.SessionsResourceWithStreamingResponse:
918+
from .resources.sessions import SessionsResourceWithStreamingResponse
919+
920+
return SessionsResourceWithStreamingResponse(self._client.sessions)
921+
922+
@cached_property
923+
def extensions(self) -> extensions.ExtensionsResourceWithStreamingResponse:
924+
from .resources.extensions import ExtensionsResourceWithStreamingResponse
925+
926+
return ExtensionsResourceWithStreamingResponse(self._client.extensions)
927+
928+
@cached_property
929+
def profiles(self) -> profiles.ProfilesResourceWithStreamingResponse:
930+
from .resources.profiles import ProfilesResourceWithStreamingResponse
931+
932+
return ProfilesResourceWithStreamingResponse(self._client.profiles)
933+
799934

800935
class AsyncSteelWithStreamedResponse:
936+
_client: AsyncSteel
937+
801938
def __init__(self, client: AsyncSteel) -> None:
802-
self.credentials = credentials.AsyncCredentialsResourceWithStreamingResponse(client.credentials)
803-
self.files = files.AsyncFilesResourceWithStreamingResponse(client.files)
804-
self.sessions = sessions.AsyncSessionsResourceWithStreamingResponse(client.sessions)
805-
self.extensions = extensions.AsyncExtensionsResourceWithStreamingResponse(client.extensions)
806-
self.profiles = profiles.AsyncProfilesResourceWithStreamingResponse(client.profiles)
939+
self._client = client
807940

808941
self.pdf = async_to_streamed_response_wrapper(
809942
client.pdf,
@@ -815,6 +948,36 @@ def __init__(self, client: AsyncSteel) -> None:
815948
client.screenshot,
816949
)
817950

951+
@cached_property
952+
def credentials(self) -> credentials.AsyncCredentialsResourceWithStreamingResponse:
953+
from .resources.credentials import AsyncCredentialsResourceWithStreamingResponse
954+
955+
return AsyncCredentialsResourceWithStreamingResponse(self._client.credentials)
956+
957+
@cached_property
958+
def files(self) -> files.AsyncFilesResourceWithStreamingResponse:
959+
from .resources.files import AsyncFilesResourceWithStreamingResponse
960+
961+
return AsyncFilesResourceWithStreamingResponse(self._client.files)
962+
963+
@cached_property
964+
def sessions(self) -> sessions.AsyncSessionsResourceWithStreamingResponse:
965+
from .resources.sessions import AsyncSessionsResourceWithStreamingResponse
966+
967+
return AsyncSessionsResourceWithStreamingResponse(self._client.sessions)
968+
969+
@cached_property
970+
def extensions(self) -> extensions.AsyncExtensionsResourceWithStreamingResponse:
971+
from .resources.extensions import AsyncExtensionsResourceWithStreamingResponse
972+
973+
return AsyncExtensionsResourceWithStreamingResponse(self._client.extensions)
974+
975+
@cached_property
976+
def profiles(self) -> profiles.AsyncProfilesResourceWithStreamingResponse:
977+
from .resources.profiles import AsyncProfilesResourceWithStreamingResponse
978+
979+
return AsyncProfilesResourceWithStreamingResponse(self._client.profiles)
980+
818981

819982
Client = Steel
820983

0 commit comments

Comments
 (0)