Skip to main content
Sessions allow you to maintain state, cookies, and connection pooling across multiple requests. Scrapling provides three session types corresponding to each fetcher: FetcherSession, StealthySession, and DynamicSession.

Session Types Overview

FetcherSession (HTTP)

Fast HTTP sessions with browser impersonation.

Basic Usage

Configuration Options

Async Context Support

FetcherSession is context-aware and works in both sync and async:

Per-Request Overrides

StealthySession (Anti-Bot)

Persistent browser session with anti-bot capabilities.

Basic Usage

Configuration Options

Persistent Browser Profile

Maintain browser state across script runs:

Async Stealth Session

DynamicSession (Browser Automation)

Persistent browser session for automation.

Basic Usage

Configuration Options

Async Dynamic Session

Session Lifecycle

Always use context managers to ensure proper cleanup:

Manual Lifecycle

For advanced use cases:

Page Pooling (Browser Sessions)

Browser sessions (Stealthy and Dynamic) support page pooling for concurrent requests:

Pool Configuration

Pool Stats

Monitor pool usage:

Per-Request Customization

Override session settings per request:

Setting Cookies

Accessing Cookies

Browser sessions provide access to cookies through the page object:

Best Practices

Use with statements to ensure proper cleanup of sessions, especially for browser sessions.
Sessions maintain state and connections. Reuse them instead of creating new ones for each request.
Set sensible defaults at the session level and override only when needed per-request.
For browser sessions, use user_data_dir to maintain state across script runs.
Set max_pages based on your concurrency needs and system resources. More tabs = more memory.
Use get_pool_stats() to debug concurrency issues and optimize pool size.

Session Comparison

Next Steps

Proxy Rotation

Automatically rotate proxies in sessions

Spiders

Use sessions in spider crawls