Skip to content

Commit 6747c20

Browse files
authored
feat: add list kv store keys by collection or prefix (#397)
Add `collection` and `prefix` query params for listing key-value store keys based on https://github.com/apify/actor-whitepaper/blob/master/pages/KEY_VALUE_STORE_SCHEMA.md#api-implications Api docs: apify/apify-docs#1564 Api impl: apify/apify-core#20726
1 parent 1fef5a4 commit 6747c20

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/apify_client/clients/resource_clients/key_value_store.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,33 @@ def delete(self) -> None:
6363
"""
6464
return self._delete(timeout_secs=_SMALL_TIMEOUT)
6565

66-
def list_keys(self, *, limit: int | None = None, exclusive_start_key: str | None = None) -> dict:
66+
def list_keys(
67+
self,
68+
*,
69+
limit: int | None = None,
70+
exclusive_start_key: str | None = None,
71+
collection: str | None = None,
72+
prefix: str | None = None,
73+
) -> dict:
6774
"""List the keys in the key-value store.
6875
6976
https://docs.apify.com/api/v2#/reference/key-value-stores/key-collection/get-list-of-keys
7077
7178
Args:
7279
limit: Number of keys to be returned. Maximum value is 1000.
7380
exclusive_start_key: All keys up to this one (including) are skipped from the result.
81+
collection: The name of the collection in store schema to list keys from.
82+
prefix: The prefix of the keys to be listed.
7483
7584
Returns:
7685
The list of keys in the key-value store matching the given arguments.
7786
"""
78-
request_params = self._params(limit=limit, exclusiveStartKey=exclusive_start_key)
87+
request_params = self._params(
88+
limit=limit,
89+
exclusiveStartKey=exclusive_start_key,
90+
collection=collection,
91+
prefix=prefix,
92+
)
7993

8094
response = self.http_client.call(
8195
url=self._url('keys'),
@@ -292,19 +306,33 @@ async def delete(self) -> None:
292306
"""
293307
return await self._delete(timeout_secs=_SMALL_TIMEOUT)
294308

295-
async def list_keys(self, *, limit: int | None = None, exclusive_start_key: str | None = None) -> dict:
309+
async def list_keys(
310+
self,
311+
*,
312+
limit: int | None = None,
313+
exclusive_start_key: str | None = None,
314+
collection: str | None = None,
315+
prefix: str | None = None,
316+
) -> dict:
296317
"""List the keys in the key-value store.
297318
298319
https://docs.apify.com/api/v2#/reference/key-value-stores/key-collection/get-list-of-keys
299320
300321
Args:
301322
limit: Number of keys to be returned. Maximum value is 1000.
302323
exclusive_start_key: All keys up to this one (including) are skipped from the result.
324+
collection: The name of the collection in store schema to list keys from.
325+
prefix: The prefix of the keys to be listed.
303326
304327
Returns:
305328
The list of keys in the key-value store matching the given arguments.
306329
"""
307-
request_params = self._params(limit=limit, exclusiveStartKey=exclusive_start_key)
330+
request_params = self._params(
331+
limit=limit,
332+
exclusiveStartKey=exclusive_start_key,
333+
collection=collection,
334+
prefix=prefix,
335+
)
308336

309337
response = await self.http_client.call(
310338
url=self._url('keys'),

0 commit comments

Comments
 (0)