Actor
Index
Constructors
Properties
Methods
Constructors
__init__
{"content": ["Create an Actor instance.\n\nNote that you don't have to do this, all the methods on this class function as classmethods too,\nand that is their preferred usage.\n", {"
Parameters
config: Configuration | None = None
Returns None
Properties
apify_client
{"content": ["The ApifyClientAsync instance the Actor instance uses."]}
config
{"content": ["The Configuration instance the Actor instance uses."]}
event_manager
{"content": ["The EventManager instance the Actor instance uses."]}
log
{"content": ["The logging.Logger instance the Actor uses."]}
Methods
abort
{"content": ["Abort given actor run on the Apify platform using the current user account (determined by the
APIFY_TOKENenvironment variable).\n", {"Parameters
run_id: str
keyword-onlytoken: str | None = None
keyword-onlygracefully: bool | None = None
Returns dict
add_webhook
{"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.\nWhen running the actor locally, the function will print a warning and have no effect.\n\nFor more information about Apify actor webhooks, please see the documentation.\n", {"
Parameters
keyword-onlyevent_types: list[WebhookEventType]
keyword-onlyrequest_url: str
keyword-onlypayload_template: str | None = None
keyword-onlyignore_ssl_errors: bool | None = None
keyword-onlydo_not_retry: bool | None = None
keyword-onlyidempotency_key: str | None = None
Returns dict
call
{"content": ["Start an actor on the Apify Platform and wait for it to finish before returning.\n\nIt waits indefinitely, unless the wait_secs 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_secs: int | None = None
keyword-onlywebhooks: list[dict] | None = None
keyword-onlywait_secs: int | None = None
Returns dict | None
call_task
{"content": ["Start an actor task on the Apify Platform and wait for it to finish before returning.\n\nIt waits indefinitely, unless the wait_secs argument is provided.\n\nNote that an actor task is a saved input configuration and options for an actor.\nIf you want to run an actor directly 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_secs: int | None = None
keyword-onlywebhooks: list[dict] | None = None
keyword-onlywait_secs: int | None = None
keyword-onlytoken: str | None = None
Returns dict | None
create_proxy_configuration
{"content": ["Create a ProxyConfiguration object with the passed proxy configuration.\n\nConfigures connection to a proxy server with the provided options.\nProxy servers are used to prevent target websites from blocking your crawlers based on IP address rate limits or blacklists.\n\nFor more details and code examples, see the
ProxyConfigurationclass.\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
keyword-onlynew_url_function: Callable[[str | None], str] | Callable[[str | None], Awaitable[str]] | None = None
Returns ProxyConfiguration | None
exit
{"content": ["Exit the actor instance.\n\nThis stops the Actor instance.\nIt cancels all the intervals for regularly sending
PERSIST_STATEevents,\nsends a finalPERSIST_STATEevent,\nwaits for all the event listeners to finish,\nand stops the event manager.\n", {"Parameters
keyword-onlyexit_code: int = 0
keyword-onlyevent_listeners_timeout_secs: float | None = EVENT_LISTENERS_TIMEOUT_SECS
keyword-onlystatus_message: str | None = None
keyword-onlycleanup_timeout: timedelta = timedelta(seconds=30)
Returns None
fail
{"content": ["Fail the actor instance.\n\nThis performs all the same steps as Actor.exit(),\nbut 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_env
{"content": ["Return a dictionary with information parsed from all the
APIFY_XXXenvironment variables.\n\nFor a list of all the environment variables,\nsee the Actor documentation.\nIf some variables are not defined or are invalid, the corresponding value in the resulting dictionary will be None."]}Returns dict
get_input
{"content": ["Get the actor input value from the default key-value store associated with the current actor run."]}
Returns Any
get_system_info
{"content": ["Get the current system info."]}
Returns dict
get_value
{"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
{"content": ["Initialize the actor instance.\n\nThis initializes the Actor instance.\nIt configures the right storage client based on whether the actor is running locally or on the Apify platform,\nit initializes the event manager for processing actor events,\nand starts an interval for regularly sending
PERSIST_STATEevents,\nso that the actor can regularly persist its state in response to these events.\n\nThis method should be called immediately before performing any additional actor actions,\nand it should be called only once."]}Returns None
is_at_home
{"content": ["Return
Truewhen the actor is running on the Apify platform, andFalseotherwise (for example when running locally)."]}Returns bool
main
{"content": ["Initialize the actor, run the passed function and finish the actor cleanly.\n\nThe
Actor.main()function is optional and is provided merely for your convenience.\nIt is mainly useful when you're running your code as an actor on the Apify platform.\n\nTheActor.main()function performs the following actions:\n\n- When running on the Apify platform (i.e.APIFY_IS_AT_HOMEenvironment variable is set),\nit sets up a connection to listen for platform events.\nFor example, to get a notification about an imminent migration to another server.\n- It invokes the user function passed as themain_actor_functionparameter.\n- If the user function was an async function, it awaits it.\n- If the user function throws an exception or some other error is encountered,\nit prints error details to console so that they are stored to the log,\nand finishes the actor cleanly.\n- Finally, it exits the Python process, with zero exit code on success and non-zero on errors.\n", {"Parameters
main_actor_function: Callable[[], MainReturnType]
Returns MainReturnType | None
metamorph
{"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.\nAll the default storages are preserved,\nand the new input is stored under the
INPUT-METAMORPH-1key in the same default 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_millis: int | None = None
Returns None
new_client
{"content": ["Return a new instance of the Apify API client.\n\nThe
ApifyClientAsyncclass is provided by the apify-client package,\nand it is automatically configured using theAPIFY_API_BASE_URLandAPIFY_TOKENenvironment variables.\n\nYou can override the token via the available options.\nThat's useful if you want to use the client as 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_millis: int | None = None
keyword-onlytimeout_secs: int | None = None
Returns ApifyClientAsync
off
{"content": ["Remove a listener, or all listeners, from an actor event.\n", {"
Parameters
event_name: ActorEventTypes
listener: Callable | None = None
Returns None
on
{"content": ["Add an event listener to the actor's event manager.\n\nThe following events can be emitted:\n-
ActorEventTypes.SYSTEM_INFO:\nEmitted every minute, the event data contains info about the resource usage of the actor.\n-ActorEventTypes.MIGRATING:\nEmitted when the actor running on the Apify platform is going to be migrated to another worker server soon.\nYou can use it to persist the state of the actor and gracefully stop your in-progress tasks,\nso that they are not interrupted by the migration..\n-ActorEventTypes.PERSIST_STATE:\nEmitted in regular intervals (by default 60 seconds) to notify the actor that it should persist its state,\nin order to avoid repeating all work when the actor restarts.\nThis event is automatically emitted together with the migrating event,\nin which case theisMigratingflag in the event data is set to True, otherwise the flag is False.\nNote that this event is provided merely for your convenience,\nyou can achieve the same effect using an interval and listening for the migrating event.\n-ActorEventTypes.ABORTING:\nWhen a user aborts an actor run on the Apify platform,\nthey can choose to abort it gracefully, to allow the actor some time before getting terminated.\nThis graceful abort emits the aborting event, which you can use to clean up the actor state.\n", {"Parameters
event_name: ActorEventTypes
listener: Callable
Returns Callable
open_dataset
{"content": ["Open a dataset.\n\nDatasets are used to store structured data where each object stored has the same attributes,\nsuch as online store products or real estate offers.\nThe actual data is stored either on the 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 Dataset
open_key_value_store
{"content": ["Open a key-value store.\n\nKey-value stores are used to store records or files, along with their MIME content type.\nThe records are stored and retrieved using a unique key.\nThe 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
{"content": ["Open a request queue.\n\nRequest queue represents a queue of URLs to crawl, which is stored either on local filesystem or in the Apify cloud.\nThe 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\nand depth-first crawling orders.\n", {"
Parameters
keyword-onlyid: str | None = None
keyword-onlyname: str | None = None
keyword-onlyforce_cloud: bool = False
Returns RequestQueue
push_data
{"content": ["Store an object or a list of objects to the default dataset of the current actor run.\n", {"
Parameters
data: Any
Returns None
reboot
{"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_secs: int | None = EVENT_LISTENERS_TIMEOUT_SECS
keyword-onlycustom_after_sleep_millis: int | None = None
Returns None
set_status_message
{"content": ["Set the status message for the current actor run.\n", {"
Parameters
status_message: str
keyword-onlyis_terminal: bool | None = None
Returns dict | None
set_value
{"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
{"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_secs: int | None = None
keyword-onlywait_for_finish: int | None = None
keyword-onlywebhooks: list[dict] | None = None
Returns dict
{"content": ["The main class of the SDK, through which all the actor operations should be done."]}