Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions docs/02_concepts/code/03_nested_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from apify_client import ApifyClientAsync
from apify_client._models import ActorJobStatus

TOKEN = 'MY-APIFY-TOKEN'

Expand All @@ -14,7 +13,7 @@ async def main() -> None:
actor_runs = (await runs_client.list(limit=10, desc=True)).items

# Select the last run of the Actor that finished with a SUCCEEDED status.
last_succeeded_run_client = actor_client.last_run(status=ActorJobStatus.SUCCEEDED)
last_succeeded_run_client = actor_client.last_run(status='SUCCEEDED')

# Get dataset
actor_run_dataset_client = last_succeeded_run_client.dataset()
Expand Down
3 changes: 1 addition & 2 deletions docs/02_concepts/code/03_nested_sync.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from apify_client import ApifyClient
from apify_client._models import ActorJobStatus

TOKEN = 'MY-APIFY-TOKEN'

Expand All @@ -14,7 +13,7 @@ def main() -> None:
actor_runs = runs_client.list(limit=10, desc=True).items

# Select the last run of the Actor that finished with a SUCCEEDED status.
last_succeeded_run_client = actor_client.last_run(status=ActorJobStatus.SUCCEEDED)
last_succeeded_run_client = actor_client.last_run(status='SUCCEEDED')

# Get dataset
actor_run_dataset_client = last_succeeded_run_client.dataset()
Expand Down
28 changes: 21 additions & 7 deletions docs/04_upgrading/upgrading_to_v3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,36 @@ client.key_value_store('my-store').set_record('my-key', {'data': 1}, content_typ
client.run('my-run').charge('my-event', count=5, idempotency_key='my-idempotency-key')
```

## Snake_case `sort_by` values on `actors().list()`
## `Literal` type aliases instead of `StrEnum` classes

The `sort_by` parameter of <ApiLink to="class/ActorCollectionClient#list">`ActorCollectionClient.list()`</ApiLink> and <ApiLink to="class/ActorCollectionClientAsync#list">`ActorCollectionClientAsync.list()`</ApiLink> now accepts pythonic snake_case values instead of the raw camelCase values used by the API.
Generated enum-like types are now [`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal) type aliases instead of `StrEnum` classes. Pass plain strings instead of enum members; type checkers will validate them against the allowed set.

Affected types: `ActorJobStatus`, `ActorPermissionLevel`, `ErrorType`, `GeneralAccess`, `HttpMethod`, `RunOrigin`, `SourceCodeFileFormat`, `StorageOwnership`, `VersionSourceType`, `WebhookDispatchStatus`, `WebhookEventType`.

Before (v2):

```python
client.actors().list(sort_by='createdAt')
client.actors().list(sort_by='stats.lastRunStartedAt')
from apify_client._models import WebhookEventType

client.actor('apify/hello-world').webhooks().create(
event_types=[WebhookEventType.ACTOR_RUN_SUCCEEDED],
request_url='https://example.com/webhook',
)
```

After (v3):

```python
client.actors().list(sort_by='created_at')
client.actors().list(sort_by='last_run_started_at')
client.actor('apify/hello-world').webhooks().create(
event_types=['ACTOR.RUN.SUCCEEDED'],
request_url='https://example.com/webhook',
)
```

The default value also changed from `'createdAt'` to `'created_at'` (behavior is unchanged). The client translates the snake_case value to the form expected by the API internally.
The aliases now live in `apify_client._literals` (previously `apify_client._models`) and can be imported for use in type annotations:

```python
from apify_client._literals import WebhookEventType

events: list[WebhookEventType] = ['ACTOR.RUN.SUCCEEDED', 'ACTOR.RUN.FAILED']
```
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ indent-style = "space"
"**/__init__.py" = [
"F401", # Unused imports
]
"**/_models.py" = [
"TC001", # Pydantic needs the literal aliases importable at runtime to resolve forward references
]
"**/{scripts}/*" = [
"D", # Everything from the pydocstyle
"INP001", # File {filename} is part of an implicit namespace package, add an __init__.py
Expand Down
Loading
Loading