Skip to main content

TaskClient

Sub-client for managing a specific task.

Provides methods to manage a specific task, e.g. update it, delete it, or start runs. Obtain an instance via an appropriate method on the ApifyClient class.

Hierarchy

Index

Methods

__init__

  • __init__(*, base_url, public_base_url, http_client, resource_path, client_registry, resource_id, params): None
  • Initialize the resource client.


    Parameters

    • keyword-onlybase_url: str

      API base URL.

    • keyword-onlypublic_base_url: str

      Public CDN base URL.

    • keyword-onlyhttp_client: HttpClient

      HTTP client for making requests.

    • keyword-onlyresource_path: str

      Resource endpoint path (e.g., 'actors', 'datasets').

    • keyword-onlyclient_registry: ClientRegistry

      Bundle of client classes for dependency injection.

    • optionalkeyword-onlyresource_id: str | None = None

      Optional resource ID for single-resource clients.

    • optionalkeyword-onlyparams: dict | None = None

      Optional default parameters for all requests.

    Returns None

call

  • call(*, task_input, build, max_items, memory_mbytes, timeout, restart_on_error, webhooks, wait_duration): Run | None
  • Start a task and wait for it to finish before returning the Run object.

    It waits indefinitely, unless the wait_duration argument is provided.

    https://docs.apify.com/api/v2#/reference/actor-tasks/run-collection/run-task


    Parameters

    • optionalkeyword-onlytask_input: dict | None = None

      Task input dictionary.

    • optionalkeyword-onlybuild: str | None = None

      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 task settings (typically latest).

    • optionalkeyword-onlymax_items: int | None = None

      Maximum number of results that will be returned by this run. If the Actor is charged per result, you will not be charged for more results than the given limit.

    • optionalkeyword-onlymemory_mbytes: int | None = None

      Memory limit for the run, in megabytes. By default, the run uses a memory limit specified in the task settings.

    • optionalkeyword-onlytimeout: timedelta | None = None

      Optional timeout for the run. By default, the run uses timeout specified in the task settings.

    • optionalkeyword-onlyrestart_on_error: bool | None = None

      If true, the Task run process will be restarted whenever it exits with a non-zero status code.

    • optionalkeyword-onlywebhooks: list[dict] | None = None

      Specifies optional webhooks associated with the Actor run, which can be used to receive a notification e.g. when the Actor finished or failed. Note: if you already have a webhook set up for the Actor or task, you do not have to add it again here.

    • optionalkeyword-onlywait_duration: timedelta | None = None

      The maximum time the server waits for the task run to finish. If not provided, waits indefinitely.

    Returns Run | None

    The run object.

delete

  • delete(): None

get

get_input

  • get_input(): dict | None

last_run

  • Retrieve the client for the last run of this task.

    Last run is retrieved based on the start time of the runs.


    Parameters

    • optionalkeyword-onlystatus: ActorJobStatus | None = None

      Consider only runs with this status.

    • optionalkeyword-onlyorigin: RunOrigin | None = None

      Consider only runs started with this origin.

    Returns RunClient

    The resource client for the last run of this task.

runs

start

  • start(*, task_input, build, max_items, memory_mbytes, timeout, restart_on_error, wait_for_finish, webhooks): Run
  • Start the task and immediately return the Run object.

    https://docs.apify.com/api/v2#/reference/actor-tasks/run-collection/run-task


    Parameters

    • optionalkeyword-onlytask_input: dict | None = None

      Task input dictionary.

    • optionalkeyword-onlybuild: str | None = None

      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 task settings (typically latest).

    • optionalkeyword-onlymax_items: int | None = None

      Maximum number of results that will be returned by this run. If the Actor is charged per result, you will not be charged for more results than the given limit.

    • optionalkeyword-onlymemory_mbytes: int | None = None

      Memory limit for the run, in megabytes. By default, the run uses a memory limit specified in the task settings.

    • optionalkeyword-onlytimeout: timedelta | None = None

      Optional timeout for the run. By default, the run uses timeout specified in the task settings.

    • optionalkeyword-onlyrestart_on_error: bool | None = None

      If true, the Task run process will be restarted whenever it exits with a non-zero status code.

    • optionalkeyword-onlywait_for_finish: int | None = None

      The maximum number of seconds the server waits for the run to finish. By default, it is 0, the maximum value is 60.

    • optionalkeyword-onlywebhooks: list[dict] | None = None

      Optional ad-hoc webhooks (https://docs.apify.com/webhooks/ad-hoc-webhooks) associated with the Actor run which can be used to receive a notification, e.g. when the Actor finished or failed. If you already have a webhook set up for the Actor or task, you do not have to add it again here. Each webhook is represented by a dictionary containing these items:

      • event_types: List of WebhookEventType values which trigger the webhook.
      • request_url: URL to which to send the webhook HTTP request.
      • payload_template: Optional template for the request payload.

    Returns Run

    The run object.

update

  • update(*, name, task_input, build, max_items, memory_mbytes, timeout, restart_on_error, title, actor_standby_desired_requests_per_actor_run, actor_standby_max_requests_per_actor_run, actor_standby_idle_timeout, actor_standby_build, actor_standby_memory_mbytes): Task

  • Parameters

    • optionalkeyword-onlyname: str | None = None

      Name of the task.

    • optionalkeyword-onlytask_input: dict | None = None

      Task input dictionary.

    • optionalkeyword-onlybuild: str | None = None

      Actor build to run. It can be either a build tag or build number. By default, the run uses the build specified in the task settings (typically latest).

    • optionalkeyword-onlymax_items: int | None = None

      Maximum number of results that will be returned by this run. If the Actor is charged per result, you will not be charged for more results than the given limit.

    • optionalkeyword-onlymemory_mbytes: int | None = None

      Memory limit for the run, in megabytes. By default, the run uses a memory limit specified in the task settings.

    • optionalkeyword-onlytimeout: timedelta | None = None

      Optional timeout for the run. By default, the run uses timeout specified in the task settings.

    • optionalkeyword-onlyrestart_on_error: bool | None = None

      If true, the Task run process will be restarted whenever it exits with a non-zero status code.

    • optionalkeyword-onlytitle: str | None = None

      A human-friendly equivalent of the name.

    • optionalkeyword-onlyactor_standby_desired_requests_per_actor_run: int | None = None

      The desired number of concurrent HTTP requests for a single Actor Standby run.

    • optionalkeyword-onlyactor_standby_max_requests_per_actor_run: int | None = None

      The maximum number of concurrent HTTP requests for a single Actor Standby run.

    • optionalkeyword-onlyactor_standby_idle_timeout: timedelta | None = None

      If the Actor run does not receive any requests for this time, it will be shut down.

    • optionalkeyword-onlyactor_standby_build: str | None = None

      The build tag or number to run when the Actor is in Standby mode.

    • optionalkeyword-onlyactor_standby_memory_mbytes: int | None = None

      The memory in megabytes to use when the Actor is in Standby mode.

    Returns Task

    The updated task.

update_input

  • update_input(*, task_input): dict

webhooks

Properties

resource_id

resource_id: str | None

Get the resource ID.