Skip to content
Python SDK

API reference

Every Actor method, option class, and root export.

This page lists the full Actor API and every root export of the scrapely package, with signatures taken from the SDK source. For explanations and examples, follow the topic pages linked from the SDK overview.

Every method below is a classmethod on Actor. Methods marked async are coroutines, so you must await them.

Lifecycle

MemberSignatureAsync
Actor(...)Actor(options=None, *, configure_logging=True, exit_code=0, status_message=None, cleanup_timeout=timedelta(seconds=30), exit_process=None, event_listeners_timeout=None)context manager
initinit(options: InitOptions | None = None) -> Noneasync
mainmain(user_func: Callable[[], Awaitable]) -> Any. Always ends with sys.exit()async
exitexit(message_or_options=None, options: ExitOptions | None = None, *, status_message=None, exit_code=None) -> Noneasync
failfail(message_or_options=None, options: ExitOptions | None = None, *, status_message=None, exit_code=None) -> Noneasync
get_default_instanceget_default_instance() -> Actorsync

async with Actor: and async with Actor(...): call init() on entry and shut down on exit. Neither form calls sys.exit(). See Lifecycle.

Input and output

MemberSignatureAsync
get_inputget_input() -> dict | Noneasync
get_input_or_throwget_input_or_throw() -> dictasync
inputproperty -> dict | Nonesync
push_datapush_data(data: dict | list[dict], charged_event_name: str | None = None, *, event_name: str | None = None) -> ChargeResultasync
get_valueget_value(key: str, default_value: Any = None) -> Anyasync
set_valueset_value(key: str, value: Any, content_type: str | None = None) -> Noneasync

Storages

MemberSignatureAsync
open_datasetopen_dataset(name_or_id=None, options: OpenStorageOptions | None = None, *, id=None, name=None, alias=None, force_cloud=False) -> Datasetasync
open_key_value_storesame arguments -> KeyValueStoreasync
open_request_queuesame arguments -> RequestQueueasync

Events, state and status

MemberSignatureAsync
onon(event: Event, listener) -> Nonesync
offoff(event: Event, listener=None) -> Nonesync
use_stateuse_state(default_value: dict | None = None, key: str | None = None, kvs_name: str | None = None) -> MutableMapping[str, Any]async
rebootreboot(options: RebootOptions | None = None) -> Noneasync
set_status_messageset_status_message(message: str, options: SetStatusMessageOptions | None = None, *, is_terminal: bool | None = None) -> ActorRunasync

Runs and webhooks

MemberSignatureAsync
startstart(actor_id: str, run_input=None, options: StartOptions | None = None) -> ActorRunasync
callcall(actor_id: str, run_input=None, options: CallOptions | None = None) -> ActorRunasync
call_taskcall_task(task_id: str, task_input: dict | None = None, options: CallOptions | None = None) -> ActorRunasync
abortabort(run_id: str | None = None, options: AbortOptions | None = None) -> ActorRunasync
metamorphmetamorph(target_actor_id: str, run_input=None, options: MetamorphOptions | None = None) -> Noneasync
add_webhookadd_webhook(webhook: Webhook) -> Webhook | Noneasync

Charging

MemberSignatureAsync
chargecharge(event_name: str, count: int = 1) -> ChargeResultasync
get_charging_managerget_charging_manager() -> ChargingManagersync

For the ChargingManager methods, see Actors & webhooks.

Proxy and browser

MemberSignatureAsync
create_proxy_configurationcreate_proxy_configuration(actor_proxy_input=None, password=None, groups=None, country_code=None, subdivision_code=None, proxy_urls=None, new_url_function=None, tiered_proxy_urls=None, tiered_proxy_config=None, check_access=True) -> ProxyConfiguration | Noneasync
create_browser_configurationcreate_browser_configuration(actor_browser_input=None, *, country_code=None, state=None, city=None, os=None, timezone=None, language=None, adblock=None, solve_cloudflare=None) -> BrowserConfigurationasync

Environment and clients

MemberSignatureAsync
is_at_homeis_at_home() -> boolsync
is_standbyis_standby() -> boolsync
is_payingproperty -> boolsync
get_envget_env() -> ApifyEnvsync
get_remaining_timeget_remaining_time() -> int | None (milliseconds)sync
get_configget_config() -> Configurationsync
configurationproperty -> Configurationsync
event_managerproperty -> EventManager | Nonesync
logproperty -> logging.Loggersync
exit_codeproperty -> intsync
status_messageproperty -> str | Nonesync
new_clientnew_client(token=None, base_url=None) -> scrapely.storage.ApiClientsync
apify_clientproperty -> scrapely_client.ApifyClientAsyncsync

apify_client comes from scrapely-client-python. See the Python API client.

Option classes

ClassFields (defaults)
InitOptionsconfiguration=None, storage=None, graceful_shutdown=True (unused), graceful_shutdown_delay_millis=0 (unused), configure_logging=True
ExitOptionsstatus_message=None, timeout_secs=30, exit_code=0, exit=True
CallOptions, StartOptionstoken, build, max_total_charge_usd, restart_on_error, memory_mbytes, timeout (int or "inherit"), force_permission_level, webhooks. All default to None. build is ignored on someone else's Actor, which runs the User Build
AbortOptionstoken=None, status_message=None, gracefully=None
MetamorphOptionsbuild=None (ignored on someone else's Actor, which runs the User Build)
RebootOptionscustom_after_sleep_millis=None
SetStatusMessageOptionsis_status_message_terminal=False, level="INFO"
OpenStorageOptionsforce_cloud=False, config=None
RecordOptionscontent_type=None, do_not_retry_timeouts=False, timeout_secs=None. Exported for typing parity. set_value() takes content_type directly
WebhookOptionsevent_types, request_url, payload_template, idempotency_key, headers_template, description, ignore_ssl_errors=False, do_not_retry=False, should_interpolate_strings=False, is_apify_integration=False

Result types

ClassFields
ActorRunid, actor_id, status, started_at, finished_at, duration_millis, build_id, build_number, default_dataset_id, default_key_value_store_id, default_request_queue_id, exit_code, status_message, input, output, usage_total_usd, usage
ChargeResultchargeable_within_limit, charged_count, event_charge_limit_reached
ActorPricingInfoResultis_pay_per_event, max_total_charge_usd, per_event_prices, pricing_model
ProxyInfourl, scheme, hostname, port, username, password, session_id, proxy_tier, groups, country_code, subdivision_code
ApifyEnvSee Environment

ActorRun objects returned by start(), call() and abort() fill only the fields the endpoint returned. The others are None.

Root exports

Core: Actor, Configuration, set_cdp_url, BrowserConfiguration

Options and types: InitOptions, ExitOptions, CallOptions, StartOptions, AbortOptions, MetamorphOptions, RebootOptions, SetStatusMessageOptions, RecordOptions, OpenStorageOptions, WebhookOptions, ActorInput, ActorRun, ApifyEnv, ActorPermissionLevel

Storage: Dataset, KeyValueStore, RequestQueue, Request, DatasetItemsListPage, StorageClient, ApiStorageClient, ScrapelyStorageClient, SmartScrapelyStorageClient, FileSystemStorageClient, MemoryStorageClient, set_api_storage

Request loaders: ScrapelyRequestList, RequestLoader, RequestManager, RequestManagerTandem, SitemapRequestLoader

Events: Event, EventListener, EventManager (alias of ScrapelyEventManager), ScrapelyEventManager, CrawleeEventManager, LocalEventManager, ActorEventTypes, PersistStateEvent, SystemInfoEvent, MigratingEvent, AbortingEvent, ExitEvent, EventWithoutData, DeprecatedEvent, UnknownEvent, EventMessage, SystemInfoEventData, EventAbortingData, EventExitData, EventMigratingData, EventPersistStateData, EventSystemInfoData

Proxy: ProxyConfiguration, ProxyInfo

Charging: ChargingManager, ChargeResult, ChargeUncertainError, ChargeRejectedError, merge_charge_results, push_data_and_charge, create_charging_client, push_data_charging_context, USES_PUSH_DATA_INTERCEPTION

Pricing: PricingModel, ActorPricingInfo, ActorPricingInfoResult, ActorChargeEvent, PricingPerEvent, FreeActorPricingInfo, FlatPricePerMonthActorPricingInfo, PricePerDatasetItemActorPricingInfo, PayPerEventActorPricingInfo

Webhooks: Webhook, WebhookEventType

Errors: ScrapelyClientError, ScrapelyApiError, InvalidResponseBodyError, InvalidRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, RateLimitError, ServerError, raise_for_status

Also importable from the root, though they aren't in __all__, are APIFY_DEFAULT_DATASET_ITEM_EVENT ("apify-default-dataset-item"), SCRAPELY_DEFAULT_DATASET_ITEM_EVENT ("scrapely-default-dataset-item"), is_default_dataset_item_event, resolve_default_dataset_item_event_name and has_default_dataset_item_event_in_pricing.

Submodules

ModuleContents
scrapely.storageApiClient, ApiClientError, set_storage_client, persist_autosaved_values and other storage internals
scrapely.storagesDataset, KeyValueStore, RequestQueue
scrapely.storage_clientsStorage client classes, including the ApifyStorageClient and SmartApifyStorageClient aliases
scrapely.request_loadersScrapelyRequestList
scrapely.logThe scrapely logger and ActorLogFormatter

In Scrape.ly images, import apify resolves to a shim that re-exports scrapely.

Differences from the JavaScript SDK

AreaJavaScriptPython
OptionsObject literalsDataclass instances passed positionally (exit()/fail() also take keywords)
useState / use_stateuseState(name, defaultValue)use_state(default_value, key)
setValue / set_valueRecordOptions objectcontent_type argument
EntrypointActor.main(fn)async with Actor: or Actor.main(fn)
StandbyBuilt-in helperActor.is_standby() plus your own server
CrawlersRe-exported from the SDKImported from crawlee.crawlers

What's next