Regional Settings

Language

No languages match your search.

Team playbook

How Teams Rotate Proxies in Python: Two Script Patterns

C By Cheapest Proxies team Updated

Plenty of business data projects start life as a Python script that an analyst or developer writes for the team, and proxy rotation takes only a few lines to add. Two approaches work cleanly. The first points the Python requests library at a rotating gateway and leaves IP changes to the pool. The second cycles through a list of endpoints inside your own code. You will find both below with working examples, followed by a third snippet that holds a session and paces requests politely.

The examples assume legitimate collection of publicly available data, within each site's terms of service, robots directives and applicable law. No proxy can promise access, so every script should expect failures and handle them gracefully.

C
Cheapest Proxies team

We write these guides for e-commerce, marketing and agency teams that pay for proxies by the gigabyte.

Pattern 1: A rotating gateway (least code to maintain)

A rotating endpoint means every request goes to the same gateway address and the pool hands out a fresh IP automatically, so nobody has to maintain a list. With requests, one proxies dict is enough:

import requests

# One rotating gateway; the pool changes the exit IP for you.
proxies = {
    "http":  "http://USER:PASS@gateway.example:8000",
    "https": "http://USER:PASS@gateway.example:8000",
}

resp = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=20)
print(resp.json())  # a different exit IP on subsequent calls

We recommend this pattern for most teams. Rotation, location targeting and pool size all live on the server side, which keeps the script short and easy to pass from one colleague to another.

Pattern 2: Cycling your own list of endpoints

When your team holds a list of individual endpoints, such as static IPs, the script can rotate through them itself. Python's itertools.cycle handles the looping neatly:

import requests
from itertools import cycle

proxy_list = [
    "http://USER:PASS@ip1.example:8000",
    "http://USER:PASS@ip2.example:8000",
    "http://USER:PASS@ip3.example:8000",
]
pool = cycle(proxy_list)

urls = ["https://httpbin.org/ip"] * 6
for url in urls:
    proxy = next(pool)
    proxies = {"http": proxy, "https": proxy}
    try:
        r = requests.get(url, proxies=proxies, timeout=20)
        print(r.status_code, r.json())
    except requests.RequestException as e:
        print("request failed:", e)  # skip and continue

Holding a session and pacing requests

For a flow that spans several pages, a requests.Session reuses one connection throughout, and a short randomised pause between requests keeps the rate reasonable:

import requests, time, random

session = requests.Session()
session.proxies = {
    "http":  "http://USER:PASS@gateway.example:8000",
    "https": "http://USER:PASS@gateway.example:8000",
}

for path in ["/", "/page/2", "/page/3"]:
    r = session.get("https://example.com" + path, timeout=20)
    print(r.status_code)
    time.sleep(random.uniform(1.0, 3.0))  # be polite

The table shows which situations each approach suits.

Which Python rotation approach to use
Approach Suits Effort
Rotating gateway Most collection jobs; IPs managed for you Lowest (one proxies dict)
Cycle your own list Fixed/static IPs you manage Low (itertools.cycle)
Session + pacing Multi-step, stateful flows Low (Session + delay)

Making scripts dependable

  • Give every request a timeout and wrap calls in try/except, so a single failure cannot halt the run.
  • Retry temporary errors such as timeouts and 5xx responses with exponential backoff, and give up on hard failures.
  • Pace the script with randomised delays and modest concurrency, keeping the load on each site reasonable.
  • Pick the pool for the target: datacenter for lightly defended sites, residential for protected or location-specific ones.

Credentials, costs and next steps

Our proxies support HTTP/HTTPS and SOCKS5 (install requests[socks] for SOCKS) with username/password or IP-whitelist authentication across 55+ countries. Credentials appear in the dashboard as soon as an order is paid, ready to paste into the script. To budget the project, run the expected volume through the proxy calculator and check per-GB rates on the pricing page; when you are ready, buy proxies. For the wider process, see how to scrape a website.

Match the pool to the workflow

Every pool is billed per GB and run from the same dashboard, so one team can keep low-cost volume work and high-trust checks side by side.

Covering several markets in one report? MIX packages combine multi-country residential traffic in a single order. Agencies buying on behalf of clients can apply for the reseller programme.

Get your team running

Per-GB pricing from $3.50 · 55+ countries · instant delivery · 30-day validity · no traffic logs · 24/7 human support

  1. 1

    Size the job

    Pick a proxy type in the proxy calculator and enter the gigabytes you expect to use to see the order total.

  2. 2

    Order and pay

    Choose the pool on the proxies page and pay by card through Stripe or in crypto through Cryptomus. Each order is billed per GB and does not renew on its own.

  3. 3

    Share access

    Credentials appear in the dashboard as soon as payment clears. Add them to each tool with a login or an IP whitelist, then send one test request before the real job starts.

Questions team leads ask

Give the requests library a proxies dict that points at a rotating gateway; the pool then changes the exit IP for you. If your team manages fixed endpoints instead, rotate through them with itertools.cycle.
No, as long as the team uses a rotating gateway. All requests go to one endpoint and the pool assigns fresh IPs on the server side, so the code stays short. A list is needed only when you work with fixed or static IPs.
Open a requests.Session against a sticky endpoint so the whole task runs from one IP, and pause briefly, at random, between requests so the rate stays reasonable.
Yes. Install the SOCKS extra first (pip install 'requests[socks]'), then put a socks5:// URL in your proxies dict. Every plan we sell supports HTTP, HTTPS and SOCKS5.
Set a timeout on every call, wrap calls in try/except and retry temporary errors such as timeouts and 5xx responses with exponential backoff. That way one failure never stops the whole run.

More playbooks for your team

By workflow and market

Proxy types

All playbooks

What Are Proxies? A Primer for Business Teams Ad Verification Proxies: A Playbook for Ad-Ops Teams Web Scraping Proxies: Picking a Pool for Each Data Job Datacenter vs Residential Proxies: Which Should Your Team Buy? What Are Residential Proxies? When a Team Needs Home IPs Mobile vs Residential Proxies: Which Fits Your Team's Work? What Are Datacenter Proxies? The Low-Cost Pool for Volume Work How Rotating Proxies Work, and When Your Team Needs Them SOCKS5 vs HTTPS Proxies: Which Protocol Should Your Tools Use? Proxy vs VPN: Different Tools for Different Team Jobs How to Use a Proxy: A Setup Playbook for Teams How to Choose a Proxy for Each Business Workflow Shared vs Dedicated Proxies: Which Model Fits Your Team? Free vs Paid Proxies: The Business Case What Is an IP Address? Why It Shapes What Your Team Sees What Is a Residential IP, and When Does a Team Need One? Forward vs Reverse Proxy: Which One Does Your Team Use? What Are Mobile Proxies? Uses for Social, Ad and App Teams What Are ISP Proxies? Static Residential IPs for Account Work What Is a Sticky Session? One IP for a Whole Task Logins or IP Whitelists? Proxy Authentication for Teams Proxy Protocols for Business Tools: HTTP, HTTPS and SOCKS5 Rotating vs Sticky Sessions: Matching the Mode to the Workflow ISP vs Residential Proxies: Stability or Reach for Your Team? SEO Rank Tracking Proxies: A Playbook for Agencies Social Media Proxies for Agencies and Brand Teams Price Monitoring Proxies: A Guide for Pricing Teams eCommerce Monitoring Proxies: A Marketplace Team Playbook Market Research Proxies: Seeing Each Market Locally Competitor Intelligence with Proxies: What to Track and How How to Scrape a Website: A Five-Step Workflow for Teams How to Reduce CAPTCHAs When Your Team Collects Web Data How to Test Proxy Speed Before Your Team Commits Why Proxies Get Blocked and What Your Team Can Change Proxy Error Codes: A Troubleshooting Sheet for Teams How Many Proxies Does Your Team Need? How Teams Rotate Proxies in Python: Two Script Patterns Web Scraping Best Practices: A Policy Checklist for Teams
Cheapest Proxies logo

or
Continue with Email

By continuing you agree to our Terms and Privacy Policy.

Already have an account?

New here?

Subscriber offer

10% off
your team’s next order

Enter your work email and we’ll send the code there. It applies at checkout to any proxy plan, from datacenter to residential premium.

We send the code, then an occasional offer. To stop those emails, write to support and we’ll remove your address.

Your code is ready

Copy the 10% code below and paste it into the promo code field at checkout. A copy goes to your inbox too, so you can forward it to whoever places the order.

Choose a residential plan →