Guides

Configuration

Control timeouts, retries, rate limits, proxies, and caching with ScraperConfig.

Every scraper accepts an optional ScraperConfig. It controls timeouts, retries, rate limiting, proxies, browser behavior, and caching.

from pyscrappy import ScraperConfig, GenericScraper
 
config = ScraperConfig(
    timeout=20.0,            # request timeout in seconds
    max_retries=3,           # retry failed requests
    rate_limit=2.0,          # seconds between requests per domain
    proxy="http://...",      # proxy URL, or a list to rotate through
    scraper_api=None,        # route via a scraping-API service (see Proxies)
    headless=True,           # browser runs headless
    render_js="auto",        # auto-detect if JS rendering is needed
    cache_ttl=0,             # response cache TTL in seconds (0 = disabled)
)
 
with GenericScraper(config) as gs:
    result = gs.scrape(url="https://example.com")

Options

OptionTypeDefaultDescription
timeoutfloat20.0Per-request timeout, in seconds.
max_retriesint3Retries on failure, with exponential backoff.
rate_limitfloat-Minimum seconds between requests per domain.
proxystr | list[str]NoneA proxy URL, or a list rotated one-per-request.
scraper_apidictNoneRoute through ScraperAPI / ScrapeOps / ScrapingBee.
headlessboolTrueWhether the browser backend runs headless.
render_js"auto" | bool"auto"Whether to render JavaScript with a browser.
cache_ttlfloat0Cache successful GETs for this many seconds (0 disables).

Applying config to any scraper

The same config object works for every scraper, so pass it to the constructor:

from pyscrappy import ScraperConfig, AmazonScraper
 
config = ScraperConfig(timeout=30.0, max_retries=5, rate_limit=1.0)
 
with AmazonScraper(config) as scraper:
    result = scraper.scrape(query="laptop")

See also: Proxies & blocked sites, Concurrency, and Caching.