Skip to main content

A simple wrapper for Requests to randomly select proxies

Project description

PyProxyRoulette

The pyproxyroulette library is a wrapper for the Requests library. The wrapper applies a random proxy to each request and ensures that the proxy is working and swaps it out when needed. Additionally, the wrapper tries to detect if a request has been blocked by the requested web-host. Blocked requests are repeated with different proxy servers.

Installation

This library is available on pypi. It can be installed as follows:

pip install pyproxyroulette

Example Wrapper Usage

from pyproxyroulette import ProxyRoulette
pr = ProxyRoulette()
pr.get("http://github.com")

The functions get, post, option, put, delete and head from the requests library are wrapped and callable through the wrapper. It is generally only recommended to call and use idempotent methods as requests which timeout can be registered by the server, despite not beeing registerd in time at the client. Hence it is only recommended to use the GET method in production environments.

Initialisation parameters

pr = ProxyRoulette(max_retries=5,
                   max_timeout=15,
                   func_proxy_validator=defaults.proxy_is_working,
                   func_proxy_response_validator=defaults.proxy_response_validator)
Parameter Default Description
max_retries 5 Number of retries with different proxies when a request fails. Set to 0 for unlimited retries.
max_timeout 15 Timeout until a request is assumed to have failed
func_proxy_validator defaults.proxy_is_working() Function, that can check if a specific (ip,port) combination is valid and working
func_proxy_response_validator defaults.proxy_response_validator() Function, which checks if a request has been blocked by inspecting the response. A blocked request will lead to repetition of the request using a different proxy

Extend the Pool of Proxies

It is possible to add functions to the system, which are called on a regular basis and return pairs of IP,PORT to be used in the proxy roulette. A proxy pool update function has to return a list of IP,PORT tuples. A default function is used to populate the proxy pool if no explicit function is defined. Multiple functions can be added using the following decorator:

from pyproxyroulette import ProxyRoulette

@ProxyRoulette.proxy_pool_updater
def my_cool_proxy_obtaining_function():
    return [("172.0.0.1",80),...]

pr = ProxyRoulette()

pr.get("http://some.url")

Disclaimer

THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Project details


Download files

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

Source Distribution

pyproxyroulette-0.4.9.tar.gz (10.7 kB view details)

Uploaded Source

Built Distributions

pyproxyroulette-0.4.9-py3.8.egg (22.3 kB view details)

Uploaded Source

pyproxyroulette-0.4.9-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file pyproxyroulette-0.4.9.tar.gz.

File metadata

  • Download URL: pyproxyroulette-0.4.9.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for pyproxyroulette-0.4.9.tar.gz
Algorithm Hash digest
SHA256 f82a2117f9207bf2b56ae25fdeff5cde67532f8db9fc2413c7b5ff8b28e009e4
MD5 94a5dc1c78c34d1f854c65a2c9a17933
BLAKE2b-256 ee90524165cc4a789fa814dc8ea6cf857bf72bc8f8a168a10ede13bff652d1f3

See more details on using hashes here.

File details

Details for the file pyproxyroulette-0.4.9-py3.8.egg.

File metadata

  • Download URL: pyproxyroulette-0.4.9-py3.8.egg
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for pyproxyroulette-0.4.9-py3.8.egg
Algorithm Hash digest
SHA256 12e5bc64855ced4521d4acde3da35d58ceb332ac7c8f9864b4bb720603c49325
MD5 c27e7a507ea8708b8cf9bf835720b36f
BLAKE2b-256 2a9d145328877f41ee57eaf3865ab6158f8563426753dc5835db7c50e7a55815

See more details on using hashes here.

File details

Details for the file pyproxyroulette-0.4.9-py3-none-any.whl.

File metadata

  • Download URL: pyproxyroulette-0.4.9-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for pyproxyroulette-0.4.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ee1b9e8f06aeddd7f26cc6e954cd88c890e99a7b012d801665fe24f7c528151c
MD5 95aee53790a91041ac8013aa5d024da9
BLAKE2b-256 f70949ccc84f1e6ee42afa37c3e2a0bf9df6cbf1996b697e06411022ad55edb3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page