Skip to content

Commit 05a8aba

Browse files
vdusekclaude
andcommitted
Replace SDK models with apify-client models: use Run instead of ActorRun, import pricing models from client
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 05cf57e commit 05a8aba

13 files changed

Lines changed: 81 additions & 356 deletions

‎src/apify/_actor.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from apify._configuration import Configuration
3030
from apify._consts import EVENT_LISTENERS_TIMEOUT, ActorEnvVars, ActorExitCodes, ApifyEnvVars
3131
from apify._crypto import decrypt_input_secrets, load_private_key
32-
from apify._models import ActorRun
3332
from apify._proxy_configuration import ProxyConfiguration
3433
from apify._utils import docs_group, docs_name, ensure_context, get_system_info, is_running_in_ipython
3534
from apify.events import ApifyEventManager, EventManager, LocalEventManager
@@ -44,6 +43,7 @@
4443
from types import TracebackType
4544
from typing import Self
4645

46+
from apify_client._models import Run
4747
from crawlee._types import JsonSerializable
4848
from crawlee.proxy_configuration import _NewUrlFunction
4949

@@ -869,7 +869,7 @@ async def start(
869869
timeout: timedelta | None | Literal['inherit', 'RemainingTime'] = None,
870870
wait_for_finish: int | None = None,
871871
webhooks: list[Webhook] | None = None,
872-
) -> ActorRun:
872+
) -> Run:
873873
"""Run an Actor on the Apify platform.
874874
875875
Unlike `Actor.call`, this method just starts the run without waiting for finish.
@@ -935,7 +935,7 @@ async def start(
935935
if run is None:
936936
raise RuntimeError(f'Failed to start Actor with ID "{actor_id}".')
937937

938-
return ActorRun.from_client_actor_run(run)
938+
return run
939939

940940
@_ensure_context
941941
async def abort(
@@ -945,7 +945,7 @@ async def abort(
945945
token: str | None = None,
946946
status_message: str | None = None,
947947
gracefully: bool | None = None,
948-
) -> ActorRun:
948+
) -> Run:
949949
"""Abort given Actor run on the Apify platform using the current user account.
950950
951951
The user account is determined by the `APIFY_TOKEN` environment variable.
@@ -972,7 +972,7 @@ async def abort(
972972
if run is None:
973973
raise RuntimeError(f'Failed to abort Actor run with ID "{run_id}".')
974974

975-
return ActorRun.from_client_actor_run(run)
975+
return run
976976

977977
@_ensure_context
978978
async def call(
@@ -988,7 +988,7 @@ async def call(
988988
webhooks: list[Webhook] | None = None,
989989
wait: timedelta | None = None,
990990
logger: logging.Logger | None | Literal['default'] = 'default',
991-
) -> ActorRun | None:
991+
) -> Run | None:
992992
"""Start an Actor on the Apify Platform and wait for it to finish before returning.
993993
994994
It waits indefinitely, unless the wait argument is provided.
@@ -1059,7 +1059,7 @@ async def call(
10591059
if run is None:
10601060
raise RuntimeError(f'Failed to call Actor with ID "{actor_id}".')
10611061

1062-
return ActorRun.from_client_actor_run(run)
1062+
return run
10631063

10641064
@_ensure_context
10651065
async def call_task(
@@ -1073,7 +1073,7 @@ async def call_task(
10731073
webhooks: list[Webhook] | None = None,
10741074
wait: timedelta | None = None,
10751075
token: str | None = None,
1076-
) -> ActorRun | None:
1076+
) -> Run | None:
10771077
"""Start an Actor task on the Apify Platform and wait for it to finish before returning.
10781078
10791079
It waits indefinitely, unless the wait argument is provided.
@@ -1133,7 +1133,7 @@ async def call_task(
11331133
if run is None:
11341134
raise RuntimeError(f'Failed to call Task with ID "{task_id}".')
11351135

1136-
return ActorRun.from_client_actor_run(run)
1136+
return run
11371137

11381138
@_ensure_context
11391139
async def metamorph(
@@ -1292,7 +1292,7 @@ async def set_status_message(
12921292
status_message: str,
12931293
*,
12941294
is_terminal: bool | None = None,
1295-
) -> ActorRun | None:
1295+
) -> Run | None:
12961296
"""Set the status message for the current Actor run.
12971297
12981298
Args:
@@ -1322,7 +1322,7 @@ async def set_status_message(
13221322
f'Failed to set status message for Actor run with ID "{self.configuration.actor_run_id}".'
13231323
)
13241324

1325-
return ActorRun.from_client_actor_run(run)
1325+
return run
13261326

13271327
@_ensure_context
13281328
async def create_proxy_configuration(

‎src/apify/_charging.py‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
from decimal import Decimal
88
from typing import TYPE_CHECKING, Protocol, TypedDict
99

10-
from pydantic import TypeAdapter
11-
12-
from apify._models import (
13-
ActorRun,
10+
from apify_client._models import (
1411
FlatPricePerMonthActorPricingInfo,
1512
FreeActorPricingInfo,
1613
PayPerEventActorPricingInfo,
1714
PricePerDatasetItemActorPricingInfo,
18-
PricingModel,
1915
)
16+
2017
from apify._utils import ReentrantLock, docs_group, ensure_context
2118
from apify.log import logger
2219
from apify.storages import Dataset
@@ -27,8 +24,7 @@
2724
from apify_client import ApifyClientAsync
2825

2926
from apify._configuration import Configuration
30-
31-
run_validator = TypeAdapter[ActorRun | None](ActorRun | None)
27+
from apify._models import PricingModel
3228

3329
DEFAULT_DATASET_ITEM_EVENT = 'apify-default-dataset-item'
3430

@@ -426,15 +422,10 @@ async def _fetch_pricing_info(self) -> _FetchedPricingInfoDict:
426422
if run is None:
427423
raise RuntimeError('Actor run not found')
428424

429-
actor_run = ActorRun.from_client_actor_run(run)
430-
431-
if actor_run is None:
432-
raise RuntimeError('Actor run not found')
433-
434-
max_charge = actor_run.options.max_total_charge_usd
425+
max_charge = run.options.max_total_charge_usd
435426
return _FetchedPricingInfoDict(
436-
pricing_info=actor_run.pricing_info,
437-
charged_event_counts=actor_run.charged_event_counts or {},
427+
pricing_info=run.pricing_info,
428+
charged_event_counts=run.charged_event_counts or {},
438429
max_total_charge_usd=Decimal(str(max_charge)) if max_charge is not None else Decimal('inf'),
439430
)
440431

‎src/apify/_configuration.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
from pydantic import AliasChoices, BeforeValidator, Field, model_validator
1111
from typing_extensions import TypedDict, deprecated
1212

13-
from crawlee import service_locator
14-
from crawlee._utils.models import timedelta_ms
15-
from crawlee._utils.urls import validate_http_url
16-
from crawlee.configuration import Configuration as CrawleeConfiguration
17-
18-
from apify._models import (
13+
from apify_client._models import (
1914
FlatPricePerMonthActorPricingInfo,
2015
FreeActorPricingInfo,
2116
PayPerEventActorPricingInfo,
2217
PricePerDatasetItemActorPricingInfo,
2318
)
19+
from crawlee import service_locator
20+
from crawlee._utils.models import timedelta_ms
21+
from crawlee._utils.urls import validate_http_url
22+
from crawlee.configuration import Configuration as CrawleeConfiguration
23+
2424
from apify._utils import docs_group
2525

2626
logger = getLogger(__name__)

0 commit comments

Comments
 (0)