22
33from typing import TYPE_CHECKING , Any , Literal
44
5+ from apify_client ._models import Actor , Build , Run
56from apify_client ._utils import (
67 encode_key_value_store_record_value ,
78 encode_webhook_list_to_base64 ,
@@ -105,15 +106,16 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
105106 resource_path = kwargs .pop ('resource_path' , 'acts' )
106107 super ().__init__ (* args , resource_path = resource_path , ** kwargs )
107108
108- def get (self ) -> dict | None :
109+ def get (self ) -> Actor | None :
109110 """Retrieve the Actor.
110111
111112 https://docs.apify.com/api/v2#/reference/actors/actor-object/get-actor
112113
113114 Returns:
114115 The retrieved Actor.
115116 """
116- return self ._get ()
117+ result = self ._get ()
118+ return Actor .model_validate (result ) if result is not None else None
117119
118120 def update (
119121 self ,
@@ -143,7 +145,7 @@ def update(
143145 actor_standby_memory_mbytes : int | None = None ,
144146 pricing_infos : list [dict ] | None = None ,
145147 actor_permission_level : ActorPermissionLevel | None = None ,
146- ) -> dict :
148+ ) -> Actor :
147149 """Update the Actor with the specified fields.
148150
149151 https://docs.apify.com/api/v2#/reference/actors/actor-object/update-actor
@@ -211,7 +213,8 @@ def update(
211213 actor_permission_level = actor_permission_level ,
212214 )
213215
214- return self ._update (filter_out_none_values_recursively (actor_representation ))
216+ result = self ._update (filter_out_none_values_recursively (actor_representation ))
217+ return Actor .model_validate (result )
215218
216219 def delete (self ) -> None :
217220 """Delete the Actor.
@@ -234,7 +237,7 @@ def start(
234237 force_permission_level : ActorPermissionLevel | None = None ,
235238 wait_for_finish : int | None = None ,
236239 webhooks : list [dict ] | None = None ,
237- ) -> dict :
240+ ) -> Run :
238241 """Start the Actor and immediately return the Run object.
239242
240243 https://docs.apify.com/api/v2#/reference/actors/run-collection/run-actor
@@ -290,7 +293,8 @@ def start(
290293 params = request_params ,
291294 )
292295
293- return parse_date_fields (pluck_data (response .json ()))
296+ result = parse_date_fields (pluck_data (response .json ()))
297+ return Run .model_validate (result )
294298
295299 def call (
296300 self ,
@@ -307,7 +311,7 @@ def call(
307311 force_permission_level : ActorPermissionLevel | None = None ,
308312 wait_secs : int | None = None ,
309313 logger : Logger | None | Literal ['default' ] = 'default' ,
310- ) -> dict | None :
314+ ) -> Run | None :
311315 """Start the Actor and wait for it to finish before returning the Run object.
312316
313317 It waits indefinitely, unless the wait_secs argument is provided.
@@ -356,15 +360,15 @@ def call(
356360 force_permission_level = force_permission_level ,
357361 )
358362 if not logger :
359- return self .root_client .run (started_run [ 'id' ] ).wait_for_finish (wait_secs = wait_secs )
363+ return self .root_client .run (started_run . id ).wait_for_finish (wait_secs = wait_secs )
360364
361- run_client = self .root_client .run (run_id = started_run [ 'id' ] )
365+ run_client = self .root_client .run (run_id = started_run . id )
362366
363367 if logger == 'default' :
364368 logger = None
365369
366370 with run_client .get_status_message_watcher (to_logger = logger ), run_client .get_streamed_log (to_logger = logger ):
367- return self .root_client .run (started_run [ 'id' ] ).wait_for_finish (wait_secs = wait_secs )
371+ return self .root_client .run (started_run . id ).wait_for_finish (wait_secs = wait_secs )
368372
369373 def build (
370374 self ,
@@ -374,7 +378,7 @@ def build(
374378 tag : str | None = None ,
375379 use_cache : bool | None = None ,
376380 wait_for_finish : int | None = None ,
377- ) -> dict :
381+ ) -> Build :
378382 """Build the Actor.
379383
380384 https://docs.apify.com/api/v2#/reference/actors/build-collection/build-actor
@@ -408,7 +412,8 @@ def build(
408412 params = request_params ,
409413 )
410414
411- return parse_date_fields (pluck_data (response .json ()))
415+ result = parse_date_fields (pluck_data (response .json ()))
416+ return Build .model_validate (result )
412417
413418 def builds (self ) -> BuildCollectionClient :
414419 """Retrieve a client for the builds of this Actor."""
@@ -528,15 +533,16 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
528533 resource_path = kwargs .pop ('resource_path' , 'acts' )
529534 super ().__init__ (* args , resource_path = resource_path , ** kwargs )
530535
531- async def get (self ) -> dict | None :
536+ async def get (self ) -> Actor | None :
532537 """Retrieve the Actor.
533538
534539 https://docs.apify.com/api/v2#/reference/actors/actor-object/get-actor
535540
536541 Returns:
537542 The retrieved Actor.
538543 """
539- return await self ._get ()
544+ result = await self ._get ()
545+ return Actor .model_validate (result ) if result is not None else None
540546
541547 async def update (
542548 self ,
@@ -566,7 +572,7 @@ async def update(
566572 actor_standby_memory_mbytes : int | None = None ,
567573 pricing_infos : list [dict ] | None = None ,
568574 actor_permission_level : ActorPermissionLevel | None = None ,
569- ) -> dict :
575+ ) -> Actor :
570576 """Update the Actor with the specified fields.
571577
572578 https://docs.apify.com/api/v2#/reference/actors/actor-object/update-actor
@@ -634,7 +640,8 @@ async def update(
634640 actor_permission_level = actor_permission_level ,
635641 )
636642
637- return await self ._update (filter_out_none_values_recursively (actor_representation ))
643+ result = await self ._update (filter_out_none_values_recursively (actor_representation ))
644+ return Actor .model_validate (result )
638645
639646 async def delete (self ) -> None :
640647 """Delete the Actor.
@@ -657,7 +664,7 @@ async def start(
657664 force_permission_level : ActorPermissionLevel | None = None ,
658665 wait_for_finish : int | None = None ,
659666 webhooks : list [dict ] | None = None ,
660- ) -> dict :
667+ ) -> Run :
661668 """Start the Actor and immediately return the Run object.
662669
663670 https://docs.apify.com/api/v2#/reference/actors/run-collection/run-actor
@@ -713,7 +720,8 @@ async def start(
713720 params = request_params ,
714721 )
715722
716- return parse_date_fields (pluck_data (response .json ()))
723+ result = parse_date_fields (pluck_data (response .json ()))
724+ return Run .model_validate (result )
717725
718726 async def call (
719727 self ,
@@ -730,7 +738,7 @@ async def call(
730738 force_permission_level : ActorPermissionLevel | None = None ,
731739 wait_secs : int | None = None ,
732740 logger : Logger | None | Literal ['default' ] = 'default' ,
733- ) -> dict | None :
741+ ) -> Run | None :
734742 """Start the Actor and wait for it to finish before returning the Run object.
735743
736744 It waits indefinitely, unless the wait_secs argument is provided.
@@ -780,9 +788,9 @@ async def call(
780788 )
781789
782790 if not logger :
783- return await self .root_client .run (started_run [ 'id' ] ).wait_for_finish (wait_secs = wait_secs )
791+ return await self .root_client .run (started_run . id ).wait_for_finish (wait_secs = wait_secs )
784792
785- run_client = self .root_client .run (run_id = started_run [ 'id' ] )
793+ run_client = self .root_client .run (run_id = started_run . id )
786794
787795 if logger == 'default' :
788796 logger = None
@@ -791,7 +799,7 @@ async def call(
791799 streamed_log = await run_client .get_streamed_log (to_logger = logger )
792800
793801 async with status_redirector , streamed_log :
794- return await self .root_client .run (started_run [ 'id' ] ).wait_for_finish (wait_secs = wait_secs )
802+ return await self .root_client .run (started_run . id ).wait_for_finish (wait_secs = wait_secs )
795803
796804 async def build (
797805 self ,
@@ -801,7 +809,7 @@ async def build(
801809 tag : str | None = None ,
802810 use_cache : bool | None = None ,
803811 wait_for_finish : int | None = None ,
804- ) -> dict :
812+ ) -> Build :
805813 """Build the Actor.
806814
807815 https://docs.apify.com/api/v2#/reference/actors/build-collection/build-actor
@@ -835,7 +843,8 @@ async def build(
835843 params = request_params ,
836844 )
837845
838- return parse_date_fields (pluck_data (response .json ()))
846+ result = parse_date_fields (pluck_data (response .json ()))
847+ return Build .model_validate (result )
839848
840849 def builds (self ) -> BuildCollectionClientAsync :
841850 """Retrieve a client for the builds of this Actor."""
0 commit comments