ProxyRotator provides thread-safe proxy rotation with pluggable strategies. It works seamlessly with all fetchers and sessions (HTTP, Stealthy, and Dynamic).
Basic Usage
With HTTP Sessions
With Browser Sessions
Proxy Formats
String Format (HTTP Sessions)
ForFetcherSession:
Dict Format (Browser Sessions)
ForStealthySession and DynamicSession:
Mixed Format Support
Rotation Strategies
Cyclic Rotation (Default)
Rotates through proxies sequentially:Custom Rotation Strategy
Implement your own rotation logic:Weighted Rotation
Give higher probability to certain proxies:Sticky Session Strategy
Stick to one proxy until it fails:Automatic Retry on Proxy Failure
Scrapling automatically detects proxy errors and retries with the next proxy:net::err_proxynet::err_tunnelconnection refusedconnection resetconnection timed outfailed to connectcould not resolve proxy
Per-Request Proxy Override
Override the rotator for specific requests:ProxyRotator API
Constructor
Methods
Usage with Different Sessions
FetcherSession
StealthySession
AsyncStealthySession
DynamicSession
Advanced Example: Rate-Limited Scraping
Rotate proxies to bypass rate limits:Best Practices
Use enough proxies
Use enough proxies
Have at least 3-5 proxies in your rotation pool. More proxies = better distribution and resilience.
Configure retry settings
Configure retry settings
Set appropriate
retries and retry_delay when using proxy rotation. Failed proxies will be skipped automatically.Match proxy format to session type
Match proxy format to session type
Use string format for
FetcherSession and dict format for browser sessions (StealthySession, DynamicSession).Test proxies before adding
Test proxies before adding
Validate that your proxies work before adding them to the rotator. Bad proxies will cause retry delays.
Monitor proxy performance
Monitor proxy performance
Log proxy usage and failures to identify problematic proxies and optimize your pool.
Use custom strategies for advanced needs
Use custom strategies for advanced needs
Implement custom rotation strategies for weighted selection, geo-targeting, or performance-based rotation.
Proxy Rotation vs Static Proxy
Thread Safety
ProxyRotator is thread-safe and can be shared across threads:
Next Steps
Sessions
Learn more about session management
Spiders
Use proxy rotation in spider crawls