Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Proxy Manager

Project description

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

  1. 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’ }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for proxy-manager, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size proxy-manager-0.0.6.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page