Skip to main content
The Request class represents a single request in Scrapling’s spider framework. It encapsulates the URL, callback, priority, metadata, and session parameters for fetching and processing web pages.

Class Definition

Constructor

str
required
The URL to request.
str
default:"\"\""
Session ID to use for this request. If empty, the spider’s default session is used.
Callable | None
default:"None"
Async generator function to process the response. If None, the spider’s parse() method is used.
int
default:"0"
Request priority. Higher values are processed first. Default is 0.
bool
default:"False"
If True, this request won’t be filtered by the duplicate filter, even if it’s already been seen.
dict[str, Any] | None
default:"None"
Arbitrary metadata dictionary to pass along with the request. Merged with response.meta.
int
default:"0"
Internal retry counter (managed automatically by the engine).
Any
Additional session-specific keyword arguments (e.g., headers, proxy, method, data, json). These are passed to the session’s fetch method.

Attributes

str
The request URL.
str
Session ID for this request.
Callable | None
Response processing callback.
int
Request priority for scheduling.
bool
Whether to bypass duplicate filtering.
dict[str, Any]
Metadata dictionary.
str
Cached property that extracts the domain from the URL (e.g., “example.com”).

Methods

copy

Create a copy of this request. Useful when retrying or modifying requests. Returns: A new Request instance with copied attributes Example:

update_fingerprint

Generate a unique fingerprint for deduplication. The fingerprint is cached in self._fp after first computation.
bool
default:"False"
Include session kwargs (except data/json) in the fingerprint.
bool
default:"False"
Include request headers in the fingerprint.
bool
default:"False"
Keep URL fragments when canonicalizing the URL for fingerprinting.
Returns: SHA-1 hash bytes representing the unique fingerprint
The fingerprint is based on: URL (canonicalized), session ID, HTTP method, request body (data/json), and optionally headers and kwargs.

Special Methods

Comparison

Requests can be compared for priority-based sorting:

Equality

Requests are equal if they have the same fingerprint:
You must call update_fingerprint() before comparing requests with ==, otherwise a RuntimeError is raised.

String Representation

Serialization

Requests support pickling for checkpoint/resume functionality. The callback is stored as a method name string and restored from the spider instance.

Usage Examples

Basic Request

POST Request with JSON

Request with Custom Callback

Request with Metadata

Request with Different Session

Request with Proxy

Bypassing Duplicate Filter

Internal Attributes

int
Number of times this request has been retried (managed by CrawlerEngine).
dict
Dictionary of keyword arguments to pass to the session’s fetch method.
bytes | None
Cached fingerprint bytes. None until update_fingerprint() is called.
str | None
Temporary attribute used during pickling to store callback method name.

See Also