Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/apify_client/_resource_clients/actor_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

from apify_client._types import Timeout

_SORT_BY_TO_API: dict[str, str] = {
'created_at': 'createdAt',
'last_run_started_at': 'stats.lastRunStartedAt',
}


@docs_group('Resource clients')
class ActorCollectionClient(ResourceClient):
Expand Down Expand Up @@ -48,7 +53,7 @@ def list(
limit: int | None = None,
offset: int | None = None,
desc: bool | None = None,
sort_by: Literal['createdAt', 'stats.lastRunStartedAt'] | None = 'createdAt',
sort_by: Literal['created_at', 'last_run_started_at'] | None = 'created_at',
timeout: Timeout = 'medium',
) -> ListOfActors:
"""List the Actors the user has created or used.
Expand All @@ -66,7 +71,8 @@ def list(
Returns:
The list of available Actors matching the specified filters.
"""
result = self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=sort_by)
api_sort_by = _SORT_BY_TO_API[sort_by] if sort_by is not None else None
result = self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=api_sort_by)
return ListOfActorsResponse.model_validate(result).data

def create(
Expand Down Expand Up @@ -193,7 +199,7 @@ async def list(
limit: int | None = None,
offset: int | None = None,
desc: bool | None = None,
sort_by: Literal['createdAt', 'stats.lastRunStartedAt'] | None = 'createdAt',
sort_by: Literal['created_at', 'last_run_started_at'] | None = 'created_at',
timeout: Timeout = 'medium',
) -> ListOfActors:
"""List the Actors the user has created or used.
Expand All @@ -211,7 +217,8 @@ async def list(
Returns:
The list of available Actors matching the specified filters.
"""
result = await self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=sort_by)
api_sort_by = _SORT_BY_TO_API[sort_by] if sort_by is not None else None
result = await self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=api_sort_by)
return ListOfActorsResponse.model_validate(result).data

async def create(
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def test_list_actors_pagination(client: ApifyClient | ApifyClientAsync) ->

async def test_list_actors_sorting(client: ApifyClient | ApifyClientAsync) -> None:
"""Test listing Actors with sorting."""
result = await maybe_await(client.actors().list(limit=10, desc=True, sort_by='createdAt'))
result = await maybe_await(client.actors().list(limit=10, desc=True, sort_by='created_at'))
actors_page = cast('ListOfActors', result)

assert actors_page is not None
Expand Down