Try 500 MB of US mobile proxy data free for 30 days.Start free trial

Integrations

Python

Proxy setup for requests and httpx over HTTP and SOCKS5.

The examples use mlabs_a1f9c3 / <PASSWORD>. Replace them with your own credential. Suffixes on the username select the session mode and location, see Rotating vs sticky sessions and Location targeting.

requests

pip install requests
import requests

PROXY = "http://mlabs_a1f9c3:<PASSWORD>@proxy.masklabs.io:8080"

resp = requests.get(
    "https://ipinfo.io/json",
    proxies={"http": PROXY, "https": PROXY},
)
print(resp.json())

The keys in proxies are the target URL's scheme. Both point at the same proxy URL.

A requests.Session reuses connections, so requests made through one session share an exit IP until the connection closes. Use a plain requests.get per request, or a new session per request, to get a new IP each time.

For SOCKS5:

pip install "requests[socks]"
PROXY = "socks5h://mlabs_a1f9c3:<PASSWORD>@proxy.masklabs.io:1080"

Use socks5h, not socks5, so DNS is resolved through the proxy.

httpx

pip install httpx
pip install "httpx[socks]"   # for SOCKS5
import httpx

PROXY = "http://mlabs_a1f9c3:<PASSWORD>@proxy.masklabs.io:8080"

with httpx.Client(proxy=PROXY) as client:
    resp = client.get("https://ipinfo.io/json")
    print(resp.json())

httpx.AsyncClient(proxy=PROXY) takes the same argument. A client pools connections; requests through one client share an exit IP until the connection closes.

Sticky, pinned to a location, over SOCKS5:

PROXY = "socks5h://mlabs_a1f9c3_loc_ORD_sticky:<PASSWORD>@proxy.masklabs.io:1080"