Skip to content

Commit d2c79d3

Browse files
committed
polishment
1 parent ed78ac5 commit d2c79d3

File tree

6 files changed

+43
-35
lines changed

6 files changed

+43
-35
lines changed

src/apify/_actor.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,11 @@ async def open_dataset(
413413
414414
Args:
415415
id: The ID of the dataset to open. If provided, searches for existing dataset by ID.
416-
name: The name of the dataset for named storages. Mutually exclusive with alias.
417-
alias: The alias of the dataset for unnamed storages. Mutually exclusive with name.
416+
Mutually exclusive with name and alias.
417+
name: The name of the dataset to open (global scope, persists across runs).
418+
Mutually exclusive with id and alias.
419+
alias: The alias of the dataset to open (run scope, creates unnamed storage).
420+
Mutually exclusive with id and name.
418421
force_cloud: If set to `True` then the Apify cloud storage is always used. This way it is possible
419422
to combine local and cloud storage.
420423
@@ -449,8 +452,11 @@ async def open_key_value_store(
449452
450453
Args:
451454
id: The ID of the KVS to open. If provided, searches for existing KVS by ID.
452-
name: The name of the KVS for named storages. Mutually exclusive with alias.
453-
alias: The alias of the KVS for unnamed storages. Mutually exclusive with name.
455+
Mutually exclusive with name and alias.
456+
name: The name of the KVS to open (global scope, persists across runs).
457+
Mutually exclusive with id and alias.
458+
alias: The alias of the KVS to open (run scope, creates unnamed storage).
459+
Mutually exclusive with id and name.
454460
force_cloud: If set to `True` then the Apify cloud storage is always used. This way it is possible
455461
to combine local and cloud storage.
456462
@@ -485,9 +491,12 @@ async def open_request_queue(
485491
crawling orders.
486492
487493
Args:
488-
id: The ID of the request queue to open. If provided, searches for existing request queue by ID.
489-
name: The name of the request queue for named storages. Mutually exclusive with alias.
490-
alias: The alias of the request queue for unnamed storages. Mutually exclusive with name.
494+
id: The ID of the RQ to open. If provided, searches for existing RQ by ID.
495+
Mutually exclusive with name and alias.
496+
name: The name of the RQ to open (global scope, persists across runs).
497+
Mutually exclusive with id and alias.
498+
alias: The alias of the RQ to open (run scope, creates unnamed storage).
499+
Mutually exclusive with id and name.
491500
force_cloud: If set to `True` then the Apify cloud storage is always used. This way it is possible
492501
to combine local and cloud storage.
493502

src/apify/storage_clients/_apify/_dataset_client.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,12 @@ async def open(
7777
It handles authentication, storage lookup/creation, and metadata retrieval.
7878
7979
Args:
80-
id: The ID of an existing dataset to open. If provided, the client will connect to this specific storage.
81-
Cannot be used together with `name` or `alias`.
82-
name: The name of a dataset to get or create. If a storage with this name exists, it will be opened;
83-
otherwise, a new one will be created. Cannot be used together with `id` or `alias`.
84-
alias: The alias of a dataset for unnamed storages. If a storage with this alias exists, it will be
85-
opened; otherwise, a new one will be created and the alias will be saved. Cannot be used together
86-
with `id` or `name`.
80+
id: The ID of the dataset to open. If provided, searches for existing dataset by ID.
81+
Mutually exclusive with name and alias.
82+
name: The name of the dataset to open (global scope, persists across runs).
83+
Mutually exclusive with id and alias.
84+
alias: The alias of the dataset to open (run scope, creates unnamed storage).
85+
Mutually exclusive with id and name.
8786
configuration: The configuration object containing API credentials and settings. Must include a valid
8887
`token` and `api_base_url`. May also contain a `default_dataset_id` for fallback when neither
8988
`id`, `name`, nor `alias` is provided.

src/apify/storage_clients/_apify/_key_value_store_client.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,12 @@ async def open(
6868
It handles authentication, storage lookup/creation, and metadata retrieval.
6969
7070
Args:
71-
id: The ID of an existing key-value store to open. If provided, the client will connect to this specific
72-
storage. Cannot be used together with `name` or `alias`.
73-
name: The name of a key-value store to get or create. If a storage with this name exists, it will be
74-
opened; otherwise, a new one will be created. Cannot be used together with `id` or `alias`.
75-
alias: The alias of a key-value store for unnamed storages. If a storage with this alias exists, it will
76-
be opened; otherwise, a new one will be created and the alias will be saved. Cannot be used together
77-
with `id` or `name`.
71+
id: The ID of the KVS to open. If provided, searches for existing KVS by ID.
72+
Mutually exclusive with name and alias.
73+
name: The name of the KVS to open (global scope, persists across runs).
74+
Mutually exclusive with id and alias.
75+
alias: The alias of the KVS to open (run scope, creates unnamed storage).
76+
Mutually exclusive with id and name.
7877
configuration: The configuration object containing API credentials and settings. Must include a valid
7978
`token` and `api_base_url`. May also contain a `default_key_value_store_id` for fallback when
8079
neither `id`, `name`, nor `alias` is provided.
@@ -121,7 +120,7 @@ async def open(
121120
# Handle alias resolution
122121
if alias:
123122
# Try to resolve alias to existing storage ID
124-
resolved_id = await resolve_alias_to_id(alias, 'key_value_store', configuration)
123+
resolved_id = await resolve_alias_to_id(alias, 'kvs', configuration)
125124
if resolved_id:
126125
id = resolved_id
127126
else:
@@ -130,7 +129,7 @@ async def open(
130129
await apify_kvss_client.get_or_create(),
131130
)
132131
id = new_storage_metadata.id
133-
await store_alias_mapping(alias, 'key_value_store', id, configuration)
132+
await store_alias_mapping(alias, 'kvs', id, configuration)
134133

135134
# If name is provided, get or create the storage by name.
136135
elif name:

src/apify/storage_clients/_apify/_request_queue_client.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,12 @@ async def open(
146146
management structures.
147147
148148
Args:
149-
id: The ID of an existing request queue to open. If provided, the client will connect to this specific
150-
storage. Cannot be used together with `name` or `alias`.
151-
name: The name of a request queue to get or create. If a storage with this name exists, it will be opened;
152-
otherwise, a new one will be created. Cannot be used together with `id` or `alias`.
153-
alias: The alias of a request queue for unnamed storages. If a storage with this alias exists, it will
154-
be opened; otherwise, a new one will be created and the alias will be saved. Cannot be used together
155-
with `id` or `name`.
149+
id: The ID of the RQ to open. If provided, searches for existing RQ by ID.
150+
Mutually exclusive with name and alias.
151+
name: The name of the RQ to open (global scope, persists across runs).
152+
Mutually exclusive with id and alias.
153+
alias: The alias of the RQ to open (run scope, creates unnamed storage).
154+
Mutually exclusive with id and name.
156155
configuration: The configuration object containing API credentials and settings. Must include a valid
157156
`token` and `api_base_url`. May also contain a `default_request_queue_id` for fallback when neither
158157
`id`, `name`, nor `alias` is provided.
@@ -199,7 +198,7 @@ async def open(
199198
# Handle alias resolution
200199
if alias:
201200
# Try to resolve alias to existing storage ID
202-
resolved_id = await resolve_alias_to_id(alias, 'request_queue', configuration)
201+
resolved_id = await resolve_alias_to_id(alias, 'rq', configuration)
203202
if resolved_id:
204203
id = resolved_id
205204
else:
@@ -208,7 +207,7 @@ async def open(
208207
await apify_rqs_client.get_or_create(),
209208
)
210209
id = new_storage_metadata.id
211-
await store_alias_mapping(alias, 'request_queue', id, configuration)
210+
await store_alias_mapping(alias, 'rq', id, configuration)
212211

213212
# If name is provided, get or create the storage by name.
214213
elif name:

src/apify/storage_clients/_apify/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from logging import getLogger
4-
from typing import TYPE_CHECKING
4+
from typing import TYPE_CHECKING, Literal
55

66
from apify_client import ApifyClientAsync
77

@@ -15,7 +15,7 @@
1515

1616
async def resolve_alias_to_id(
1717
alias: str,
18-
storage_type: str,
18+
storage_type: Literal['dataset', 'kvs', 'rq'],
1919
configuration: Configuration,
2020
) -> str | None:
2121
"""Resolve a storage alias to its corresponding storage ID.
@@ -52,7 +52,7 @@ async def resolve_alias_to_id(
5252

5353
async def store_alias_mapping(
5454
alias: str,
55-
storage_type: str,
55+
storage_type: Literal['dataset', 'kvs', 'rq'],
5656
storage_id: str,
5757
configuration: Configuration,
5858
) -> None:

tests/integration/test_actor_request_queue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ async def test_rq_defaults(
405405
run_actor: RunActorFunction,
406406
) -> None:
407407
async def main() -> None:
408+
from apify import Request
408409
from apify.storages import RequestQueue
409410

410411
async with Actor:
@@ -445,6 +446,7 @@ async def test_rq_aliases(
445446
run_actor: RunActorFunction,
446447
) -> None:
447448
async def main() -> None:
449+
from apify import Request
448450
from apify.storages import RequestQueue
449451

450452
async with Actor:

0 commit comments

Comments
 (0)