Skip to main content

A library to provide easy to use weighted proxy rotation and Proxy class to manage all of your proxies.

Project description

A library to add the ability to swap(rotate) proxies easily

This library will provide a Proxy class to manage all of your porxies plus Rotator class to obtain a Proxy based on weights of proxies. An exelent fit for requests and selenium libraries

An example usage for "selenium" library

    from proxy_rotator import Proxy, Rotator
    
    proxies: list[Proxy] = []
    # Load proxies from a file
    proxies_json = load_proxies("proxies.json")
    for proxy_item in proxies_json:
        proxies.append(Proxy(
            proxy_item['path'], 
            proxy_item['type'], 
            proxy_item['protocol'],
            proxy_item['status'], 
            proxy_item['weight'])
        )

    # Make a rotation for a proxy
    rotator = Rotator(proxies)
    # Get the random proxy by weight
    proxy = rotator.get()
    # Create a webdriver and put new proxy in use
    firefox_opt = Options()
    firefox_opt.add_argument('--headless')
    firefox_opt.add_argument("--no-sandbox")
    firefox_opt.add_argument("--disable-dev-shm-usage")  
    firefox_opt.add_argument(f"--proxy-server={proxy}")
    driver = webdriver.Firefox(options=firefox_opt)

An example usage for "requests" library

    from simple_proxy_rotator import proxy_to_requests_proxy
    from simple_proxy_rotator.proxy_rotator import Proxy, Rotator

    proxies: list[Proxy] = []
    # Load proxies from a file
    proxies_json = load_proxies("proxies.json")
    for proxy_item in proxies_json:
        proxies.append(Proxy(
            proxy_item['path'], 
            proxy_item['type'], 
            proxy_item['protocol'],
            proxy_item['status'], 
            proxy_item['weight'])
        )

    # Make a rotation for a proxy
    rotator = Rotator(proxies)
    # Get the random proxy by weight
    rotator_proxy = rotator_.get()
    # The returned proxy must be convert into string 
    # to be passed to requests.get method
    proxy = proxy_to_requests_proxy(rotator_proxy.ip, rotator_proxy.protocol)
    board_page = requests.get(url=url_, headers=conf.headers, proxies=proxy)

An example of "proxies.json" file content

  {
    "path": "100.100.100.100:1080",
    "protocol": "socks4",
    "type": "mobile",
    "weight": 1250.8024368286133,
    "status": "alive"
  },
  {
    "path": "100.100.100.100:1080",
    "protocol": "http",
    "type": "mobile",
    "weight": 1258.7508733272552,
    "status": "dead"
  },
  {
    "path": "100.100.100.100:1080",
    "protocol": "https",
    "type": "datacenter",
    "weight": 1350.0,
    "status": "alive"
  },
  {
    "path": "100.100.100.100:1080",
    "protocol": "https",
    "type": "datacenter",
    "weight": 850.4147324562073,
    "status": "dead"
  },
  {
    "path": "100.100.100.100:1080",
    "protocol": "socks4",
    "type": "datacenter",
    "weight": 1253.0103130340576,
    "status": "alive"
  },
  {
    "path": "100.100.100.100:1080",
    "protocol": "socks5",
    "type": "datacenter",
    "weight": 1250.8180613517761,
    "status": "alive"
  }
]

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

simple_proxy_rotator-0.0.1.tar.gz (5.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_proxy_rotator-0.0.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file simple_proxy_rotator-0.0.1.tar.gz.

File metadata

  • Download URL: simple_proxy_rotator-0.0.1.tar.gz
  • Upload date:
  • Size: 5.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for simple_proxy_rotator-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f34676e0fef511562de051a54c636bfaf8bd029bb922b8cb0630b00f6453e02d
MD5 6a0b157e763e92114acfc66fd72c7808
BLAKE2b-256 890f63120e8853a513059d939ee331f3d95ce78d143f49787448492733067c1b

See more details on using hashes here.

File details

Details for the file simple_proxy_rotator-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_proxy_rotator-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 294be3dde3f0870e0641a5688811630112e19875d2536e0373000f8e511590f5
MD5 54ce04204368c87f8693e1874a1c8551
BLAKE2b-256 db6071aa6b656780d3328a2a0cb5fa0799465a71beafecbb7c9a5d26c3905569

See more details on using hashes here.

Supported by

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