proxywhirl.rotator.base

Shared base class for ProxyWhirl and AsyncProxyWhirl.

This module provides common functionality between sync and async rotators, reducing code duplication and ensuring consistent behavior.

Classes

ProxyRotatorBase

Shared logic for sync and async proxy rotators.

Module Contents

class proxywhirl.rotator.base.ProxyRotatorBase[source]

Shared logic for sync and async proxy rotators.

This base class provides common functionality for both ProxyWhirl and AsyncProxyWhirl, including: - Proxy dictionary conversion (credentials handling) - Circuit breaker state checking - Proxy selection with circuit breaker filtering - Common attribute initialization

pool

Proxy pool instance

strategy

Rotation strategy instance

config

Configuration settings

circuit_breakers

Circuit breaker instances per proxy

retry_policy

Retry policy configuration

retry_metrics

Retry metrics tracking

get_circuit_breaker_states()[source]

Get circuit breaker states for all proxies.

Returns:

Mapping of proxy IDs to their circuit breaker instances.

Return type:

dict[str, CircuitBreaker]

Note

Returns a copy to prevent external modification.

get_pool_stats()[source]

Get statistics about the proxy pool.

Returns:

Pool statistics including total_proxies, healthy_proxies, unhealthy_proxies, dead_proxies, total_requests, total_successes, total_failures, and average_success_rate.

Return type:

dict[str, Any]

get_retry_metrics()[source]

Get retry metrics.

Returns:

RetryMetrics instance with current metrics

Return type:

proxywhirl.retry.RetryMetrics

get_statistics()[source]

Get comprehensive statistics including source breakdown (FR-050).

Returns:

All stats from get_pool_stats() plus source_breakdown mapping source names to proxy counts.

Return type:

dict[str, Any]

reset_circuit_breaker(proxy_id)[source]

Manually reset a circuit breaker to CLOSED state.

Parameters:

proxy_id (str) – ID of the proxy whose circuit breaker to reset

Raises:

KeyError – If proxy_id not found

Return type:

None