human_requests.session¶
core.session — unified stateful session for curl_cffi and Playwright-compatible engines.
Main Methods¶
Session.request
— low-level HTTP request (curl_cffi) with cookie jar.Session.goto_page
— opens a URL in the browser, returns a Page inside a context manager; upon exit synchronizes cookies + localStorage.Response.render
— offline render of a pre-fetched Response.
Optional Dependencies¶
playwright-stealth: enabled via playwright_stealth=True. If the package is not installed and the flag is set — raises RuntimeError with installation instructions.
camoufox: selected with browser=’camoufox’.
patchright: selected with browser=’patchright’.
Incompatibility: camoufox/patchright + playwright_stealth cannot be used together. Raises RuntimeError.
Additional¶
Browser launch arguments are assembled via make_browser_launch_opts() from: - browser_launch_opts (arbitrary dict) - headless (always overrides the key of the same name) - proxy (string URL or dict) → adapted for Playwright/Patchright/Camoufox
Proxy is also applied to curl_cffi (if no custom proxy is passed in .request()).
Classes¶
curl_cffi.AsyncSession + BrowserMaster + CookieManager. |
Module Contents¶
- class Session(
- *,
- timeout: float = 15.0,
- headless: bool = True,
- browser: human_requests.browsers.Engine = 'chromium',
- spoof: ImpersonationConfig | None = None,
- playwright_stealth: bool = True,
- page_retry: int = 2,
- direct_retry: int = 1,
- browser_launch_opts: Mapping[str, Any] = {},
- proxy: str | None = None,
curl_cffi.AsyncSession + BrowserMaster + CookieManager.
- browser_name: human_requests.browsers.Engine = 'chromium'[source]¶
Current browser (chromium/firefox/webkit/camoufox/patchright).
- spoof: ImpersonationConfig[source]¶
Impersonation settings (user-agent, TLS, client-hello).
- playwright_stealth: bool = True[source]¶
Hide certain automation signatures? Implemented via JS injection. Some sites may detect this.
- proxy: str | dict[str, str] | None = None[source]¶
Proxy server, one of:
URL string in the form: schema://user:pass@host:port
playwright-like dict
- cookies: CookieManager[source]¶
Storage of all active cookies.
- local_storage: dict[str, dict[str, str]][source]¶
localStorage from the last browser context (goto run).
- async request(
- method: HttpMethod | str,
- url: str,
- *,
- headers: Mapping[str, str] | None = None,
- retry: int | None = None,
- **kwargs: Any,
Standard fast request via curl_cffi. You must provide either an HttpMethod or its string representation, as well as a URL.
Optionally, you can pass additional headers.
Extra parameters can be passed through **kwargs to curl_cffi.AsyncSession.request (see their documentation for details). Retries are performed ONLY on cffi Timeout:
curl_cffi.requests.exceptions.Timeout
.
- async goto_page(
- url: str,
- *,
- wait_until: Literal['commit', 'load', 'domcontentloaded', 'networkidle'] = 'commit',
- retry: int | None = None,
Opens a page in the browser using a one-time context. Retries perform a “soft reload” without recreating the context.
- async __aexit__(
- exc_type: type[BaseException] | None,
- exc: BaseException | None,
- tb: TracebackType | None,