Skip to main content
Version: 2.5

apify-client

Index

Main Clients

Resource Clients

Async Resource Clients

Helper Classes

Errors

Methods

Properties

Constants

Errors

is_retryable_error

  • is_retryable_error(exc): bool
  • Check if the given error is retryable.

    All `impit.HTTPError` subclasses are considered retryable because they represent transport-level failures (network issues, timeouts, protocol errors, body decoding errors) that are typically transient. HTTP status code errors are handled separately in `_make_request` based on the response status code, not here.


    Parameters

    • exc: Exception

    Returns bool

Methods

create_hmac_signature

  • create_hmac_signature(secret_key, message): str
  • Generate an HMAC signature and encodes it using Base62. Base62 encoding reduces the signature length.

    HMAC signature is truncated to 30 characters to make it shorter.


    Parameters

    • secret_key: str
    • message: str

    Returns str

create_redirect_logger

  • create_redirect_logger(name): logging.Logger
  • Create a logger for redirecting logs from another Actor.


    Parameters

    • name: str

    Returns logging.Logger

create_storage_content_signature

  • create_storage_content_signature(resource_id, url_signing_secret_key, expires_in_millis, version): str
  • Create a secure signature for a resource like a dataset or key-value store.

    This signature is used to generate a signed URL for authenticated access, which can be expiring or permanent. The signature is created using HMAC with the provided secret key and includes the resource ID, expiration time, and version.

    Note: expires_in_millis is optional. If not provided, the signature will not expire.


    Parameters

    • resource_id: str
    • url_signing_secret_key: str
    • expires_in_millis: int | None = None
    • version: int = 0

    Returns str

encode_base62

  • encode_base62(num): str
  • Encode the given number to base62.


    Parameters

    • num: int

    Returns str

encode_webhook_list_to_base64

  • encode_webhook_list_to_base64(webhooks): str
  • Encode a list of dictionaries representing webhooks to their base64-encoded representation for the API.


    Parameters

    • webhooks: list[dict]

    Returns str

filter_out_none_values_recursively

  • filter_out_none_values_recursively(dictionary): dict
  • Return copy of the dictionary, recursively omitting all keys for which values are None.


    Parameters

    • dictionary: dict

    Returns dict

filter_out_none_values_recursively_internal

  • filter_out_none_values_recursively_internal(dictionary, *, remove_empty_dicts): dict | None
  • Recursively filters out None values from a dictionary.

    Unfortunately, it's necessary to have an internal function for the correct result typing, without having to create complicated overloads


    Parameters

    • dictionary: dict
    • keyword-onlyremove_empty_dicts: bool | None = None

    Returns dict | None

get_actor_env_var_representation

  • get_actor_env_var_representation(*, is_secret, name, value): dict
  • Return an environment variable representation of the Actor in a dictionary.


    Parameters

    • keyword-onlyis_secret: bool | None = None
    • keyword-onlyname: str | None = None
    • keyword-onlyvalue: str | None = None

    Returns dict

get_actor_representation

  • get_actor_representation(*, name, title, description, seo_title, seo_description, versions, restart_on_error, is_public, is_deprecated, is_anonymously_runnable, categories, default_run_build, default_run_max_items, default_run_memory_mbytes, default_run_timeout_secs, default_run_force_permission_level, example_run_input_body, example_run_input_content_type, actor_standby_is_enabled, actor_standby_desired_requests_per_actor_run, actor_standby_max_requests_per_actor_run, actor_standby_idle_timeout_secs, actor_standby_build, actor_standby_memory_mbytes, pricing_infos, actor_permission_level, tagged_builds): dict
  • Get dictionary representation of the Actor.


    Parameters

    • keyword-onlyname: str | None
    • keyword-onlytitle: str | None = None
    • keyword-onlydescription: str | None = None
    • keyword-onlyseo_title: str | None = None
    • keyword-onlyseo_description: str | None = None
    • keyword-onlyversions: list[dict] | None = None
    • keyword-onlyrestart_on_error: bool | None = None
    • keyword-onlyis_public: bool | None = None
    • keyword-onlyis_deprecated: bool | None = None
    • keyword-onlyis_anonymously_runnable: bool | None = None
    • keyword-onlycategories: list[str] | None = None
    • keyword-onlydefault_run_build: str | None = None
    • keyword-onlydefault_run_max_items: int | None = None
    • keyword-onlydefault_run_memory_mbytes: int | None = None
    • keyword-onlydefault_run_timeout_secs: int | None = None
    • keyword-onlydefault_run_force_permission_level: ActorPermissionLevel | None = None
    • keyword-onlyexample_run_input_body: Any = None
    • keyword-onlyexample_run_input_content_type: str | None = None
    • keyword-onlyactor_standby_is_enabled: bool | None = None
    • keyword-onlyactor_standby_desired_requests_per_actor_run: int | None = None
    • keyword-onlyactor_standby_max_requests_per_actor_run: int | None = None
    • keyword-onlyactor_standby_idle_timeout_secs: int | None = None
    • keyword-onlyactor_standby_build: str | None = None
    • keyword-onlyactor_standby_memory_mbytes: int | None = None
    • keyword-onlypricing_infos: list[dict] | None = None
    • keyword-onlyactor_permission_level: ActorPermissionLevel | None = None
    • keyword-onlytagged_builds: dict[str, None | dict[str, str]] | None = None

    Returns dict

get_task_representation

  • get_task_representation(actor_id, name, task_input, build, max_items, memory_mbytes, timeout_secs, title, actor_standby_desired_requests_per_actor_run, actor_standby_max_requests_per_actor_run, actor_standby_idle_timeout_secs, actor_standby_build, actor_standby_memory_mbytes, *, restart_on_error): dict
  • Get the dictionary representation of a task.


    Parameters

    • actor_id: str | None = None
    • name: str | None = None
    • task_input: dict | None = None
    • build: str | None = None
    • max_items: int | None = None
    • memory_mbytes: int | None = None
    • timeout_secs: int | None = None
    • title: str | None = None
    • actor_standby_desired_requests_per_actor_run: int | None = None
    • actor_standby_max_requests_per_actor_run: int | None = None
    • actor_standby_idle_timeout_secs: int | None = None
    • actor_standby_build: str | None = None
    • actor_standby_memory_mbytes: int | None = None
    • keyword-onlyrestart_on_error: bool | None = None

    Returns dict

get_webhook_representation

  • get_webhook_representation(*, event_types, request_url, payload_template, headers_template, actor_id, actor_task_id, actor_run_id, ignore_ssl_errors, do_not_retry, idempotency_key, is_ad_hoc): dict
  • Prepare webhook dictionary representation for clients.


    Parameters

    • keyword-onlyevent_types: list[WebhookEventType] | None = None
    • keyword-onlyrequest_url: str | None = None
    • keyword-onlypayload_template: str | None = None
    • keyword-onlyheaders_template: str | None = None
    • keyword-onlyactor_id: str | None = None
    • keyword-onlyactor_task_id: str | None = None
    • keyword-onlyactor_run_id: str | None = None
    • keyword-onlyignore_ssl_errors: bool | None = None
    • keyword-onlydo_not_retry: bool | None = None
    • keyword-onlyidempotency_key: str | None = None
    • keyword-onlyis_ad_hoc: bool | None = None

    Returns dict

is_content_type_json

  • is_content_type_json(content_type): bool
  • Check if the given content type is JSON.


    Parameters

    • content_type: str

    Returns bool

is_content_type_text

  • is_content_type_text(content_type): bool
  • Check if the given content type is text.


    Parameters

    • content_type: str

    Returns bool

is_content_type_xml

  • is_content_type_xml(content_type): bool
  • Check if the given content type is XML.


    Parameters

    • content_type: str

    Returns bool

is_file_or_bytes

  • is_file_or_bytes(value): bool
  • Check if the input value is a file-like object or bytes.

    The check for IOBase is not ideal, it would be better to use duck typing, but then the check would be super complex, judging from how the 'requests' library does it. This way should be good enough for the vast majority of use cases, if it causes issues, we can improve it later.


    Parameters

    • value: Any

    Returns bool

json_dumps

  • json_dumps(obj): str
  • Dump JSON to a string with the correct settings and serializer.


    Parameters

    • obj: Any

    Returns str

maybe_extract_enum_member_value

  • maybe_extract_enum_member_value(maybe_enum_member): Any
  • Extract the value of an enumeration member if it is an Enum, otherwise return the original value.


    Parameters

    • maybe_enum_member: Any

    Returns Any

parse_date_fields

  • parse_date_fields(data, max_depth): list | dict
  • Recursively parse date fields in a list or dictionary up to the specified depth.


    Parameters

    • data: list | dict
    • max_depth: int = PARSE_DATE_FIELDS_MAX_DEPTH

    Returns list | dict

Properties

JSONSerializable

JSONSerializable:

Type for representing json-serializable values. It's close enough to the real thing supported by json.parse. It was suggested in a discussion with (and approved by) Guido van Rossum, so I'd consider it correct enough.