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())aiohttp
Build the proxy URL from your portal username, API key, and the exact host/port shown in the portal. The host and port are portal-assigned, so keep <HTTP_ENDPOINT> as a placeholder in public docs and replace it with your copied endpoint locally.
import aiohttp
import asyncio
PROXY = "http://<USERNAME>:<API_KEY>@<HTTP_ENDPOINT>"
TIMEOUT = aiohttp.ClientTimeout(total=20)
async def main() -> None:
async with aiohttp.ClientSession(timeout=TIMEOUT) as session:
async with session.get("https://ip.ninjasproxy.com/", proxy=PROXY) as response:
print((await response.text()).strip())
asyncio.run(main())Scrapy
For Scrapy, set request.meta["proxy"] to the same authenticated proxy URL. As with the other Python clients, the gateway host and port are portal-assigned and must come from the exact endpoint shown in the portal.
class NinjaProxyMiddleware:
def process_request(self, request, spider):
request.meta["proxy"] = "http://<USERNAME>:<API_KEY>@<HTTP_ENDPOINT>"# settings.py
DOWNLOADER_MIDDLEWARES = {
"myproject.middlewares.NinjaProxyMiddleware": 543,
}Rotating gateway username controls
For rotating gateways, keep the same endpoint and append structured controls to the username when you need sticky sessions or routing overrides.
import requests
proxy = "http://<USERNAME>--session-checkout-flow-42--duration-90--provider-res--geo-country-us:<API_KEY>@<ROTATING_HTTP_ENDPOINT>"
response = requests.get(
"https://ip.ninjasproxy.com/",
proxies={"http": proxy, "https": proxy},
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 — username controls, headers, and sticky sessions
