Skip to main content
Version: 2.7

_ActorType

{"content": ["The class of Actor. Only make a new instance if you're absolutely sure you need to."]}

Index

Constructors

__init__

  • __init__(configuration, *, configure_logging, exit_process): None
  • {"content": ["Create an Actor instance.\n\nNote that you don't have to do this, all the functionality is accessible using the default instance\n(e.g. Actor.open_dataset()).\n", {"


    Parameters

    • configuration: Configuration | None = None
    • keyword-onlyconfigure_logging: bool = True
    • keyword-onlyexit_process: bool | None = None

    Returns None

Methods

__call__

  • __call__(configuration, *, configure_logging, exit_process): Self
  • {"content": ["Make a new Actor instance with a non-default configuration."]}


    Parameters

    • configuration: Configuration | None = None
    • keyword-onlyconfigure_logging: bool = True
    • keyword-onlyexit_process: bool | None = None

    Returns Self

abort

  • async abort(run_id, *, token, status_message, gracefully): ActorRun
  • {"content": ["Abort given Actor run on the Apify platform using the current user account.\n\nThe user account is determined by the APIFY_TOKEN environment variable.\n", {"


    Parameters

    • run_id: str
    • keyword-onlytoken: str | None = None
    • keyword-onlystatus_message: str | None = None
    • keyword-onlygracefully: bool | None = None

    Returns ActorRun

add_webhook

  • async add_webhook(webhook, *, ignore_ssl_errors, do_not_retry, idempotency_key): None
  • {"content": ["Create an ad-hoc webhook for the current Actor run.\n\nThis webhook lets you receive a notification when the Actor run finished or failed.\n\nNote that webhooks are only supported for Actors running on the Apify platform. When running the Actor locally,\nthe function will print a warning and have no effect.\n\nFor more information about Apify Actor webhooks, please see the documentation.\n", {"


    Parameters

    • webhook: Webhook
    • keyword-onlyignore_ssl_errors: bool | None = None
    • keyword-onlydo_not_retry: bool | None = None
    • keyword-onlyidempotency_key: str | None = None

    Returns None

apify_client

  • apify_client(): ApifyClientAsync
  • {"content": ["The ApifyClientAsync instance the Actor instance uses."]}


    Returns ApifyClientAsync

call

  • async call(actor_id, run_input, *, token, content_type, build, memory_mbytes, timeout, webhooks, wait, logger): ActorRun | None
  • {"content": ["Start an Actor on the Apify Platform and wait for it to finish before returning.\n\nIt waits indefinitely, unless the wait argument is provided.\n", {"


    Parameters

    • actor_id: str
    • run_input: Any = None
    • keyword-onlytoken: str | None = None
    • keyword-onlycontent_type: str | None = None
    • keyword-onlybuild: str | None = None
    • keyword-onlymemory_mbytes: int | None = None
    • keyword-onlytimeout: timedelta | None | Literal['RemainingTime'] = None
    • keyword-onlywebhooks: list[Webhook] | None = None
    • keyword-onlywait: timedelta | None = None
    • keyword-onlylogger: logging.Logger | None | Literal['default'] = 'default'

    Returns ActorRun | None

call_task

  • async call_task(task_id, task_input, *, build, memory_mbytes, timeout, webhooks, wait, token): ActorRun | None
  • {"content": ["Start an Actor task on the Apify Platform and wait for it to finish before returning.\n\nIt waits indefinitely, unless the wait argument is provided.\n\nNote that an Actor task is a saved input configuration and options for an Actor. If you want to run an Actor\ndirectly rather than an Actor task, please use the Actor.call\n", {"


    Parameters

    • task_id: str
    • task_input: dict | None = None
    • keyword-onlybuild: str | None = None
    • keyword-onlymemory_mbytes: int | None = None
    • keyword-onlytimeout: timedelta | None = None
    • keyword-onlywebhooks: list[Webhook] | None = None
    • keyword-onlywait: timedelta | None = None
    • keyword-onlytoken: str | None = None

    Returns ActorRun | None

charge

  • {"content": ["Charge for a specified number of events - sub-operations of the Actor.\n\nThis is relevant only for the pay-per-event pricing model.\n", {"


    Parameters

    • event_name: str
    • count: int = 1

    Returns ChargeResult

config

  • {"content": ["The Configuration instance the Actor instance uses."]}


    Returns Configuration

configuration

  • {"content": ["The Configuration instance the Actor instance uses."]}


    Returns Configuration

create_proxy_configuration

  • async create_proxy_configuration(*, actor_proxy_input, password, groups, country_code, proxy_urls, new_url_function): ProxyConfiguration | None
  • {"content": ["Create a ProxyConfiguration object with the passed proxy configuration.\n\nConfigures connection to a proxy server with the provided options. Proxy servers are used to prevent target\nwebsites from blocking your crawlers based on IP address rate limits or blacklists.\n\nFor more details and code examples, see the ProxyConfiguration class.\n", {"


    Parameters

    • keyword-onlyactor_proxy_input: dict | None = None
    • keyword-onlypassword: str | None = None
    • keyword-onlygroups: list[str] | None = None
    • keyword-onlycountry_code: str | None = None
    • keyword-onlyproxy_urls: list[str | None] | None = None
    • keyword-onlynew_url_function: _NewUrlFunction | None = None

    Returns ProxyConfiguration | None

event_manager

  • event_manager(): EventManager
  • {"content": ["The EventManager instance the Actor instance uses."]}


    Returns EventManager

exit

  • async exit(*, exit_code, event_listeners_timeout, status_message, cleanup_timeout): None
  • {"content": ["Exit the Actor instance.\n\nThis stops the Actor instance. It cancels all the intervals for regularly sending PERSIST_STATE events,\nsends a final PERSIST_STATE event, waits for all the event listeners to finish, and stops the event manager.\n", {"


    Parameters

    • keyword-onlyexit_code: int = 0
    • keyword-onlyevent_listeners_timeout: timedelta | None = EVENT_LISTENERS_TIMEOUT
    • keyword-onlystatus_message: str | None = None
    • keyword-onlycleanup_timeout: timedelta = timedelta(seconds=30)

    Returns None

fail

  • async fail(*, exit_code, exception, status_message): None
  • {"content": ["Fail the Actor instance.\n\nThis performs all the same steps as Actor.exit(), but it additionally sets the exit code to 1 (by default).\n", {"


    Parameters

    • keyword-onlyexit_code: int = 1
    • keyword-onlyexception: BaseException | None = None
    • keyword-onlystatus_message: str | None = None

    Returns None

get_charging_manager

  • {"content": ["Retrieve the charging manager to access granular pricing information."]}


    Returns ChargingManager

get_env

  • get_env(): dict
  • {"content": ["Return a dictionary with information parsed from all the APIFY_XXX environment variables.\n\nFor a list of all the environment variables, see the\nActor documentation. If some variables\nare not defined or are invalid, the corresponding value in the resulting dictionary will be None."]}


    Returns dict

get_input

  • async get_input(): Any
  • {"content": ["Get the Actor input value from the default key-value store associated with the current Actor run."]}


    Returns Any

get_value

  • async get_value(key, default_value): Any
  • {"content": ["Get a value from the default key-value store associated with the current Actor run.\n", {"


    Parameters

    • key: str
    • default_value: Any = None

    Returns Any

init

  • async init(): None
  • {"content": ["Initialize the Actor instance.\n\nThis initializes the Actor instance. It configures the right storage client based on whether the Actor is\nrunning locally or on the Apify platform, it initializes the event manager for processing Actor events,\nand starts an interval for regularly sending PERSIST_STATE events, so that the Actor can regularly persist\nits state in response to these events.\n\nThis method should be called immediately before performing any additional Actor actions, and it should be\ncalled only once."]}


    Returns None

is_at_home

  • is_at_home(): bool
  • {"content": ["Return True when the Actor is running on the Apify platform, and False otherwise (e.g. local run)."]}


    Returns bool

log

  • log(): logging.Logger
  • {"content": ["The logging.Logger instance the Actor uses."]}


    Returns logging.Logger

metamorph

  • async metamorph(target_actor_id, run_input, *, target_actor_build, content_type, custom_after_sleep): None
  • {"content": ["Transform this Actor run to an Actor run of a different Actor.\n\nThe platform stops the current Actor container and starts a new container with the new Actor instead. All\nthe default storages are preserved, and the new input is stored under the INPUT-METAMORPH-1 key in the same\ndefault key-value store.\n", {"


    Parameters

    • target_actor_id: str
    • run_input: Any = None
    • keyword-onlytarget_actor_build: str | None = None
    • keyword-onlycontent_type: str | None = None
    • keyword-onlycustom_after_sleep: timedelta | None = None

    Returns None

new_client

  • new_client(*, token, api_url, max_retries, min_delay_between_retries, timeout): ApifyClientAsync
  • {"content": ["Return a new instance of the Apify API client.\n\nThe ApifyClientAsync class is provided by the apify-client\npackage, and it is automatically configured using the APIFY_API_BASE_URL and APIFY_TOKEN environment\nvariables.\n\nYou can override the token via the available options. That's useful if you want to use the client\nas a different Apify user than the SDK internals are using.\n", {"


    Parameters

    • keyword-onlytoken: str | None = None
    • keyword-onlyapi_url: str | None = None
    • keyword-onlymax_retries: int | None = None
    • keyword-onlymin_delay_between_retries: timedelta | None = None
    • keyword-onlytimeout: timedelta | None = None

    Returns ApifyClientAsync

off

  • off(event_name, listener): None
  • {"content": ["Remove a listener, or all listeners, from an Actor event.\n", {"


    Parameters

    • event_name: Event
    • listener: Callable | None = None

    Returns None

on

  • on(event_name, listener): EventListener[Any]
  • {"content": ["Add an event listener to the Actor's event manager.\n\nThe following events can be emitted:\n\n- Event.SYSTEM_INFO: Emitted every minute; the event data contains information about the Actor's resource\nusage.\n\n- Event.MIGRATING: Emitted when the Actor on the Apify platform is about to be migrated to another worker\nserver. Use this event to persist the Actor's state and gracefully stop in-progress tasks, preventing\ndisruption.\n\n- Event.PERSIST_STATE: Emitted regularly (default: 60 seconds) to notify the Actor to persist its state,\npreventing work repetition after a restart. This event is emitted together with the MIGRATING event, where\nthe isMigrating flag in the event data is True; otherwise, the flag is False. This event is for\nconvenience; the same effect can be achieved by setting an interval and listening for the MIGRATING event.\n\n- Event.ABORTING: Emitted when a user aborts an Actor run on the Apify platform, allowing the Actor time\nto clean up its state if the abort is graceful.\n", {"


    Parameters

    • event_name: Event
    • listener: EventListener[Any]

    Returns EventListener[Any]

open_dataset

  • async open_dataset(*, id, name, force_cloud): Dataset
  • {"content": ["Open a dataset.\n\nDatasets are used to store structured data where each object stored has the same attributes, such as online\nstore products or real estate offers. The actual data is stored either on the local filesystem or in\nthe Apify cloud.\n", {"


    Parameters

    • keyword-onlyid: str | None = None
    • keyword-onlyname: str | None = None
    • keyword-onlyforce_cloud: bool = False

    Returns Dataset

open_key_value_store

  • async open_key_value_store(*, id, name, force_cloud): KeyValueStore
  • {"content": ["Open a key-value store.\n\nKey-value stores are used to store records or files, along with their MIME content type. The records are stored\nand retrieved using a unique key. The actual data is stored either on a local filesystem or in the Apify cloud.\n", {"


    Parameters

    • keyword-onlyid: str | None = None
    • keyword-onlyname: str | None = None
    • keyword-onlyforce_cloud: bool = False

    Returns KeyValueStore

open_request_queue

  • async open_request_queue(*, id, name, force_cloud): RequestQueue
  • {"content": ["Open a request queue.\n\nRequest queue represents a queue of URLs to crawl, which is stored either on local filesystem or in\nthe Apify cloud. The queue is used for deep crawling of websites, where you start with several URLs and then\nrecursively follow links to other pages. The data structure supports both breadth-first and depth-first\ncrawling orders.\n", {"


    Parameters

    • keyword-onlyid: str | None = None
    • keyword-onlyname: str | None = None
    • keyword-onlyforce_cloud: bool = False

    Returns RequestQueue

push_data

  • async push_data(data, charged_event_name): ChargeResult | None
  • {"content": ["Store an object or a list of objects to the default dataset of the current Actor run.\n", {"


    Parameters

    • data: dict | list[dict]
    • charged_event_name: str | None = None

    Returns ChargeResult | None

reboot

  • async reboot(*, event_listeners_timeout, custom_after_sleep): None
  • {"content": ["Internally reboot this Actor.\n\nThe system stops the current container and starts a new one, with the same run ID and default storages.\n", {"


    Parameters

    • keyword-onlyevent_listeners_timeout: timedelta | None = EVENT_LISTENERS_TIMEOUT
    • keyword-onlycustom_after_sleep: timedelta | None = None

    Returns None

set_status_message

  • async set_status_message(status_message, *, is_terminal): ActorRun | None
  • {"content": ["Set the status message for the current Actor run.\n", {"


    Parameters

    • status_message: str
    • keyword-onlyis_terminal: bool | None = None

    Returns ActorRun | None

set_value

  • async set_value(key, value, *, content_type): None
  • {"content": ["Set or delete a value in the default key-value store associated with the current Actor run.\n", {"


    Parameters

    • key: str
    • value: Any
    • keyword-onlycontent_type: str | None = None

    Returns None

start

  • async start(actor_id, run_input, *, token, content_type, build, memory_mbytes, timeout, wait_for_finish, webhooks): ActorRun
  • {"content": ["Run an Actor on the Apify platform.\n\nUnlike Actor.call, this method just starts the run without waiting for finish.\n", {"


    Parameters

    • actor_id: str
    • run_input: Any = None
    • keyword-onlytoken: str | None = None
    • keyword-onlycontent_type: str | None = None
    • keyword-onlybuild: str | None = None
    • keyword-onlymemory_mbytes: int | None = None
    • keyword-onlytimeout: timedelta | None | Literal['RemainingTime'] = None
    • keyword-onlywait_for_finish: int | None = None
    • keyword-onlywebhooks: list[Webhook] | None = None

    Returns ActorRun