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

# Python

> Working Python code for FlameProxies residential, premium residential, and static proxies. Copy-paste examples using the requests library.

These examples use the [requests](https://requests.readthedocs.io/) library. Replace `USERNAME` and `PASSWORD` with your package credentials from the [dashboard](https://flameproxies.com/dashboard).

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://USERNAME-package-standard-country-us:PASSWORD@proxy.flameproxies.com:8989"

response = requests.get(
    "https://ipinfo.io/json",
    proxies={"http": proxy_url, "https": proxy_url},
    timeout=30,
)

print(response.json())
```

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

### Sticky session (same IP across requests)

```python theme={null}
import requests

proxy_url = "http://USERNAME-package-standard-country-us-session-py1-time-30:PASSWORD@proxy.flameproxies.com:8989"

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

All three requests return the same IP. The session holds it for up to 30 minutes.

### Target a specific city

```python theme={null}
import requests

proxy_url = "http://USERNAME-package-standard-country-us-city-newyorkcity:PASSWORD@proxy.flameproxies.com:8989"

response = requests.get(
    "https://ipinfo.io/json",
    proxies={"http": proxy_url, "https": proxy_url},
    timeout=30,
)

print(response.json())
```

### Fast mode and sub-pools

Route through the lowest-latency peer in sub-pool 1:

```python theme={null}
import requests

proxy_url = "http://USERNAME-package-standard-country-us-pool-1-mode-fast:PASSWORD@proxy.flameproxies.com:8989"

response = requests.get(
    "https://ipinfo.io/json",
    proxies={"http": proxy_url, "https": proxy_url},
    timeout=30,
)

print(response.json())
```

## Premium residential proxies

Use `package-premium` instead of `package-standard`. Everything else works the same way.

### Rotating

```python theme={null}
import requests

proxy_url = "http://USERNAME-package-premium-country-us:PASSWORD@proxy.flameproxies.com:8989"

response = requests.get(
    "https://ipinfo.io/json",
    proxies={"http": proxy_url, "https": proxy_url},
    timeout=30,
)

print(response.json())
```

### Sticky session

```python theme={null}
import requests

proxy_url = "http://USERNAME-package-premium-country-gb-session-c3d4-time-20:PASSWORD@proxy.flameproxies.com:8989"

with requests.Session() as session:
    session.proxies = {"http": proxy_url, "https": proxy_url}
    for i in range(3):
        print(session.get("https://ipinfo.io/json", timeout=30).json()["ip"])
```

## SOCKS5

Install SOCKS support for requests:

```bash theme={null}
pip install "requests[socks]"
```

Then connect on port `1080`. The `socks5h` scheme resolves hostnames through the proxy, so DNS lookups don't leak from your machine:

```python theme={null}
import requests

proxy_url = "socks5h://USERNAME-package-standard-country-us:PASSWORD@proxy.flameproxies.com:1080"

response = requests.get(
    "https://ipinfo.io/json",
    proxies={"http": proxy_url, "https": proxy_url},
    timeout=30,
)

print(response.json())
```

## Static residential (ISP) proxies

Static proxies use a dedicated host for each IP:

```python theme={null}
import requests

proxy_url = "http://USERNAME-203.0.113.10:PASSWORD@203.0.113.10.static.flameproxies.com:1337"

response = requests.get(
    "https://ipinfo.io/json",
    proxies={"http": proxy_url, "https": proxy_url},
    timeout=30,
)

print(response.json())
```

Replace `203.0.113.10` with your static IP. The dashboard shows the exact line for each IP you own.

ISP Monthly IPs (United States) connect straight to the IP instead, with no `.static.flameproxies.com` hostname:

```python theme={null}
proxy_url = "http://USERNAME:PASSWORD@203.0.113.10:PORT"
```

ISP Monthly IPs (United States) connect straight to the IP instead, with no `.static.flameproxies.com` hostname:

```python theme={null}
proxy_url = "http://USERNAME:PASSWORD@203.0.113.10:PORT"
```

## Multiple concurrent sessions

There are no limits on threads or concurrent connections. To run several sticky sessions in parallel — for example, one per target — give each one its own session ID:

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

targets = [
    {"session": "targeta", "country": "us"},
    {"session": "targetb", "country": "gb"},
    {"session": "targetc", "country": "de"},
]

def fetch(target):
    proxy_url = (
        f"http://USERNAME-package-standard-country-{target['country']}"
        f"-session-{target['session']}-time-10:PASSWORD@proxy.flameproxies.com:8989"
    )
    response = requests.get(
        "https://ipinfo.io/json",
        proxies={"http": proxy_url, "https": proxy_url},
        timeout=30,
    )
    data = response.json()
    return f"{target['session']}: {data['ip']} ({data['country']})"

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 [ipinfo.io](https://ipinfo.io):

```json theme={null}
{
  "ip": "203.0.113.45",
  "city": "Los Angeles",
  "country": "US",
  "timezone": "America/Los_Angeles"
}
```

## Next steps

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

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

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

  <Card title="Connection debugging" icon="wrench" href="/troubleshooting/connection-debugging">
    What to do when something goes wrong.
  </Card>
</CardGroup>
