Python Integration
Use your exact NinjaProxy endpoint from the portal. For assigned/static proxies, copy the endpoint shown next to the IP. For rotating gateways, copy the rotating HTTP or SOCKS endpoint shown for your account.
Use the exact endpoint shown in Portal → Proxy IPs or Rotating Gateway IPs. Public docs intentionally use placeholders like <HTTP_ENDPOINT> because live host/port values are account-specific.requests
import requests
proxy_url = "http://<USERNAME>:<API_KEY>@<HTTP_ENDPOINT>"
proxies = {"http": proxy_url, "https": proxy_url}
response = requests.get("https://ip.ninjasproxy.com/", proxies=proxies, timeout=20)
print(response.text.strip())httpx
import httpx
proxy = "http://<USERNAME>:<API_KEY>@<HTTP_ENDPOINT>"
with httpx.Client(proxy=proxy, timeout=20) as client:
response = client.get("https://ip.ninjasproxy.com/")
print(response.text.strip())Rotating gateway headers
For rotating gateways, you can keep the same endpoint and change routing behavior with headers.
import requests
proxy = "http://<USERNAME>:<API_KEY>@<ROTATING_HTTP_ENDPOINT>"
headers = {
"X-Session-ID": "checkout-flow-42",
"X-Target-Geo": "US",
"X-Target-City": "NewYork",
}
response = requests.get(
"https://ip.ninjasproxy.com/",
proxies={"http": proxy, "https": proxy},
headers=headers,
timeout=20,
)
print(response.text.strip())Playwright
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(proxy={
"server": "http://<HTTP_ENDPOINT>",
"username": "<USERNAME>",
"password": "<API_KEY>",
})
page = browser.new_page()
page.goto("https://ip.ninjasproxy.com/")
print(page.text_content("body"))
browser.close()Retries
import requests
from tenacity import retry, stop_after_attempt, wait_exponential
PROXY = "http://<USERNAME>:<API_KEY>@<HTTP_ENDPOINT>"
@retry(stop=stop_after_attempt(5), wait=wait_exponential(min=2, max=30), reraise=True)
def fetch(url: str) -> requests.Response:
return requests.get(url, proxies={"http": PROXY, "https": PROXY}, timeout=20)
response = fetch("https://ip.ninjasproxy.com/")
print(response.text.strip())Next Steps
- Authentication — credential and whitelist setup
- Rate limits — connection reuse and concurrency guidance
- Residential proxies — assigned residential endpoints
- Rotating proxies — gateway-specific headers and sticky sessions
