diff --git a/src/apify_client/_resource_clients/actor.py b/src/apify_client/_resource_clients/actor.py index 6babb2c3b..4cf0f362d 100644 --- a/src/apify_client/_resource_clients/actor.py +++ b/src/apify_client/_resource_clients/actor.py @@ -57,7 +57,7 @@ WebhookCollectionClient, WebhookCollectionClientAsync, ) - from apify_client.types import Timeout, WebhooksList + from apify_client.types import ActorInput, Timeout, WebhooksList _PricingInfo = ( PayPerEventActorPricingInfo @@ -279,7 +279,7 @@ def delete(self, *, timeout: Timeout = 'short') -> None: def start( self, *, - run_input: Any = None, + run_input: ActorInput | None = None, content_type: str | None = None, build: str | None = None, max_items: int | None = None, @@ -298,10 +298,9 @@ def start( https://docs.apify.com/api/v2#/reference/actors/run-collection/run-actor Args: - run_input: The input to pass to the Actor run. Accepts the same values as - `KeyValueStoreClient.set_record`, including an `io.IOBase` stream such as an open file, an iterable - of byte chunks, or a streamed `HttpResponse`, which are uploaded in chunks without being held in - memory. Streaming is experimental, and its behavior may change in future versions. + run_input: The input to pass to the Actor run. See `ActorInput` for the accepted values. A stream, such as + an open file, an iterable of byte chunks, or a streamed `HttpResponse`, is uploaded in chunks without + being held in memory. Streaming is experimental, and its behavior may change in future versions. content_type: The content type of the input. build: Specifies the Actor build to run. It can be either a build tag or build number. By default, the run uses the build specified in the default run configuration for the Actor (typically latest). @@ -373,7 +372,7 @@ def start( def call( self, *, - run_input: Any = None, + run_input: ActorInput | None = None, content_type: str | None = None, build: str | None = None, max_items: int | None = None, @@ -395,10 +394,9 @@ def call( https://docs.apify.com/api/v2#/reference/actors/run-collection/run-actor Args: - run_input: The input to pass to the Actor run. Accepts the same values as - `KeyValueStoreClient.set_record`, including an `io.IOBase` stream such as an open file, an iterable - of byte chunks, or a streamed `HttpResponse`, which are uploaded in chunks without being held in - memory. Streaming is experimental, and its behavior may change in future versions. + run_input: The input to pass to the Actor run. See `ActorInput` for the accepted values. A stream, such as + an open file, an iterable of byte chunks, or a streamed `HttpResponse`, is uploaded in chunks without + being held in memory. Streaming is experimental, and its behavior may change in future versions. content_type: The content type of the input. build: Specifies the Actor build to run. It can be either a build tag or build number. By default, the run uses the build specified in the default run configuration for the Actor (typically latest). @@ -616,7 +614,7 @@ def webhooks(self) -> WebhookCollectionClient: def validate_input( self, - run_input: Any = None, + run_input: ActorInput | None = None, *, build: str | None = None, content_type: str | None = None, @@ -626,10 +624,9 @@ def validate_input( """Validate an input for the Actor that defines an input schema. Args: - run_input: The input to validate. Accepts the same values as `KeyValueStoreClient.set_record`, - including an `io.IOBase` stream such as an open file, an iterable of byte chunks, or a streamed - `HttpResponse`, which are uploaded in chunks without being held in memory. Streaming is experimental, - and its behavior may change in future versions. + run_input: The input to validate. See `ActorInput` for the accepted values. A stream, such as an open file, + an iterable of byte chunks, or a streamed `HttpResponse`, is uploaded in chunks without being held in + memory. Streaming is experimental, and its behavior may change in future versions. build: The Actor build to validate the input against. It can be either a build tag or build number. By default, the build specified in the default run configuration for the Actor (typically latest) is used. content_type: The content type of the input. @@ -913,7 +910,7 @@ async def delete(self, *, timeout: Timeout = 'short') -> None: async def start( self, *, - run_input: Any = None, + run_input: ActorInput | None = None, content_type: str | None = None, build: str | None = None, max_items: int | None = None, @@ -932,10 +929,9 @@ async def start( https://docs.apify.com/api/v2#/reference/actors/run-collection/run-actor Args: - run_input: The input to pass to the Actor run. Accepts the same values as - `KeyValueStoreClientAsync.set_record`, including an `io.IOBase` stream such as an open file, an iterable - of byte chunks, or a streamed `HttpResponse`, which are uploaded in chunks without being held in - memory. Streaming is experimental, and its behavior may change in future versions. + run_input: The input to pass to the Actor run. See `ActorInput` for the accepted values. A stream, such as + an open file, an iterable of byte chunks, or a streamed `HttpResponse`, is uploaded in chunks without + being held in memory. Streaming is experimental, and its behavior may change in future versions. content_type: The content type of the input. build: Specifies the Actor build to run. It can be either a build tag or build number. By default, the run uses the build specified in the default run configuration for the Actor (typically latest). @@ -1007,7 +1003,7 @@ async def start( async def call( self, *, - run_input: Any = None, + run_input: ActorInput | None = None, content_type: str | None = None, build: str | None = None, max_items: int | None = None, @@ -1029,10 +1025,9 @@ async def call( https://docs.apify.com/api/v2#/reference/actors/run-collection/run-actor Args: - run_input: The input to pass to the Actor run. Accepts the same values as - `KeyValueStoreClientAsync.set_record`, including an `io.IOBase` stream such as an open file, an iterable - of byte chunks, or a streamed `HttpResponse`, which are uploaded in chunks without being held in - memory. Streaming is experimental, and its behavior may change in future versions. + run_input: The input to pass to the Actor run. See `ActorInput` for the accepted values. A stream, such as + an open file, an iterable of byte chunks, or a streamed `HttpResponse`, is uploaded in chunks without + being held in memory. Streaming is experimental, and its behavior may change in future versions. content_type: The content type of the input. build: Specifies the Actor build to run. It can be either a build tag or build number. By default, the run uses the build specified in the default run configuration for the Actor (typically latest). @@ -1251,7 +1246,7 @@ def webhooks(self) -> WebhookCollectionClientAsync: async def validate_input( self, - run_input: Any = None, + run_input: ActorInput | None = None, *, build: str | None = None, content_type: str | None = None, @@ -1261,10 +1256,9 @@ async def validate_input( """Validate an input for the Actor that defines an input schema. Args: - run_input: The input to validate. Accepts the same values as `KeyValueStoreClientAsync.set_record`, - including an `io.IOBase` stream such as an open file, an iterable of byte chunks, or a streamed - `HttpResponse`, which are uploaded in chunks without being held in memory. Streaming is experimental, - and its behavior may change in future versions. + run_input: The input to validate. See `ActorInput` for the accepted values. A stream, such as an open file, + an iterable of byte chunks, or a streamed `HttpResponse`, is uploaded in chunks without being held in + memory. Streaming is experimental, and its behavior may change in future versions. build: The Actor build to validate the input against. It can be either a build tag or build number. By default, the build specified in the default run configuration for the Actor (typically latest) is used. content_type: The content type of the input. diff --git a/src/apify_client/_resource_clients/run.py b/src/apify_client/_resource_clients/run.py index 8947e81aa..519c357b3 100644 --- a/src/apify_client/_resource_clients/run.py +++ b/src/apify_client/_resource_clients/run.py @@ -36,7 +36,7 @@ RequestQueueClientAsync, ) from apify_client._resource_clients.dataset import DatasetItemsPage - from apify_client.types import Timeout + from apify_client.types import ActorInput, Timeout @docs_group('Resource clients') @@ -175,7 +175,7 @@ def metamorph( *, target_actor_id: str, target_actor_build: str | None = None, - run_input: Any = None, + run_input: ActorInput | None = None, content_type: str | None = None, timeout: Timeout = 'medium', ) -> Run: @@ -188,10 +188,9 @@ def metamorph( target_actor_build: The build of the target Actor. It can be either a build tag or build number. By default, the run uses the build specified in the default run configuration for the target Actor (typically the latest build). - run_input: The input to pass to the new run. Accepts the same values as - `KeyValueStoreClient.set_record`, including an `io.IOBase` stream such as an open file, an iterable - of byte chunks, or a streamed `HttpResponse`, which are uploaded in chunks without being held in - memory. Streaming is experimental, and its behavior may change in future versions. + run_input: The input to pass to the new run. See `ActorInput` for the accepted values. A stream, such as an + open file, an iterable of byte chunks, or a streamed `HttpResponse`, is uploaded in chunks without being + held in memory. Streaming is experimental, and its behavior may change in future versions. content_type: The content type of the input. timeout: Timeout for the API HTTP request. @@ -771,7 +770,7 @@ async def metamorph( *, target_actor_id: str, target_actor_build: str | None = None, - run_input: Any = None, + run_input: ActorInput | None = None, content_type: str | None = None, timeout: Timeout = 'medium', ) -> Run: @@ -784,10 +783,9 @@ async def metamorph( target_actor_build: The build of the target Actor. It can be either a build tag or build number. By default, the run uses the build specified in the default run configuration for the target Actor (typically the latest build). - run_input: The input to pass to the new run. Accepts the same values as - `KeyValueStoreClientAsync.set_record`, including an `io.IOBase` stream such as an open file, an iterable - of byte chunks, or a streamed `HttpResponse`, which are uploaded in chunks without being held in - memory. Streaming is experimental, and its behavior may change in future versions. + run_input: The input to pass to the new run. See `ActorInput` for the accepted values. A stream, such as an + open file, an iterable of byte chunks, or a streamed `HttpResponse`, is uploaded in chunks without being + held in memory. Streaming is experimental, and its behavior may change in future versions. content_type: The content type of the input. timeout: Timeout for the API HTTP request. diff --git a/src/apify_client/types.py b/src/apify_client/types.py index d66fa5988..e6d8cca2e 100644 --- a/src/apify_client/types.py +++ b/src/apify_client/types.py @@ -3,7 +3,7 @@ from collections.abc import AsyncIterable, Iterable, Mapping, Sequence from datetime import datetime, timedelta from decimal import Decimal -from typing import IO, TYPE_CHECKING, Literal, Protocol +from typing import IO, TYPE_CHECKING, Any, Literal, Protocol from apify_client._models import CreateWebhookRequest, WebhookRepresentation from apify_client._typeddicts import ( @@ -102,6 +102,14 @@ def read(self) -> bytes | str | Awaitable[bytes | str]: Streaming is experimental, and its behavior and interface may change in future versions. """ +ActorInput = Mapping[str, Any] | Sequence[Mapping[str, Any]] | bytes | bytearray | str | StreamedBodySource +"""Type for the `run_input` parameter on Actor `start`, `call`, and `validate_input`, and on run `metamorph`. + +A `dict`, or a list or tuple of `dict`s, is serialized to JSON when `content_type` is unset or JSON. Bytes and a string +are sent as they are, typically with a `content_type`, and a `StreamedBodySource` is streamed to the API in chunks. An +Actor with an input schema accepts only a JSON object. +""" + JsonSerializable = Mapping[str, 'JsonSerializable'] | Sequence['JsonSerializable'] | str | int | float | bool | None """Recursive type for JSON-serializable values - primitives plus objects and arrays with JSON-serializable contents. @@ -109,6 +117,7 @@ def read(self) -> bytes | str | Awaitable[bytes | str]: """ __all__ = [ + 'ActorInput', 'HttpCompressionAlgorithm', 'JsonSerializable', 'QueryParamValue',