Skip to content
Draft
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
7 changes: 4 additions & 3 deletions docs/02_concepts/code/07_webhook.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import asyncio

from apify import Actor, Webhook, WebhookEventType
from apify import Actor, WebhookCondition, WebhookCreate


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

# Add the webhook to the Actor.
Expand Down
10 changes: 6 additions & 4 deletions docs/02_concepts/code/07_webhook_preventing.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import asyncio

from apify import Actor, Webhook, WebhookEventType
from apify import Actor, WebhookCondition, WebhookCreate


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

# Add the webhook to the Actor.
await Actor.add_webhook(webhook, idempotency_key=Actor.configuration.actor_run_id)
await Actor.add_webhook(webhook)

# Raise an error to simulate a failed run.
raise RuntimeError('I am an error and I know it!')
Expand Down
35 changes: 35 additions & 0 deletions docs/04_upgrading/upgrading_to_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,41 @@ Some changes in the related model classes:
- `stats` field in `RequestQueueMetadata` - removed as it was unused.
- `RequestQueueHead` - replaced by `RequestQueueHeadWithLocks`.

## Webhook model changes

The SDK no longer ships its own `Webhook` Pydantic model. The webhook models from `apify-client` are now used directly:

- `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`).
- `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.

**Before (v2.x):**

```python
from apify import Actor, Webhook

await Actor.add_webhook(
Webhook(event_types=['ACTOR.RUN.FAILED'], request_url='https://example.com'),
idempotency_key='my-key',
)
```

**Now (v3.0):**

```python
from apify import Actor, WebhookCondition, WebhookCreate

await Actor.add_webhook(
WebhookCreate(
event_types=['ACTOR.RUN.FAILED'],
request_url='https://example.com',
condition=WebhookCondition(),
idempotency_key='my-key',
)
)
```

`WebhookCondition`, `WebhookCreate`, `WebhookRepresentation`, `WebhookEventType`, and `ActorPermissionLevel` are all re-exported from `apify` for convenience.

## Removed Actor.config property
- `Actor.config` property has been removed. Use `Actor.configuration` instead.

Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ keywords = [
"scraping",
]
dependencies = [
"apify-client>=2.3.0,<3.0.0",
"apify-shared>=2.0.0,<3.0.0",
"apify-client>=3.0.0,<4.0.0",
"crawlee>=1.0.4,<2.0.0",
"cachetools>=5.5.0",
"cryptography>=42.0.0",
"impit>=0.8.0",
"lazy-object-proxy>=1.11.0",
"more_itertools>=10.2.0",
"pydantic>=2.11.0",
"pydantic[email]>=2.11.0",
"typing-extensions>=4.1.0",
"websockets>=14.0",
"yarl>=1.18.0",
Expand Down Expand Up @@ -197,7 +196,7 @@ builtins-ignorelist = ["id"]

[tool.ruff.lint.isort]
known-local-folder = ["apify"]
known-first-party = ["apify_client", "apify_shared", "crawlee"]
known-first-party = ["apify_client", "crawlee"]

[tool.ruff.lint.pylint]
max-branches = 18
Expand Down
9 changes: 7 additions & 2 deletions src/apify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from importlib import metadata

from apify_shared.consts import WebhookEventType
from apify_client._literals import ActorPermissionLevel, WebhookEventType
from apify_client._models import WebhookCondition, WebhookCreate, WebhookRepresentation
from apify_client._models import WebhookRepresentation as Webhook
from crawlee import Request
from crawlee.events import (
Event,
Expand All @@ -14,13 +16,13 @@

from apify._actor import Actor
from apify._configuration import Configuration
from apify._models import Webhook
from apify._proxy_configuration import ProxyConfiguration, ProxyInfo

__version__ = metadata.version('apify')

__all__ = [
'Actor',
'ActorPermissionLevel',
'Configuration',
'Event',
'EventAbortingData',
Expand All @@ -33,6 +35,9 @@
'ProxyInfo',
'Request',
'Webhook',
'WebhookCondition',
'WebhookCreate',
'WebhookEventType',
'WebhookRepresentation',
'__version__',
]
Loading