Skip to main content

A Library to easily load/fetch proxy servers.

Project description

ProxyCycle

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install proxycycle

Usage

######  Simple  ######

import proxycycle as pc
from proxycycle import filters as pcfilters
import requests

# Fetch proxies
pset = pc.ProxyScrape.fetch_proxyset(50, scheme = pc.Scheme.HTTP, timeout=300)

# Filter proxies
pset_filtered = pcfilters.DummyUseCheck(timeout=10).run(pset)
# Some checks support asyncio:
# pset_filtered = asyncio.run(pcfilters.DummyUseCheck(timeout=10).run_async(pset))

# Loop from start to end, then exit the loop
for proxy in pset_filtered:
    proxy_dict = {
        "http": proxy.toString(),
        "https": proxy.toString()
    }

    # request through proxy
    resp = requests.get(url, proxies = proxy_dict)

# Loop from start to end, forever, exit the loop only if/when there are no more proxies
for proxy in pset_filtered.cycle():
    proxy_dict = {
        "http": proxy.toString(),
        "https": proxy.toString()
    }
    resp = requests.get(url, proxies = proxy_dict)


###### Advanced ######

### Initialize a proxy object
from proxycycle.Proxy import Proxy
proxy1 = Proxy("127.0.0.1", 8080)
proxy2 = Proxy.fromString("127.0.0.1:8080")
proxy3 = Proxy.fromString("http://127.0.0.1:8080")

### Initialize a proxyset (manually)
from proxycycle.ProxySet import ProxySet
ps1 = ProxySet([proxy2, proxy3])

### Initialize a proxyset (from file)
with open('file.txt', 'r') as f:
    ps2 = ProxySet.fromFile(f)

### Initialize a proxyset (automatically)
from proxycycle.api.proxyscrape import ProxyScrape
ps3 = ProxyScrape.fetch_proxyset(limit = 50)

# Add a proxy to a proxyset
ps4 = ProxySet()
ps4.set_proxy(proxy1)

# Extend proxyset with other proxysets (ps4 = ps4 + ps1 + ps2 + ps3)
ps4.extend_with_proxysets(ps1, ps2, ps3)

# Filtering (Using .filter())
ps5 = ps4.filter(lambda p: p.scheme == Scheme.HTTP)

# Filtering (Using .filter_async())
import asyncio
async def check(p):
    import aiohttp
    try:
        async with aiohttp.ClientSession(proxy = p.toString()) as c:
            async with c.get(url) as resp:
                return True
    except Exception:
        return False
ps6 = asyncio.run(ps4.filter_async(check))

License

proxycycle is distributed under the terms of the MIT license.

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

proxycycle-2.0.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

proxycycle-2.0.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file proxycycle-2.0.0.tar.gz.

File metadata

  • Download URL: proxycycle-2.0.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for proxycycle-2.0.0.tar.gz
Algorithm Hash digest
SHA256 519d96ef609fc90912f1142d7dab31bdad2694a21c784d53f995e0ccc75d1fb7
MD5 b62fad14fd28291116a7242b3f936b4a
BLAKE2b-256 738195b3121705d82f0230f20e7e2bdaf72e2b1ecb6c79b29f5524a0c4fb692e

See more details on using hashes here.

File details

Details for the file proxycycle-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: proxycycle-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for proxycycle-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eaf130c258d5c64cc953bc56b180b3a29756e525de609b804ec98112286c1e76
MD5 c9239082d9226396cbf273fdc3739014
BLAKE2b-256 755deeb85cf69921ff9c5f526b3fb1b1e2188bef000ec0cdfd1942c0548c7033

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