Skip to content

Commit 24a6fa8

Browse files
vdusekclaude
andcommitted
refactor!: adapt to apify-client v3
Bump apify-client to v3 (>=3.0.0,<4.0.0) and re-use its models, literals, and constants instead of maintaining SDK-side duplicates. - Replace SDK models with apify-client equivalents (e.g. `Run` instead of `ActorRun`) and import pricing models from the client; remove the now redundant `src/apify/_models.py`. - Drop the `apify-shared` dependency and define the few needed constants locally in `_consts.py`. - Adapt `Actor.start`/`call`/`call_task` to the v3 `run_timeout` API and tolerate platform pricing-info env var omissions. - Adapt the Apify storage clients (dataset, key-value store, request queue) to the v3 client surface. - Refresh `uv.lock` (apify-client 3.0.2, drops apify-shared, adds dnspython/email-validator). - Align unit, integration, and e2e tests with the v3 type and model changes. BREAKING CHANGE: requires apify-client v3; SDK-side model and literal duplicates are removed in favor of those exported by apify-client. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b9578dc commit 24a6fa8

48 files changed

Lines changed: 1115 additions & 816 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/02_concepts/code/07_webhook.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import asyncio
22

3-
from apify import Actor, Webhook, WebhookEventType
3+
from apify import Actor, WebhookCondition, WebhookCreate
44

55

66
async def main() -> None:
77
async with Actor:
88
# Create a webhook that will be triggered when the Actor run fails.
9-
webhook = Webhook(
10-
event_types=[WebhookEventType.ACTOR_RUN_FAILED],
9+
webhook = WebhookCreate(
10+
event_types=['ACTOR.RUN.FAILED'],
1111
request_url='https://example.com/run-failed',
12+
condition=WebhookCondition(),
1213
)
1314

1415
# Add the webhook to the Actor.

docs/02_concepts/code/07_webhook_preventing.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import asyncio
22

3-
from apify import Actor, Webhook, WebhookEventType
3+
from apify import Actor, WebhookCondition, WebhookCreate
44

55

66
async def main() -> None:
77
async with Actor:
88
# Create a webhook that will be triggered when the Actor run fails.
9-
webhook = Webhook(
10-
event_types=[WebhookEventType.ACTOR_RUN_FAILED],
9+
webhook = WebhookCreate(
10+
event_types=['ACTOR.RUN.FAILED'],
1111
request_url='https://example.com/run-failed',
12+
condition=WebhookCondition(),
13+
idempotency_key=Actor.configuration.actor_run_id,
1214
)
1315

1416
# Add the webhook to the Actor.
15-
await Actor.add_webhook(webhook, idempotency_key=Actor.configuration.actor_run_id)
17+
await Actor.add_webhook(webhook)
1618

1719
# Raise an error to simulate a failed run.
1820
raise RuntimeError('I am an error and I know it!')

docs/04_upgrading/upgrading_to_v3.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,41 @@ Some changes in the related model classes:
6767
- `stats` field in `RequestQueueMetadata` - removed as it was unused.
6868
- `RequestQueueHead` - replaced by `RequestQueueHeadWithLocks`.
6969

70+
## Webhook model changes
71+
72+
The SDK no longer ships its own `Webhook` Pydantic model. The webhook models from `apify-client` are now used directly:
73+
74+
- `apify.Webhook` is now an alias of `apify_client._models.WebhookRepresentation`. It still has the same shape used in `Actor.start`, `Actor.call`, and `Actor.call_task` (`event_types`, `request_url`, `payload_template`, `headers_template`).
75+
- `Actor.add_webhook` now accepts an `apify.WebhookCreate` instance instead of `apify.Webhook` + separate kwargs. All fields (`ignore_ssl_errors`, `do_not_retry`, `idempotency_key`, `headers_template`, etc.) move onto the `WebhookCreate` instance. `condition` is required by the underlying type — pass `WebhookCondition()` when you do not need to scope to other resources.
76+
77+
**Before (v2.x):**
78+
79+
```python
80+
from apify import Actor, Webhook
81+
82+
await Actor.add_webhook(
83+
Webhook(event_types=['ACTOR.RUN.FAILED'], request_url='https://example.com'),
84+
idempotency_key='my-key',
85+
)
86+
```
87+
88+
**Now (v3.0):**
89+
90+
```python
91+
from apify import Actor, WebhookCondition, WebhookCreate
92+
93+
await Actor.add_webhook(
94+
WebhookCreate(
95+
event_types=['ACTOR.RUN.FAILED'],
96+
request_url='https://example.com',
97+
condition=WebhookCondition(),
98+
idempotency_key='my-key',
99+
)
100+
)
101+
```
102+
103+
`WebhookCondition`, `WebhookCreate`, `WebhookRepresentation`, `WebhookEventType`, and `ActorPermissionLevel` are all re-exported from `apify` for convenience.
104+
70105
## Removed Actor.config property
71106
- `Actor.config` property has been removed. Use `Actor.configuration` instead.
72107

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ keywords = [
3434
"scraping",
3535
]
3636
dependencies = [
37-
"apify-client>=2.3.0,<3.0.0",
38-
"apify-shared>=2.0.0,<3.0.0",
37+
"apify-client>=3.0.0,<4.0.0",
3938
"crawlee>=1.0.4,<2.0.0",
4039
"cachetools>=5.5.0",
4140
"cryptography>=42.0.0",
4241
"impit>=0.8.0",
4342
"lazy-object-proxy>=1.11.0",
4443
"more_itertools>=10.2.0",
45-
"pydantic>=2.11.0",
44+
"pydantic[email]>=2.11.0",
4645
"typing-extensions>=4.1.0",
4746
"websockets>=14.0",
4847
"yarl>=1.18.0",
@@ -197,7 +196,7 @@ builtins-ignorelist = ["id"]
197196

198197
[tool.ruff.lint.isort]
199198
known-local-folder = ["apify"]
200-
known-first-party = ["apify_client", "apify_shared", "crawlee"]
199+
known-first-party = ["apify_client", "crawlee"]
201200

202201
[tool.ruff.lint.pylint]
203202
max-branches = 18

src/apify/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from importlib import metadata
22

3-
from apify_shared.consts import WebhookEventType
3+
from apify_client._literals import ActorPermissionLevel, WebhookEventType
4+
from apify_client._models import WebhookCondition, WebhookCreate, WebhookRepresentation
5+
from apify_client._models import WebhookRepresentation as Webhook
46
from crawlee import Request
57
from crawlee.events import (
68
Event,
@@ -14,13 +16,13 @@
1416

1517
from apify._actor import Actor
1618
from apify._configuration import Configuration
17-
from apify._models import Webhook
1819
from apify._proxy_configuration import ProxyConfiguration, ProxyInfo
1920

2021
__version__ = metadata.version('apify')
2122

2223
__all__ = [
2324
'Actor',
25+
'ActorPermissionLevel',
2426
'Configuration',
2527
'Event',
2628
'EventAbortingData',
@@ -33,6 +35,9 @@
3335
'ProxyInfo',
3436
'Request',
3537
'Webhook',
38+
'WebhookCondition',
39+
'WebhookCreate',
3640
'WebhookEventType',
41+
'WebhookRepresentation',
3742
'__version__',
3843
]

0 commit comments

Comments
 (0)