Regional Preferences

Language

Nothing in the list matches what you typed there.

Beginner guide

Python and Rotating Proxies: A Gentle First Walkthrough

B By Budget Proxies team Plain-English proxy guides · Updated

Rotating proxies simply means sending your requests out through different IP addresses instead of always the same one. In Python it's easier than it sounds, and there are two tidy ways to do it. The simplest hands the job to a rotating gateway: you point the requests library, a widely used tool for fetching web pages, at it, and the pool switches IPs for you. The other is to keep your own list of proxy addresses and cycle through it. You'll find both below, with working examples and a sensible pace.

Every example is meant for legitimate collection of public data. Keep to each site's terms of service, its robots.txt rules for automated visitors and the law. And since no proxy can promise access, write your code to cope calmly with errors.

B
Budget Proxies team · Plain-English proxy guides

Written and kept up to date by the people who run Budget Proxies. If a step no longer matches what you see on your screen, let us know through the contact page.

What this guide walks you through

  • The easy way: let a gateway swap IPs for you
  • The hands-on way: step through a list of your own
  • Staying on one IP for a short task, with pauses
  • Tips that save beginners trouble
  • Getting your script connected

The easy way: let a gateway swap IPs for you

Here you only ever talk to one address, the gateway. Behind it, the pool picks a new IP for each request, so there's nothing for you to keep track of. All requests needs is a proxies dict (a small dictionary telling it which proxy to use):

import requests

# One rotating gateway; the pool changes the exit IP for you.
proxies = {
    "http":  "http://USER:[email protected]:8000",
    "https": "http://USER:[email protected]:8000",
}

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

This is the approach we suggest for beginners: we look after the rotation, the location targeting and the size of the pool, and your code stays short.

The hands-on way: step through a list of your own

If you have a list of separate proxy addresses (for example static IPs that don't change), you can rotate through them yourself. Python's itertools.cycle goes round the list in order and starts again at the top when it reaches the end:

import requests
from itertools import cycle

proxy_list = [
    "http://USER:[email protected]:8000",
    "http://USER:[email protected]:8000",
    "http://USER:[email protected]: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

Staying on one IP for a short task, with pauses

A requests.Session reuses one connection across several steps, which helps when a task has to happen in order. Add a short, random pause between requests to keep your pace reasonable:

import requests, time, random

session = requests.Session()
session.proxies = {
    "http":  "http://USER:[email protected]:8000",
    "https": "http://USER:[email protected]: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 below shows when to use each approach.

Three ways to rotate in Python, compared
Approach Good for Effort
Let the gateway rotate Most scraping; the pool picks the IPs Very little (one proxies dict)
Go round your own list Fixed or static IPs you look after A little (itertools.cycle)
One session, with pauses Tasks with several steps in order A little (Session plus a pause)

Tips that save beginners trouble

  • Give every request a timeout, and put it inside try/except (Python's way of catching errors); then a single failure can't bring the whole script down.
  • Retry temporary errors (timeouts, and server errors starting with a 5) with exponential backoff, waiting longer between each try, rather than giving up at the first failure.
  • Slow down with random pauses and only a few requests at once, so the load on the site stays reasonable.
  • Choose the right pool for each site: datacenter (server IPs) is fine where protection is light; use residential (home IPs) where it's strict or the content depends on location.

Getting your script connected

Every plan supports HTTP/HTTPS and SOCKS5 (for SOCKS, install requests[socks]), with a username/password login or an IP whitelist that approves your own address, across 55+ countries. Sizing help is on the proxy calculator, the rates are on the pricing page, and you can buy now when you're ready. Want the whole process from start to finish? Our beginner's walkthrough, how to scrape a website, covers it.

Questions beginners ask

Give the requests library a proxies dict pointing at a rotating gateway, and that's it: each request leaves from a different exit IP without any extra code. If you have your own list instead, itertools.cycle will step through it.
No, the rotating gateway takes care of that. You send every request to one endpoint, fresh IPs are handled on our side, and your code stays short. A list of your own only comes into it when you're working with fixed or static IPs.
Use a requests.Session together with a sticky endpoint, and a series of steps will stay on the same IP. Add a short random pause between calls to keep your pace sensible.
That works too. First add SOCKS support by running pip install 'requests[socks]'. Once that's done, a socks5:// address in your proxies dict is all you need. All our plans work with HTTP, HTTPS and SOCKS5.
Teach it to shrug failures off. Put a timeout on every call, catch errors with try/except, and retry the temporary ones (timeouts, 5xx) with exponential backoff, so a single failure never ends the run.

Not sure what to buy? Start at step 1

Here are our four types, from the lowest price per GB upwards. Try a small amount of the first one that could work for your project, and only move up a step if a quick test lets you down.

Small first order? Datacenter from $2.49/GB · billed on the data you actually move · ready straight away · 30 days to use it · no traffic logs.

What to read next

Ready to try your first proxy?

Choose from 55+ countries, pay from $2.49/GB for only the data you use, and get your login details straight away. If a step trips you up, human support is there 24/7.

The four types

Every guide on the site

What Are Proxies? A Starting Point for Beginners What Are Datacenter Proxies? The Low-Cost Place to Start What Are Residential Proxies? Home Addresses, Explained Datacenter vs Residential Proxies: Which Should a Beginner Buy? Mobile vs Residential Proxies: Do You Really Need Mobile? Proxy or VPN? The Difference, and Which One You Need SOCKS5 or HTTPS? Choosing a Proxy Protocol Without the Jargon How Rotating Proxies Work, Explained Without Jargon Which Proxy Type Suits Your Web Scraping Project? Checking Your Ads Appear Where You Paid for Them How to Use a Proxy: A First-Timer's Walkthrough How to Choose a Proxy Without Overspending Shared vs Dedicated Proxies: Do You Need Your Own IP? Free vs Paid Proxies: Is Free Ever Good Enough? What Is an IP Address? A Plain-English Guide What Is a Residential IP? (You Probably Have One) Forward vs Reverse Proxy, Explained with Everyday Examples What Are Mobile Proxies, and Do You Need One? What Are ISP Proxies? Home-Registered IPs on Fast Servers Sticky Sessions Explained: When Your IP Should Stay the Same Proxy Authentication for Beginners: Password or Whitelist? Proxy Protocols in Plain English: HTTP, HTTPS and SOCKS5 Rotating vs Sticky Sessions: Which One Do You Need? ISP vs Residential Proxies: Which Suits a Small Project? Checking Your Search Rankings from Another Place Social Media Accounts and Proxies: A Beginner's Guide Keeping an Eye on Prices in Other Countries Checking Online Shops and Listings from Abroad Market Research with Proxies for Small Projects Following Your Competitors, the Simple Way Your First Web Scrape with Proxies, Step by Step Getting Lots of CAPTCHAs? Why, and How to See Fewer Is My Proxy Fast? How to Test It Properly Why Your Proxy Got Blocked, in Plain English What Your Proxy Error Code Is Telling You Not Sure How Many Proxies to Buy? Start Here Python and Rotating Proxies: A Gentle First Walkthrough Web Scraping the Polite Way: Habits to Learn Early

New to proxies? Start with a small order

Datacenter proxies cost $2.49 per gigabyte (GB) of data you use, so trying one on the site you care about needn’t cost much. Your login details are ready within seconds, and if you get stuck, a real person answers questions 24/7.

Budget Proxies logo

or
Continue with Email

Continue and you're agreeing to our Terms and Privacy Policy.

Already set up with us?

First time with us?

🎉 Money-off code

Knock 10% off
your next order

Type your email below and we’ll send the code over. It works on any proxy plan, however small the order. At checkout, paste it into the Promo code box and press Apply.

You’ll get the code and, now and then, an offer by email. Changed your mind later? Ask us and we’ll take you off the list.

Sorted! It’s on its way 📬

Your 10% code is heading to your inbox. No need to wait for the email, though: copy it from here and paste it in when you check out.

See residential plans →