38
38
from apify .log import _configure_logging , logger
39
39
from apify .storage_clients import ApifyStorageClient
40
40
from apify .storage_clients ._file_system import ApifyFileSystemStorageClient
41
- from apify .storage_clients ._hybrid_apify ._storage_client import ApifyHybridStorageClient
41
+ from apify .storage_clients ._smart_apify ._storage_client import SmartApifyStorageClient
42
+ from apify .storages import Dataset , KeyValueStore , RequestQueue
42
43
43
44
if TYPE_CHECKING :
44
45
import logging
50
51
from crawlee .proxy_configuration import _NewUrlFunction
51
52
52
53
from apify ._models import Webhook
53
- from apify .storages import Dataset , KeyValueStore , RequestQueue
54
54
55
55
56
56
MainReturnType = TypeVar ('MainReturnType' )
@@ -238,14 +238,14 @@ def _raise_if_not_initialized(self) -> None:
238
238
raise RuntimeError ('The Actor was not initialized!' )
239
239
240
240
@cached_property
241
- def _storage_client (self ) -> ApifyHybridStorageClient :
241
+ def _storage_client (self ) -> SmartApifyStorageClient :
242
242
"""Storage client used by the actor.
243
243
244
244
Depending on the initialization of the service locator the client can be created in different ways.
245
245
"""
246
246
try :
247
247
# Nothing was set by the user.
248
- implicit_storage_client = ApifyHybridStorageClient (
248
+ implicit_storage_client = SmartApifyStorageClient (
249
249
local_storage_client = ApifyFileSystemStorageClient (), cloud_storage_client = ApifyStorageClient ()
250
250
)
251
251
service_locator .set_storage_client (implicit_storage_client )
@@ -259,13 +259,13 @@ def _storage_client(self) -> ApifyHybridStorageClient:
259
259
260
260
# User set something in the service locator.
261
261
storage_client = service_locator .get_storage_client ()
262
- if isinstance (storage_client , ApifyHybridStorageClient ):
262
+ if isinstance (storage_client , SmartApifyStorageClient ):
263
263
# The client was manually set to the right type in the service locator. This is the explicit way.
264
264
return storage_client
265
265
266
266
if isinstance (storage_client , ApifyStorageClient ):
267
267
# The cloud storage client was manually set in the service locator.
268
- return ApifyHybridStorageClient (cloud_storage_client = storage_client )
268
+ return SmartApifyStorageClient (cloud_storage_client = storage_client )
269
269
270
270
# The local storage client was manually set in the service locator
271
271
if type (storage_client ) is FileSystemStorageClient :
@@ -275,7 +275,7 @@ def _storage_client(self) -> ApifyHybridStorageClient:
275
275
f'`apify.storage_clients.FileSystemStorageClient` instead.'
276
276
)
277
277
278
- return ApifyHybridStorageClient (cloud_storage_client = ApifyStorageClient (), local_storage_client = storage_client )
278
+ return SmartApifyStorageClient (cloud_storage_client = ApifyStorageClient (), local_storage_client = storage_client )
279
279
280
280
async def init (self ) -> None :
281
281
"""Initialize the Actor instance.
@@ -464,7 +464,12 @@ async def open_dataset(
464
464
An instance of the `Dataset` class for the given ID or name.
465
465
"""
466
466
self ._raise_if_not_initialized ()
467
- return await self ._storage_client .open_dataset (id = id , name = name , alias = alias , force_cloud = force_cloud )
467
+ return await Dataset .open (
468
+ id = id ,
469
+ name = name ,
470
+ alias = alias ,
471
+ storage_client = self ._storage_client .get_suitable_storage_client (force_cloud = force_cloud ),
472
+ )
468
473
469
474
async def open_key_value_store (
470
475
self ,
@@ -493,7 +498,12 @@ async def open_key_value_store(
493
498
An instance of the `KeyValueStore` class for the given ID or name.
494
499
"""
495
500
self ._raise_if_not_initialized ()
496
- return await self ._storage_client .open_key_value_store (id = id , name = name , alias = alias , force_cloud = force_cloud )
501
+ return await KeyValueStore .open (
502
+ id = id ,
503
+ name = name ,
504
+ alias = alias ,
505
+ storage_client = self ._storage_client .get_suitable_storage_client (force_cloud = force_cloud ),
506
+ )
497
507
498
508
async def open_request_queue (
499
509
self ,
@@ -524,7 +534,12 @@ async def open_request_queue(
524
534
An instance of the `RequestQueue` class for the given ID or name.
525
535
"""
526
536
self ._raise_if_not_initialized ()
527
- return await self ._storage_client .open_request_queue (id = id , name = name , alias = alias , force_cloud = force_cloud )
537
+ return await RequestQueue .open (
538
+ id = id ,
539
+ name = name ,
540
+ alias = alias ,
541
+ storage_client = self ._storage_client .get_suitable_storage_client (force_cloud = force_cloud ),
542
+ )
528
543
529
544
@overload
530
545
async def push_data (self , data : dict | list [dict ]) -> None : ...
0 commit comments