How Teams Rotate Proxies in Python: Two Script Patterns
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.
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.
| 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.
High-volume collection from unprotected sites, automation, SEO tools
Market research, ad verification and geo-accurate checks on protected sites
Phone-first platforms, app and mobile ad testing
Hard targets where every failed request is costly
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
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
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
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
More playbooks for your team
What Are Proxies? A Primer for Business Teams
What a proxy server does for a business team: how the relay works, the main IP types and their per-GB prices,…
Read the playbook →Ad Verification Proxies: A Playbook for Ad-Ops Teams
How ad-ops teams check placements, creatives and landing pages from residential and mobile IPs per market, wh…
Read the playbook →Web Scraping Proxies: Picking a Pool for Each Data Job
The proxy pool a data team needs for each scraping target: datacenter for open sites, residential for protect…
Read the playbook →Datacenter vs Residential Proxies: Which Should Your Team Buy?
Decide workflow by workflow whether datacenter or residential proxies fit: cost, speed, trust and location ta…
Read the playbook →What Are Residential Proxies? When a Team Needs Home IPs
Residential proxies use real home IPs. Which team workflows need them, how a request travels, how they compar…
Read the playbook →Mobile vs Residential Proxies: Which Fits Your Team's Work?
Mobile proxies use carrier 4G/5G IPs; residential proxies use home broadband. Decide by platform which one yo…
Read the playbook →