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.1.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.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: proxycycle-2.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 265887076d3b1d72cfcc2f6bd0f4d340ad746309aa7767c99629c20e6020b31a
MD5 b1d9c76594ce662bf346d840fa7b5b40
BLAKE2b-256 c1e86c49b59cf6c0de7d9079f42e7c09c74a9b2b946423aa3cbf9b0a9068e51d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: proxycycle-2.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78aef751871837bdac6442969d3523bdecf3dea189b4512bf50007a9b8b8d371
MD5 4b0b012f0f8c473df3d87467abe6aba4
BLAKE2b-256 7bd8f0c5d3bcd0bae35766b44bbf4ad2c0bc3dca549fcc92c523ed31a2fe449b

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