ProxyInterface Class
swiftshadow.classes.ProxyInterface
Manages proxy acquisition, caching, and rotation from various providers.
This class handles proxy retrieval either through fresh fetching from registered providers or via cached data. It supports protocol filtering, country filtering, cache management, and automatic/manual proxy rotation.
Attributes:
Name | Type | Description |
---|---|---|
countries |
list[str]
|
List of ISO country codes to filter proxies by (e.g., ["US", "CA"]). |
protocol |
Literal['https', 'http']
|
Proxy protocol to use. Defaults to 'http'. |
maxproxies |
int
|
Maximum number of proxies to collect from providers. Defaults to 10. |
autorotate |
bool
|
Whether to automatically rotate proxy on each get() call. Defaults to False. |
autoUpdate |
bool
|
Whether to automatically update proxies upon class initalisation. Defaults to True. |
cachePeriod |
int
|
Number of minutes before cache is considered expired. Defaults to 10. |
cacheFolderPath |
Path
|
Filesystem path for cache storage. Uses system cache dir by default. |
proxies |
list[Proxy]
|
List of available proxy objects. |
current |
Proxy | None
|
Currently active proxy. None if no proxies available. |
cacheExpiry |
datetime | None
|
Timestamp when cache expires. None if no cache exists. |
Example
Raises:
Type | Description |
---|---|
UnsupportedProxyProtocol
|
If invalid protocol is specified during initialization. |
ValueError
|
If no proxies match filters during update(). |
Source code in swiftshadow/classes.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
__init__(countries=[], protocol='http', maxProxies=10, autoRotate=False, autoUpdate=True, cachePeriod=10, cacheFolderPath=None, debug=False, logToFile=False)
Initializes ProxyInterface with specified configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
countries
|
list[str]
|
List of ISO country codes to filter proxies. Empty list = no filtering. |
[]
|
protocol
|
Literal['https', 'http']
|
Proxy protocol to retrieve. Choose between 'http' or 'https'. |
'http'
|
maxProxies
|
int
|
Maximum proxies to collect from all providers combined. |
10
|
autoRotate
|
bool
|
Enable automatic proxy rotation on every get() call. |
False
|
autoUpdate
|
bool
|
Whether to automatically update proxies upon class initalisation. |
True
|
cachePeriod
|
int
|
Cache validity duration in minutes. |
10
|
cacheFolderPath
|
Path | None
|
Custom path for cache storage. Uses system cache dir if None. |
None
|
debug
|
bool
|
Enable debug logging level when True. |
False
|
logToFile
|
bool
|
Write logs to swiftshadow.log in cache folder when True. |
False
|
Source code in swiftshadow/classes.py
async_update()
async
Updates proxy list from providers or cache in async.
First attempts to load valid proxies from cache. If cache is expired/missing, fetches fresh proxies from registered providers that match country and protocol filters. Updates cache file with new proxies if fetched from providers.
Raises:
Type | Description |
---|---|
ValueError
|
If no proxies found after provider scraping. |
Source code in swiftshadow/classes.py
get()
Retrieves current active proxy.
Returns:
Name | Type | Description |
---|---|---|
Proxy |
Proxy
|
Current proxy object with connection details. |
Note
Performs automatic rotation if autorotate=True before returning proxy.
Raises:
Type | Description |
---|---|
ValueError
|
If no proxies are available (current is None). |
Source code in swiftshadow/classes.py
rotate(validate_cache=False)
Rotates to a random proxy from available proxies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
validate_cache
|
bool
|
Force cache validation before rotation when True. |
False
|
Note
Only required for manual rotation when autoRotate=False. Automatic rotation occurs during get() calls when autoRotate=True.
Raises:
Type | Description |
---|---|
ValueError
|
If validate_cache=True but no cache exists. |
Source code in swiftshadow/classes.py
update()
Updates proxy list from providers or cache.
First attempts to load valid proxies from cache. If cache is expired/missing, fetches fresh proxies from registered providers that match country and protocol filters. Updates cache file with new proxies if fetched from providers.
Raises:
Type | Description |
---|---|
ValueError
|
If no proxies found after provider scraping. |