Skip to content

Commit 88cb4a0

Browse files
authored
feat: Added StoreCollectionClient for listing Actors in Apify store (#147)
- Added new methods for https://docs.apify.com/api/v2/#/reference/store/store-actors-collection - Updated actions/checkout across GH workflows because actions/checkout#1448 (comment)
1 parent bf64cb2 commit 88cb4a0

File tree

12 files changed

+238
-5
lines changed

12 files changed

+238
-5
lines changed

.github/workflows/check_docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
steps:
1212
- name: Checkout repository
13-
uses: actions/checkout@v3
13+
uses: actions/checkout@v4
1414

1515
- name: Set up Python
1616
uses: actions/setup-python@v4

.github/workflows/integration_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: Checkout repository
24-
uses: actions/checkout@v3
24+
uses: actions/checkout@v4
2525

2626
- name: Set up Python ${{ matrix.python-version }}
2727
uses: actions/setup-python@v4

.github/workflows/lint_and_type_checks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout repository
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717

1818
- name: Set up Python ${{ matrix.python-version }}
1919
uses: actions/setup-python@v4

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454

5555
steps:
5656
- name: Checkout repository
57-
uses: actions/checkout@v3
57+
uses: actions/checkout@v4
5858

5959
- name: Set up Python
6060
uses: actions/setup-python@v4

.github/workflows/unit_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
steps:
1616
- name: Checkout repository
17-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1818

1919
- name: Set up Python ${{ matrix.python-version }}
2020
uses: actions/setup-python@v4

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changelog
66

77
### Added
88

9+
- Add StoreCollectionClient for listing Actors in Apify store
910
- support for specifying the `max_items` parameter for pay-per result Actors and their runs
1011

1112
### Internal changes

docs/docs.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ The Apify API client.
239239
* [task()](#apifyclient-task)
240240
* [tasks()](#apifyclient-tasks)
241241
* [user()](#apifyclient-user)
242+
* [store()](#apifyclient-store)
242243

243244
***
244245

@@ -531,6 +532,16 @@ Retrieve the sub-client for querying users.
531532

532533
***
533534

535+
#### [](#apifyclient-store) `ApifyClient.store()`
536+
537+
Retrieve the sub-client for Apify store.
538+
539+
* **Return type**
540+
541+
[`StoreCollectionClient`](#storecollectionclient)
542+
543+
***
544+
534545
### [](#apifyclientasync) ApifyClientAsync
535546

536547
The asynchronous version of the Apify API client.
@@ -558,6 +569,7 @@ The asynchronous version of the Apify API client.
558569
* [task()](#apifyclientasync-task)
559570
* [tasks()](#apifyclientasync-tasks)
560571
* [user()](#apifyclientasync-user)
572+
* [store()](#apifyclientasync-store)
561573

562574
***
563575

@@ -850,6 +862,16 @@ Retrieve the sub-client for querying users.
850862

851863
***
852864

865+
#### [](#apifyclientasync-store) `ApifyClientAsync.store()`
866+
867+
Retrieve the sub-client for Apify store.
868+
869+
* **Return type**
870+
871+
`StoreCollectionClientAsync`
872+
873+
***
874+
853875
### [](#actorclient) ActorClient
854876

855877
Sub-client for manipulating a single actor.
@@ -6237,3 +6259,83 @@ List all webhook dispatches of a user.
62376259
* **Return type**
62386260

62396261
[`ListPage`](#listpage)
6262+
6263+
***
6264+
6265+
### [](#storecollectionclient) StoreCollectionClient
6266+
6267+
Sub-client for Apify store.
6268+
6269+
* [list()](#storecollectionclient-list)
6270+
6271+
***
6272+
6273+
#### [](#storecollectionclient-list) `StoreCollectionClient.list(*, limit=None, offset=None, search=None, sort_by=None, category=None, username=None, pricing_model=None)`
6274+
6275+
List Actors in Apify store.
6276+
6277+
[https://docs.apify.com/api/v2/#/reference/store/store-actors-collection/get-list-of-actors-in-store](https://docs.apify.com/api/v2/#/reference/store/store-actors-collection/get-list-of-actors-in-store)
6278+
6279+
* **Parameters**
6280+
6281+
* **limit** (`int`, *optional*) – How many Actors to list
6282+
6283+
* **offset** (`int`, *optional*) – What Actor to include as first when retrieving the list
6284+
6285+
* **search** (`str`, *optional*) – String to search by. The search runs on the following fields: title, name, description, username, readme.
6286+
6287+
* **sort_by** (`str`, *optional*) – Specifies the field by which to sort the results.
6288+
6289+
* **category** (`str`, *optional*) – Filter by this category
6290+
6291+
* **username** (`str`, *optional*) – Filter by this username
6292+
6293+
* **pricing_model** (`str`, *optional*) – Filter by this pricing model
6294+
6295+
* **Returns**
6296+
6297+
The list of available tasks matching the specified filters.
6298+
6299+
* **Return type**
6300+
6301+
[`ListPage`](#listpage)
6302+
6303+
***
6304+
6305+
### [](#storecollectionclientasync) StoreCollectionClientAsync
6306+
6307+
Async sub-client for Apify store.
6308+
6309+
* [async list()](#storecollectionclientasync-list)
6310+
6311+
***
6312+
6313+
#### [](#storecollectionclientasync-list) `async StoreCollectionClientAsync.list(*, limit=None, offset=None, search=None, sort_by=None, category=None, username=None, pricing_model=None)`
6314+
6315+
List Actors in Apify store.
6316+
6317+
[https://docs.apify.com/api/v2/#/reference/store/store-actors-collection/get-list-of-actors-in-store](https://docs.apify.com/api/v2/#/reference/store/store-actors-collection/get-list-of-actors-in-store)
6318+
6319+
* **Parameters**
6320+
6321+
* **limit** (`int`, *optional*) – How many Actors to list
6322+
6323+
* **offset** (`int`, *optional*) – What Actor to include as first when retrieving the list
6324+
6325+
* **search** (`str`, *optional*) – String to search by. The search runs on the following fields: title, name, description, username, readme.
6326+
6327+
* **sort_by** (`str`, *optional*) – Specifies the field by which to sort the results.
6328+
6329+
* **category** (`str`, *optional*) – Filter by this category
6330+
6331+
* **username** (`str`, *optional*) – Filter by this username
6332+
6333+
* **pricing_model** (`str`, *optional*) – Filter by this pricing model
6334+
6335+
* **Returns**
6336+
6337+
The list of available tasks matching the specified filters.
6338+
6339+
* **Return type**
6340+
6341+
[`ListPage`](#listpage)

src/apify_client/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
ScheduleClientAsync,
3535
ScheduleCollectionClient,
3636
ScheduleCollectionClientAsync,
37+
StoreCollectionClient,
38+
StoreCollectionClientAsync,
3739
TaskClient,
3840
TaskClientAsync,
3941
TaskCollectionClient,
@@ -268,6 +270,10 @@ def user(self, user_id: Optional[str] = None) -> UserClient:
268270
"""
269271
return UserClient(resource_id=user_id, **self._options())
270272

273+
def store(self) -> StoreCollectionClient:
274+
"""Retrieve the sub-client for Apify store."""
275+
return StoreCollectionClient(**self._options())
276+
271277

272278
class ApifyClientAsync(_BaseApifyClient):
273279
"""The asynchronous version of the Apify API client."""
@@ -444,3 +450,7 @@ def user(self, user_id: Optional[str] = None) -> UserClientAsync:
444450
user_id (str, optional): ID of user to be queried. If None, queries the user belonging to the token supplied to the client
445451
"""
446452
return UserClientAsync(resource_id=user_id, **self._options())
453+
454+
def store(self) -> StoreCollectionClientAsync:
455+
"""Retrieve the sub-client for Apify store."""
456+
return StoreCollectionClientAsync(**self._options())

src/apify_client/clients/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
ScheduleClientAsync,
4444
ScheduleCollectionClient,
4545
ScheduleCollectionClientAsync,
46+
StoreCollectionClient,
47+
StoreCollectionClientAsync,
4648
TaskClient,
4749
TaskClientAsync,
4850
TaskCollectionClient,
@@ -88,4 +90,5 @@
8890
'WebhookCollectionClient', 'WebhookCollectionClientAsync',
8991
'WebhookDispatchClient', 'WebhookDispatchClientAsync',
9092
'WebhookDispatchCollectionClient', 'WebhookDispatchCollectionClientAsync',
93+
'StoreCollectionClient', 'StoreCollectionClientAsync',
9194
]

src/apify_client/clients/resource_clients/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .run_collection import RunCollectionClient, RunCollectionClientAsync
1616
from .schedule import ScheduleClient, ScheduleClientAsync
1717
from .schedule_collection import ScheduleCollectionClient, ScheduleCollectionClientAsync
18+
from .store_collection import StoreCollectionClient, StoreCollectionClientAsync
1819
from .task import TaskClient, TaskClientAsync
1920
from .task_collection import TaskCollectionClient, TaskCollectionClientAsync
2021
from .user import UserClient, UserClientAsync
@@ -48,4 +49,5 @@
4849
'ScheduleClient', 'WebhookCollectionClientAsync',
4950
'ScheduleCollectionClient', 'WebhookDispatchClientAsync',
5051
'UserClient', 'WebhookDispatchCollectionClientAsync',
52+
'StoreCollectionClient', 'StoreCollectionClientAsync',
5153
]
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from typing import Any, Dict, Optional
2+
3+
from apify_shared.models import ListPage
4+
from apify_shared.utils import ignore_docs
5+
6+
from ..base import ResourceCollectionClient, ResourceCollectionClientAsync
7+
8+
9+
class StoreCollectionClient(ResourceCollectionClient):
10+
"""Sub-client for Apify store."""
11+
12+
@ignore_docs
13+
def __init__(self, *args: Any, **kwargs: Any) -> None:
14+
"""Initialize the StoreCollectionClient."""
15+
resource_path = kwargs.pop('resource_path', 'store')
16+
super().__init__(*args, resource_path=resource_path, **kwargs)
17+
18+
def list(
19+
self,
20+
*,
21+
limit: Optional[int] = None,
22+
offset: Optional[int] = None,
23+
search: Optional[str] = None,
24+
sort_by: Optional[str] = None,
25+
category: Optional[str] = None,
26+
username: Optional[str] = None,
27+
pricing_model: Optional[str] = None,
28+
) -> ListPage[Dict]:
29+
"""List Actors in Apify store.
30+
31+
https://docs.apify.com/api/v2/#/reference/store/store-actors-collection/get-list-of-actors-in-store
32+
33+
Args:
34+
limit (int, optional): How many Actors to list
35+
offset (int, optional): What Actor to include as first when retrieving the list
36+
search (str, optional): String to search by. The search runs on the following fields: title, name, description, username, readme.
37+
sort_by (str, optional): Specifies the field by which to sort the results.
38+
category (str, optional): Filter by this category
39+
username (str, optional): Filter by this username
40+
pricing_model (str, optional): Filter by this pricing model
41+
42+
Returns:
43+
ListPage: The list of available tasks matching the specified filters.
44+
"""
45+
return self._list(
46+
limit=limit,
47+
offset=offset,
48+
search=search,
49+
sortBy=sort_by,
50+
category=category,
51+
username=username,
52+
pricingModel=pricing_model,
53+
)
54+
55+
56+
class StoreCollectionClientAsync(ResourceCollectionClientAsync):
57+
"""Async sub-client for Apify store."""
58+
59+
@ignore_docs
60+
def __init__(self, *args: Any, **kwargs: Any) -> None:
61+
"""Initialize the StoreCollectionClientAsync."""
62+
resource_path = kwargs.pop('resource_path', 'store')
63+
super().__init__(*args, resource_path=resource_path, **kwargs)
64+
65+
async def list(
66+
self,
67+
*,
68+
limit: Optional[int] = None,
69+
offset: Optional[int] = None,
70+
search: Optional[str] = None,
71+
sort_by: Optional[str] = None,
72+
category: Optional[str] = None,
73+
username: Optional[str] = None,
74+
pricing_model: Optional[str] = None,
75+
) -> ListPage[Dict]:
76+
"""List Actors in Apify store.
77+
78+
https://docs.apify.com/api/v2/#/reference/store/store-actors-collection/get-list-of-actors-in-store
79+
80+
Args:
81+
limit (int, optional): How many Actors to list
82+
offset (int, optional): What Actor to include as first when retrieving the list
83+
search (str, optional): String to search by. The search runs on the following fields: title, name, description, username, readme.
84+
sort_by (str, optional): Specifies the field by which to sort the results.
85+
category (str, optional): Filter by this category
86+
username (str, optional): Filter by this username
87+
pricing_model (str, optional): Filter by this pricing model
88+
89+
Returns:
90+
ListPage: The list of available tasks matching the specified filters.
91+
"""
92+
return await self._list(
93+
limit=limit,
94+
offset=offset,
95+
search=search,
96+
sortBy=sort_by,
97+
category=category,
98+
username=username,
99+
pricingModel=pricing_model,
100+
)

tests/integration/test_store.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from apify_client import ApifyClient, ApifyClientAsync
2+
3+
4+
class TestStoreCollectionSync:
5+
def test_list(self, apify_client: ApifyClient) -> None:
6+
actors_list = apify_client.store().list()
7+
assert actors_list is not None
8+
assert len(actors_list.items) != 0
9+
10+
11+
class TestStoreCollectionAsync:
12+
async def test_list(self, apify_client_async: ApifyClientAsync) -> None:
13+
actors_list = await apify_client_async.store().list()
14+
assert actors_list is not None
15+
assert len(actors_list.items) != 0

0 commit comments

Comments
 (0)