Skip to content

Commit fdfe6ad

Browse files
committed
refactor: accept snake_case values for actors().list(sort_by=...)
Change the sort_by Literal to pythonic snake_case values ('created_at', 'last_run_started_at') and translate them to the API's camelCase form ('createdAt', 'stats.lastRunStartedAt') inside the client.
1 parent 3d4ce3f commit fdfe6ad

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/apify_client/_resource_clients/actor_collection.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
from apify_client._types import Timeout
2323

24+
_SORT_BY_TO_API: dict[str, str] = {
25+
'created_at': 'createdAt',
26+
'last_run_started_at': 'stats.lastRunStartedAt',
27+
}
28+
2429

2530
@docs_group('Resource clients')
2631
class ActorCollectionClient(ResourceClient):
@@ -48,7 +53,7 @@ def list(
4853
limit: int | None = None,
4954
offset: int | None = None,
5055
desc: bool | None = None,
51-
sort_by: Literal['createdAt', 'stats.lastRunStartedAt'] | None = 'createdAt',
56+
sort_by: Literal['created_at', 'last_run_started_at'] | None = 'created_at',
5257
timeout: Timeout = 'medium',
5358
) -> ListOfActors:
5459
"""List the Actors the user has created or used.
@@ -66,7 +71,8 @@ def list(
6671
Returns:
6772
The list of available Actors matching the specified filters.
6873
"""
69-
result = self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=sort_by)
74+
api_sort_by = _SORT_BY_TO_API[sort_by] if sort_by is not None else None
75+
result = self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=api_sort_by)
7076
return ListOfActorsResponse.model_validate(result).data
7177

7278
def create(
@@ -193,7 +199,7 @@ async def list(
193199
limit: int | None = None,
194200
offset: int | None = None,
195201
desc: bool | None = None,
196-
sort_by: Literal['createdAt', 'stats.lastRunStartedAt'] | None = 'createdAt',
202+
sort_by: Literal['created_at', 'last_run_started_at'] | None = 'created_at',
197203
timeout: Timeout = 'medium',
198204
) -> ListOfActors:
199205
"""List the Actors the user has created or used.
@@ -211,7 +217,8 @@ async def list(
211217
Returns:
212218
The list of available Actors matching the specified filters.
213219
"""
214-
result = await self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=sort_by)
220+
api_sort_by = _SORT_BY_TO_API[sort_by] if sort_by is not None else None
221+
result = await self._list(timeout=timeout, my=my, limit=limit, offset=offset, desc=desc, sortBy=api_sort_by)
215222
return ListOfActorsResponse.model_validate(result).data
216223

217224
async def create(

tests/integration/test_actor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def test_list_actors_pagination(client: ApifyClient | ApifyClientAsync) ->
6060

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

6666
assert actors_page is not None

0 commit comments

Comments
 (0)