RequestQueue
Index
Methods
add_request
{"content": ["Adds a request to the
RequestQueuewhile managing deduplication and positioning within the queue.\n\nThe deduplication of requests relies on theuniqueKeyfield within the request dictionary. IfuniqueKey\nexists, it remains unchanged; if it does not, it is generated based on the request'surl,method,\nandpayloadfields. The generation ofuniqueKeycan be influenced by thekeep_url_fragmentand\nuse_extended_unique_keyflags, which dictate whether to include the URL fragment and the request's method\nand payload, respectively, in its computation.\n\nThe request can be added to the forefront (beginning) or the back of the queue based on theforefront\nparameter. Information about the request's addition to the queue, including whether it was already present or\nhandled, is returned in an output dictionary.\n", {"Parameters
request: dict
keyword-onlyforefront: bool = False
keyword-onlykeep_url_fragment: bool = False
keyword-onlyuse_extended_unique_key: bool = False
Returns dict
\n-
requestId(str)
drop
{"content": ["Remove the request queue either from the Apify cloud storage or from the local directory."]}
Returns None
fetch_next_request
{"content": ["Return the next request in the queue to be processed.\n\nOnce you successfully finish processing of the request, you need to call\n
RequestQueue.mark_request_as_handledto mark the request as handled in the queue.\nIf there was some error in processing the request, callRequestQueue.reclaim_requestinstead,\nso that the queue will give the request to some other consumer in another call to thefetch_next_requestmethod.\n\nNote that theNonereturn value does not mean the queue processing finished, it means there are currently no pending requests.\nTo check whether all requests in queue were finished, useRequestQueue.is_finishedinstead.\n", {"Returns dict | None
get_info
{"content": ["Get an object containing general information about the request queue.\n", {"
Returns dict | None
get_request
{"content": ["Retrieve a request from the queue.\n", {"
Parameters
request_id: str
Returns dict | None
is_empty
{"content": ["Check whether the queue is empty.\n", {"
Returns bool
is_finished
{"content": ["Check whether the queue is finished.\n\nDue to the nature of distributed storage used by the queue,\nthe function might occasionally return a false negative,\nbut it will never return a false positive.\n", {"
Returns bool
mark_request_as_handled
{"content": ["Mark a request as handled after successful processing.\n\nHandled requests will never again be returned by the
RequestQueue.fetch_next_requestmethod.\n", {"Parameters
request: dict
Returns dict | None
open
{"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
keyword-onlyconfig: Configuration | None = None
Returns RequestQueue
reclaim_request
{"content": ["Reclaim a failed request back to the queue.\n\nThe request will be returned for processing later again\nby another call to
RequestQueue.fetchNextRequest.\n", {"Parameters
request: dict
forefront: bool = False
Returns dict | None
{"content": ["Represents a queue of URLs to crawl.\n\nCan be used for deep crawling of websites where you start with several URLs and then recursively\nfollow links to other pages. The data structure supports both breadth-first and depth-first crawling orders.\n\nEach URL is represented using an instance of the Request class.\nThe queue can only contain unique URLs. More precisely, it can only contain request dictionaries\nwith distinct
uniqueKeyproperties. By default,uniqueKeyis generated from the URL, but it can also be overridden.\nTo add a single URL multiple times to the queue,\ncorresponding request dictionary will need to have differentuniqueKeyproperties.\n\nDo not instantiate this class directly, use theActor.open_request_queue()function instead.\n\nRequestQueuestores its data either on local disk or in the Apify cloud,\ndepending on whether theAPIFY_LOCAL_STORAGE_DIRorAPIFY_TOKENenvironment variables are set.\n\nIf theAPIFY_LOCAL_STORAGE_DIRenvironment variable is set, the data is stored in\nthe local directory in the following files:\n``\n{APIFY_LOCAL_STORAGE_DIR}/request_queues/{QUEUE_ID}/{REQUEST_ID}.json\n``", "Note that{QUEUE_ID}is the name or ID of the request queue. The default request queue has ID:default,\nunless you override it by setting theAPIFY_DEFAULT_REQUEST_QUEUE_IDenvironment variable.\nThe{REQUEST_ID}is the id of the request.\n\nIf theAPIFY_TOKENenvironment variable is set butAPIFY_LOCAL_STORAGE_DIRis not, the data is stored in the\nApify Request Queue\ncloud storage."]}