This module loads and returns proxies for easy use with requests.
Installation
This module is available via pip:
$ pip install proxy-manager
Basic Usage
proxies.txt:
00.11.222.33:4444 55.66.777.88:9999:username:password
test.py:
from proxymanager import ProxyManager
proxy_manager = ProxyManager('proxies.txt')
random_proxy = proxy_manager.random_proxy()
print(random_proxy) # { 'http':'http://...', 'https':'https://...' }
first_proxy = proxy_manager.next_proxy()
print(first_proxy.get_dict()) # { 'http':'http://00.11.222.33:4444', 'https':'https://00.11.222.33:4444' }
second_proxy = proxy_manager.next_proxy()
print(second_proxy.get_dict()) # { 'http':'http://username:password@55.66.777.88:9999', 'https':'https://username:password@55.66.777.88:9999' }
third_proxy = proxy_manager.next_proxy()
print(third_proxy.get_dict()) # { 'http':'http://00.11.222.33:4444', 'https':'https://00.11.222.33:4444' }
Documentation
Proxy File Format
Proxies in proxy files must have one of the following formats:
ip:port
or
ip:port:username:password
These can be combined and alternated.
ProxyManager
ProxyManager(proxy_file_path)
Returns a new ProxyManager instance given the path to a proxy file.
Parameters
string - File path to the proxy
Returns
ProxyManager - ProxyManager with proxies loaded
Example
from proxymngr import ProxyManager
proxy_manager = ProxyManager('proxies.txt')
ProxyManager.random_proxy
ProxyManager.random_proxy()
Returns a random proxy of those loaded into the proxy manager
Parameters
none
Returns
Proxy - Random proxy as a Proxy object
Example
random_proxy = proxy_manager.random_proxy()
print(random_proxy.get_dict()) # { 'http':'http://...', 'https':'https://...' }
ProxyManager.next_proxy
ProxyManager.next_proxy()
Returns proxies consecutively. Thread-safe. Loops continuously through available proxies, with wrapping.
Parameters
none
Returns
Proxy - Next proxy as a Project object
Example
first_proxy = proxy_manager.next_proxy()
print(first_proxy.get_dict()) # { 'http':'http://00.11.222.33:4444', 'https':'https://00.11.222.33:4444' }
Documentation for the Proxy object
Fields
string - ip string - port bool - is_auth string - username string - password
Proxy.get_dict
Proxy.get_dict()
Parameters
none
Returns
dict - Proxy as a dict in the form { 'http':'http://...', 'https':'https://...' } for use with requests
Example
```py proxy = proxy_manager.next_proxy() proxy_dict = first_proxy.get_dict() print(proxy_dict.get_dict()) # { ‘http’:’http://00.11.222.33:4444’, ‘https’:’https://00.11.222.33:4444’ }
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file proxy-manager-0.0.6.tar.gz.
File metadata
- Download URL: proxy-manager-0.0.6.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f02bb58d74da89d8aecb27742907dfb2dc18771c388364d2f490d3a1fb36be24
|
|
| MD5 |
9f6effba0e8d09bdaf5ce02fe78fb309
|
|
| BLAKE2b-256 |
e08939532288e7fa6f36e33ecc9f3a06678e706dc06c856b1c022034c3d1ba0f
|