Skip to content
Merged
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
56 changes: 25 additions & 31 deletions src/apify_client/_resource_clients/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
WebhookCollectionClient,
WebhookCollectionClientAsync,
)
from apify_client.types import Timeout, WebhooksList
from apify_client.types import ActorInput, Timeout, WebhooksList

_PricingInfo = (
PayPerEventActorPricingInfo
Expand Down Expand Up @@ -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,
Expand All @@ -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).
Expand Down Expand Up @@ -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,
Expand All @@ -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).
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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).
Expand Down Expand Up @@ -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,
Expand All @@ -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).
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down
20 changes: 9 additions & 11 deletions src/apify_client/_resource_clients/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand All @@ -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.

Expand Down Expand Up @@ -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:
Expand All @@ -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.

Expand Down
11 changes: 10 additions & 1 deletion src/apify_client/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -102,13 +102,22 @@ 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.

Based on the definition discussed in https://github.com/python/typing/issues/182.
"""

__all__ = [
'ActorInput',
'HttpCompressionAlgorithm',
'JsonSerializable',
'QueryParamValue',
Expand Down
Loading