Skip to main content

ApifyRequestQueueClient

An Apify platform implementation of the request queue client.

Index

Methods

__init__

  • __init__(*, api_client, id, name, total_request_count, handled_request_count): None
  • Initialize a new instance.

    Preferably use the ApifyRequestQueueClient.open class method to create a new instance.


    Parameters

    • keyword-onlyapi_client: RequestQueueClientAsync
    • keyword-onlyid: str
    • keyword-onlyname: str | None
    • keyword-onlytotal_request_count: int
    • keyword-onlyhandled_request_count: int

    Returns None

add_batch_of_requests

  • async add_batch_of_requests(requests, *, forefront): AddRequestsResponse
  • Add a batch of requests to the queue.


    Parameters

    • requests: Sequence[Request]

      The requests to add.

    • optionalkeyword-onlyforefront: bool = False

      Whether to add the requests to the beginning of the queue.

    Returns AddRequestsResponse

drop

  • async drop(): None
  • Returns None

fetch_next_request

  • async fetch_next_request(): Request | None
  • Return the next request in the queue to be processed.

    Once you successfully finish processing of the request, you need to call mark_request_as_handled to mark the request as handled in the queue. If there was some error in processing the request, call reclaim_request instead, so that the queue will give the request to some other consumer in another call to the fetch_next_request method.


    Returns Request | None

get_metadata

  • async get_metadata(): RequestQueueMetadata
  • Returns RequestQueueMetadata

get_request

  • async get_request(request_id): Request | None
  • Get a request by ID.


    Parameters

    • request_id: str

      The ID of the request to get.

    Returns Request | None

is_empty

  • async is_empty(): bool
  • Check if the queue is empty.


    Returns bool

mark_request_as_handled

  • async mark_request_as_handled(request): ProcessedRequest | None
  • Mark a request as handled after successful processing.

    Handled requests will never again be returned by the fetch_next_request method.


    Parameters

    • request: Request

      The request to mark as handled.

    Returns ProcessedRequest | None

open

  • Open an Apify request queue client.

    This method creates and initializes a new instance of the Apify request queue client. It handles authentication, storage lookup/creation, and metadata retrieval, and sets up internal caching and queue management structures.


    Parameters

    • keyword-onlyid: str | None

      The ID of an existing request queue to open. If provided, the client will connect to this specific storage. Cannot be used together with name.

    • keyword-onlyname: str | None

      The name of a request queue to get or create. If a storage with this name exists, it will be opened; otherwise, a new one will be created. Cannot be used together with id.

    • keyword-onlyconfiguration: Configuration

      The configuration object containing API credentials and settings. Must include a valid token and api_base_url. May also contain a default_request_queue_id for fallback when neither id nor name is provided.

    Returns ApifyRequestQueueClient

purge

  • async purge(): None
  • Returns None

reclaim_request

  • async reclaim_request(request, *, forefront): ProcessedRequest | None
  • Reclaim a failed request back to the queue.

    The request will be returned for processing later again by another call to fetch_next_request.


    Parameters

    • request: Request

      The request to return to the queue.

    • optionalkeyword-onlyforefront: bool = False

      Whether to add the request to the head or the end of the queue.

    Returns ProcessedRequest | None