> ## Documentation Index
> Fetch the complete documentation index at: https://developers.soax.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Working Python code for SOAX residential and mobile proxies. Copy-paste examples using the requests library.

These examples use the [requests](https://docs.python-requests.org/) library. Replace `YOUR_PACKAGE_KEY` with your actual package key from the [dashboard](https://platform.soax.com).

Install requests if you haven't already:

```bash theme={null}
pip install requests
```

## Residential proxies

### Rotating (new IP every request)

```python theme={null}
import requests

proxy_url = "http://country-us:YOUR_PACKAGE_KEY@proxy.soax.com:1337"

response = requests.get(
    "https://checker.soax.com/api/ipinfo",
    proxies={"http": proxy_url, "https": proxy_url},
)

print(response.json())
```

Each time you run this, you'll get a different IP.

### Session (same IP across requests)

```python theme={null}
import requests

proxy_url = "http://country-us-session-python1:YOUR_PACKAGE_KEY@proxy.soax.com:1337"

for i in range(3):
    response = requests.get(
        "https://checker.soax.com/api/ipinfo",
        proxies={"http": proxy_url, "https": proxy_url},
    )
    data = response.json()["data"]
    print(f"Request {i + 1}: {data['ip']} ({data['city']}, {data['country_code']})")
```

All three requests will return the same IP.

### Session with timed rotation

Rotate to a new IP every 5 minutes:

```python theme={null}
import requests

proxy_url = "http://country-us-session-job1-rotate-timed_300:YOUR_PACKAGE_KEY@proxy.soax.com:1337"

response = requests.get(
    "https://checker.soax.com/api/ipinfo",
    proxies={"http": proxy_url, "https": proxy_url},
)

print(response.json())
```

### Target a specific city and ISP

```python theme={null}
import requests

proxy_url = "http://country-us-city-los_angeles-isp-comcast:YOUR_PACKAGE_KEY@proxy.soax.com:1337"

response = requests.get(
    "https://checker.soax.com/api/ipinfo",
    proxies={"http": proxy_url, "https": proxy_url},
)

print(response.json())
```

### Session with error retry and lookalike replacement

```python theme={null}
import requests

proxy_url = "http://country-us-session-scrape1-onerror-retry_3-prefer-lookalike:YOUR_PACKAGE_KEY@proxy.soax.com:1337"

response = requests.get(
    "https://checker.soax.com/api/ipinfo",
    proxies={"http": proxy_url, "https": proxy_url},
)

print(response.json())
```

## Mobile proxies

Add `network-mob` to the proxy URL. Everything else works the same way.

### Rotating

```python theme={null}
import requests

proxy_url = "http://network-mob-country-us:YOUR_PACKAGE_KEY@proxy.soax.com:1337"

response = requests.get(
    "https://checker.soax.com/api/ipinfo",
    proxies={"http": proxy_url, "https": proxy_url},
)

print(response.json())
```

### Session

```python theme={null}
import requests

proxy_url = "http://network-mob-country-us-session-mobile1:YOUR_PACKAGE_KEY@proxy.soax.com:1337"

for i in range(3):
    response = requests.get(
        "https://checker.soax.com/api/ipinfo",
        proxies={"http": proxy_url, "https": proxy_url},
    )
    data = response.json()["data"]
    print(f"Request {i + 1}: {data['ip']} ({data['carrier']})")
```

### Target a specific carrier

```python theme={null}
import requests

proxy_url = "http://network-mob-country-us-isp-t_mobile-session-tm1:YOUR_PACKAGE_KEY@proxy.soax.com:1337"

response = requests.get(
    "https://checker.soax.com/api/ipinfo",
    proxies={"http": proxy_url, "https": proxy_url},
)

print(response.json())
```

## Multiple concurrent sessions

If you need to run several sessions in parallel (for example, scraping different targets), give each one a unique session ID:

```python theme={null}
import requests
from concurrent.futures import ThreadPoolExecutor

targets = [
    {"session": "target_a", "country": "us"},
    {"session": "target_b", "country": "gb"},
    {"session": "target_c", "country": "de"},
]

def fetch(target):
    proxy_url = f"http://country-{target['country']}-session-{target['session']}:YOUR_PACKAGE_KEY@proxy.soax.com:1337"
    response = requests.get(
        "https://checker.soax.com/api/ipinfo",
        proxies={"http": proxy_url, "https": proxy_url},
    )
    data = response.json()["data"]
    return f"{target['session']}: {data['ip']} ({data['country_code']})"

with ThreadPoolExecutor(max_workers=3) as pool:
    for result in pool.map(fetch, targets):
        print(result)
```

## Expected response

All examples return a JSON response from the SOAX checker:

```json theme={null}
{
  "status": true,
  "data": {
    "ip": "185.123.45.67",
    "country_code": "US",
    "country_name": "United States",
    "region": "California",
    "city": "Los Angeles",
    "isp": "Spectrum",
    "carrier": ""
  }
}
```

## Next steps

<CardGroup cols={2}>
  <Card title="Node.js examples" icon="code" href="/examples/nodejs">
    Working Node.js code for SOAX proxies.
  </Card>

  <Card title="Go examples" icon="code" href="/examples/go">
    Working Go code for SOAX proxies.
  </Card>

  <Card title="Residential proxies" icon="wifi" href="/proxies/residential">
    Full parameter reference.
  </Card>

  <Card title="Error codes" icon="triangle-exclamation" href="/troubleshooting/error-codes">
    What to do when something goes wrong.
  </Card>
</CardGroup>
