1
1
from __future__ import annotations
2
2
3
+ import logging
3
4
from typing import TYPE_CHECKING , Any
4
5
5
6
from apify_shared .utils import (
9
10
parse_date_fields ,
10
11
)
11
12
12
- from apify_client ._utils import encode_key_value_store_record_value , encode_webhook_list_to_base64 , pluck_data
13
+ from apify_client ._utils import _to_json , encode_webhook_list_to_base64 , pluck_data
13
14
from apify_client .clients .base import ResourceClient , ResourceClientAsync
14
15
from apify_client .clients .resource_clients .actor_version import ActorVersionClient , ActorVersionClientAsync
15
16
from apify_client .clients .resource_clients .actor_version_collection import (
30
31
31
32
from apify_shared .consts import ActorJobStatus , MetaOrigin
32
33
34
+ logger = logging .getLogger (__name__ )
35
+
33
36
34
37
def get_actor_representation (
35
38
* ,
@@ -216,7 +219,7 @@ def delete(self) -> None:
216
219
def start (
217
220
self ,
218
221
* ,
219
- run_input : Any = None ,
222
+ run_input : str | dict | None = None ,
220
223
content_type : str | None = None ,
221
224
build : str | None = None ,
222
225
max_items : int | None = None ,
@@ -232,7 +235,7 @@ def start(
232
235
233
236
Args:
234
237
run_input: The input to pass to the Actor run.
235
- content_type: The content type of the input .
238
+ content_type: Deprecated .
236
239
build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
237
240
the run uses the build specified in the default run configuration for the Actor (typically latest).
238
241
max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -255,7 +258,11 @@ def start(
255
258
Returns:
256
259
The run object.
257
260
"""
258
- run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
261
+ if content_type :
262
+ logger .warning ('`content_type` is deprecated and not used anymore.' )
263
+
264
+ if not isinstance (run_input , str ):
265
+ run_input = _to_json (run_input )
259
266
260
267
request_params = self ._params (
261
268
build = build ,
@@ -270,7 +277,7 @@ def start(
270
277
response = self .http_client .call (
271
278
url = self ._url ('runs' ),
272
279
method = 'POST' ,
273
- headers = {'content-type' : content_type },
280
+ headers = {'content-type' : 'application/json' },
274
281
data = run_input ,
275
282
params = request_params ,
276
283
)
@@ -459,6 +466,27 @@ def webhooks(self) -> WebhookCollectionClient:
459
466
"""Retrieve a client for webhooks associated with this Actor."""
460
467
return WebhookCollectionClient (** self ._sub_resource_init_options ())
461
468
469
+ def validate_input (self , run_input : str | bytes | dict | None = None ) -> bool :
470
+ """Validate the input for the Actor.
471
+
472
+ Args:
473
+ run_input: The input to validate. Either dictionary or json in bytes or str.
474
+
475
+ Returns:
476
+ True if the input is valid, else raise an exception with validation error details.
477
+ """
478
+ if not isinstance (run_input , str ):
479
+ run_input = _to_json (run_input )
480
+
481
+ self .http_client .call (
482
+ url = self ._url ('validate-input' ),
483
+ method = 'POST' ,
484
+ headers = {'content-type' : 'application/json' },
485
+ data = run_input ,
486
+ )
487
+
488
+ return True
489
+
462
490
463
491
class ActorClientAsync (ResourceClientAsync ):
464
492
"""Async sub-client for manipulating a single Actor."""
@@ -583,7 +611,7 @@ async def delete(self) -> None:
583
611
async def start (
584
612
self ,
585
613
* ,
586
- run_input : Any = None ,
614
+ run_input : str | dict | None = None ,
587
615
content_type : str | None = None ,
588
616
build : str | None = None ,
589
617
max_items : int | None = None ,
@@ -599,7 +627,7 @@ async def start(
599
627
600
628
Args:
601
629
run_input: The input to pass to the Actor run.
602
- content_type: The content type of the input .
630
+ content_type: Deprecated .
603
631
build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
604
632
the run uses the build specified in the default run configuration for the Actor (typically latest).
605
633
max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -622,7 +650,11 @@ async def start(
622
650
Returns:
623
651
The run object.
624
652
"""
625
- run_input , content_type = encode_key_value_store_record_value (run_input , content_type )
653
+ if content_type :
654
+ logger .warning ('`content_type` is deprecated and not used anymore.' )
655
+
656
+ if not isinstance (run_input , str ):
657
+ run_input = _to_json (run_input )
626
658
627
659
request_params = self ._params (
628
660
build = build ,
@@ -637,7 +669,7 @@ async def start(
637
669
response = await self .http_client .call (
638
670
url = self ._url ('runs' ),
639
671
method = 'POST' ,
640
- headers = {'content-type' : content_type },
672
+ headers = {'content-type' : 'application/json' },
641
673
data = run_input ,
642
674
params = request_params ,
643
675
)
@@ -829,3 +861,24 @@ def version(self, version_number: str) -> ActorVersionClientAsync:
829
861
def webhooks (self ) -> WebhookCollectionClientAsync :
830
862
"""Retrieve a client for webhooks associated with this Actor."""
831
863
return WebhookCollectionClientAsync (** self ._sub_resource_init_options ())
864
+
865
+ async def validate_input (self , run_input : str | dict | None = None ) -> bool :
866
+ """Validate the input for the Actor.
867
+
868
+ Args:
869
+ run_input: The input to validate. Either json string or a dictionary.
870
+
871
+ Returns:
872
+ True if the input is valid, else raise an exception with validation error details.
873
+ """
874
+ if not isinstance (run_input , str ):
875
+ run_input = _to_json (run_input )
876
+
877
+ await self .http_client .call (
878
+ url = self ._url ('validate-input' ),
879
+ method = 'POST' ,
880
+ headers = {'content-type' : 'application/json' },
881
+ data = run_input ,
882
+ )
883
+
884
+ return True
0 commit comments