Handling HTTP/3 Requests with Scrapling's Fetcher Class: A Complete Guide
Scrapling enables HTTP/3 requests through the optional http3 parameter in the Fetcher and AsyncFetcher classes, which internally configures curl-cffi to use CurlHttpVersion.V3ONLY.
Scrapling is a Python web scraping library built on top of curl-cffi, providing high-level abstractions through its Fetcher and AsyncFetcher classes. When handling HTTP/3 requests with Scrapling's Fetcher class, developers can leverage the optional http3 flag to force HTTP/3-only connections, though this requires understanding the internal configuration flow from session initialization through to the actual curl execution.
How HTTP/3 Support Works in Scrapling
Scrapling's HTTP client architecture delegates protocol handling to curl-cffi, with HTTP/3 support controlled through a cascading configuration system.
The http3 Configuration Flag
The http3 parameter is defined as an optional boolean throughout the codebase. In scrapling/engines/_browsers/_types.py (line 32), the RequestsSession TypedDict declares http3: Optional[bool], making the flag part of the type-checked API. This parameter propagates from high-level fetcher classes down to the static engine that interfaces with curl-cffi.
Internal Implementation Details
The actual HTTP/3 activation occurs in scrapling/engines/static.py through three key phases:
-
Session Initialization (lines 71-84): The
__init__method storesself._default_http3from thehttp3kwarg, establishing the session-wide default. -
Argument Merging (lines 104-108): The
_merge_request_argsmethod reads a request-levelhttp3flag, falling back to the session default if not provided. -
Curl Version Switch (lines 156-162): When
http3is truthy, the code injectshttp_version = CurlHttpVersion.V3ONLYinto the arguments passed to curl-cffi. This section also emits a warning ifimpersonateis active, as some sites reject HTTP/3 when custom browser headers are generated.
Enabling HTTP/3 in Your Code
Scrapling provides multiple patterns for activating HTTP/3 depending on your architecture needs.
Session-Level Configuration
For applications requiring HTTP/3 across multiple requests, configure the session once using FetcherSession:
from scrapling.fetchers.requests import FetcherSession
# All requests inside this context will use HTTP/3
with FetcherSession(http3=True) as sess:
resp = sess.get("https://http3.tech")
print(resp.status_code, resp.http_version) # → 200, "HTTP/3"
This approach stores the http3=True default in scrapling/engines/static.py and applies it to every request made through that session instance.
Per-Request Overrides
When you need HTTP/3 only for specific calls while maintaining standard HTTP/1.1 or HTTP/2 for others:
from scrapling.fetchers.requests import FetcherSession
with FetcherSession() as sess: # default: HTTP/1.1/2
# Normal request – no HTTP/3
r1 = sess.get("https://example.com")
print(r1.http_version) # e.g. "HTTP/2"
# Force HTTP/3 just for this call
r2 = sess.get("https://http3.tech", http3=True)
print(r2.http_version) # "HTTP/3"
The _merge_request_args method in scrapling/engines/static.py handles this fallback logic, checking for a request-level http3 parameter before defaulting to the session configuration.
Using the Fetcher Facade
For quick scripts or single requests, use the low-level Fetcher class directly:
from scrapling.fetchers.requests import Fetcher
# Fetcher is a thin wrapper around a global SyncSession instance
resp = Fetcher.get("https://http3.tech", http3=True)
print(resp.http_version) # "HTTP/3"
This approach bypasses explicit session management while still supporting the http3 parameter through the same underlying mechanism in scrapling/engines/static.py.
Important Considerations and Warnings
HTTP/3 and Browser Impersonation Conflicts
When combining http3=True with the impersonate parameter (which generates browser-like headers), Scrapling emits a warning from scrapling/engines/static.py (lines 156-162). Some servers reject HTTP/3 connections when they detect mismatched or custom browser headers, potentially causing connection errors.
import logging
logging.basicConfig(level=logging.WARNING)
from scrapling.fetchers.requests import FetcherSession
with FetcherSession(http3=True, impersonate="chrome") as sess:
sess.get("https://http3.tech")
# → WARNING: The argument `http3` might cause errors if used with `impersonate` argument...
Recommendation: Disable impersonation (impersonate=False) when you need reliable HTTP/3 connectivity, or test thoroughly against your target site to verify compatibility.
Summary
- Scrapling supports HTTP/3 through the optional
http3boolean parameter inFetcher,AsyncFetcher, andFetcherSessionclasses. - The flag propagates through
scrapling/engines/static.py, where_merge_request_argsinjectsCurlHttpVersion.V3ONLYwhen HTTP/3 is enabled. - Configure HTTP/3 at the session level for consistency across requests, or override per-request for selective usage.
- Avoid combining
http3=Truewithimpersonateunless you have verified server compatibility, as this triggers warnings and potential connection failures.
Frequently Asked Questions
Does Scrapling support HTTP/3 by default?
No, HTTP/3 is disabled by default in Scrapling. You must explicitly set http3=True either when creating a FetcherSession or on individual request methods. The default behavior uses HTTP/1.1 or HTTP/2 depending on server support and curl-cffi's negotiation.
Can I use HTTP/3 with browser impersonation?
While technically possible, combining http3=True with the impersonate parameter is not recommended. According to the implementation in scrapling/engines/static.py, this combination triggers a warning because some servers reject HTTP/3 connections when they detect custom browser headers. For reliable HTTP/3 requests, disable impersonation by setting impersonate=False.
How do I check if a response used HTTP/3?
The response object returned by Scrapling's fetcher methods includes an http_version attribute. After making a request with http3=True, inspect response.http_version to verify the protocol. A successful HTTP/3 connection will return the string "HTTP/3" or similar, depending on how curl-cffi reports the version.
Is HTTP/3 available in AsyncFetcher?
Yes, the AsyncFetcher class supports the same http3 parameter as the synchronous Fetcher. The underlying FetcherSession and AsyncFetcherSession classes in scrapling/fetchers/requests.py both expose the http3 argument, which propagates to the same _merge_request_args logic in scrapling/engines/static.py for protocol negotiation.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →