PacketStream documentation

Language integrations

Connect to PacketStream with cURL, Python Requests, Node.js Undici, Go net/http, or Playwright using authenticated HTTPS proxy configuration.

Use the recommended HTTPS endpoint unless your client specifically requires SOCKS5. The examples read credentials from environment variables and request ipinfo.io so you can inspect the observed exit.

Set these values before running an example:

export PACKETSTREAM_USER='your_username'
export PACKETSTREAM_AUTH_KEY='your_auth_key'

Do not commit real credentials to a script, .env file, test fixture, or container image.

cURL

curl --silent --show-error --fail-with-body \
  --proxy 'https://proxy.packetstream.io:31111' \
  --proxy-user "${PACKETSTREAM_USER}:${PACKETSTREAM_AUTH_KEY}" \
  'https://ipinfo.io' \
  | jq '{ip, hostname, city, region, country, loc, org, postal, timezone}'

Use --connect-timeout and --max-time when the command runs unattended.

Python with Requests

Install Requests:

python -m pip install requests
import os
from urllib.parse import quote

import requests

username = quote(os.environ["PACKETSTREAM_USER"], safe="")
auth_key = quote(os.environ["PACKETSTREAM_AUTH_KEY"], safe="")
proxy = f"https://{username}:{auth_key}@proxy.packetstream.io:31111"

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

Pass the proxies dictionary on the request so environment proxy settings cannot unexpectedly replace the intended configuration. See the official Requests proxy documentation.

Node.js with Undici

Install the current Undici package:

npm install undici
import { ProxyAgent, fetch } from "undici";

const username = process.env.PACKETSTREAM_USER;
const authKey = process.env.PACKETSTREAM_AUTH_KEY;

if (!username || !authKey) {
  throw new Error("Set PACKETSTREAM_USER and PACKETSTREAM_AUTH_KEY");
}

const token = Buffer.from(`${username}:${authKey}`).toString("base64");
const dispatcher = new ProxyAgent({
  uri: "https://proxy.packetstream.io:31111",
  token: `Basic ${token}`,
});

try {
  const response = await fetch("https://ipinfo.io", {
    dispatcher,
    signal: AbortSignal.timeout(30_000),
  });
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  console.log(await response.json());
} finally {
  await dispatcher.close();
}

Undici’s ProxyAgent supports HTTPS proxy URIs and a preformatted proxy-authorization token. See the official ProxyAgent documentation.

Go with net/http

package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"net/url"
	"os"
	"time"
)

func main() {
	proxyURL := &url.URL{
		Scheme: "https",
		Host:   "proxy.packetstream.io:31111",
		User:   url.UserPassword(os.Getenv("PACKETSTREAM_USER"), os.Getenv("PACKETSTREAM_AUTH_KEY")),
	}

	transport := http.DefaultTransport.(*http.Transport).Clone()
	transport.Proxy = http.ProxyURL(proxyURL)
	client := &http.Client{Transport: transport, Timeout: 30 * time.Second}

	response, err := client.Get("https://ipinfo.io")
	if err != nil {
		log.Fatal(err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(body))
}

Go determines proxy behavior from the URL scheme and passes URL user information as proxy authorization. See the official net/http Transport documentation.

Playwright

import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: {
    server: "https://proxy.packetstream.io:31111",
    username: process.env.PACKETSTREAM_USER,
    password: process.env.PACKETSTREAM_AUTH_KEY,
  },
});

try {
  const page = await browser.newPage();
  await page.goto("https://ipinfo.io/json", {
    waitUntil: "domcontentloaded",
    timeout: 30_000,
  });
  console.log(JSON.parse(await page.locator("body").innerText()));
} finally {
  await browser.close();
}

Browsers reuse connections. A new page or navigation does not guarantee a new proxy connection or exit. See the full PacketStream Playwright guide for targeting, sticky sessions, and browser-specific recovery.

Apply targeting or a sticky session

Every example can change the password value without changing the endpoint:

PACKETSTREAM_AUTH_KEY + "_country-US"
PACKETSTREAM_AUTH_KEY + "_session-workflow42"
PACKETSTREAM_AUTH_KEY + "_country-US_session-workflow42"

Keep the composition in application configuration so the final password is not written to logs.

Runnable examples

The PacketStream examples repository has a tested, runnable project for each language above and for Python with HTTPX, Rust, PHP, Ruby, Java, C#, Puppeteer, Selenium, Scrapy, and Crawlee. Every example reads the same environment variables, supports country targeting and sticky sessions, and runs natively or in Docker.

To measure success rate and latency over many requests, use ProxySampler. See Measure success rate and latency.

Java’s built-in HttpClient, Scrapy’s default downloader, and Crawlee’s HTTP client cannot use the HTTPS proxy, and Ruby’s Net::HTTP does not verify its certificate, so their examples use the HTTP endpoint on port 31112. Requests to HTTPS sites stay encrypted inside the tunnel, but the proxy credentials reach the gateway unencrypted. Each example’s README explains the limit. To keep the credentials encrypted with Scrapy, use the loopback TLS bridge in the Scrapy integration.

Questions? We’re here to help. Talk with our support team about your integration.
Contact support