Skip to main content

requests Session for ProxyHat residential proxies — sticky sessions, rotation, geo-targeting, socks5.

Project description

requests-proxyhat

Route Python requests through ProxyHat residential proxies — a drop-in Session that pins one residential IP for the whole session by default, plus rotation, geo-targeting and socks5.

CI Compatible with requests latest PyPI License: MIT

Why

Scraping or calling APIs from a datacenter IP gets you rate-limited, CAPTCHA-walled and blocked. requests already speaks proxies through its proxies={"http": ..., "https": ...} dict — this package fills that dict with ProxyHat's residential IPs (50M+ across 148+ countries) and wires it into a Session subclass, so session.get(url) just works through a residential IP. No fork, no boilerplate.

Install

pip install requests-proxyhat

Quick start

from requests_proxyhat import ProxyHatSession

# An API key auto-selects an active residential sub-user:
with ProxyHatSession(country="us") as session:   # sticky US IP for the whole session
    print(session.get("https://api.ipify.org").text)
    print(session.get("https://api.ipify.org").text)  # same IP — cookies stay coherent

Get an API key at proxyhat.com.

Just want the proxies dict for plain requests or your own Session?

import requests
from requests_proxyhat import proxyhat_proxies

proxies = proxyhat_proxies(country="de")   # {"http": "http://…@gate.proxyhat.com:8080", "https": …}
requests.get("https://api.ipify.org", proxies=proxies)

Credentials

Pass them explicitly or via environment variables — options win over env:

Option Env var Notes
api_key PROXYHAT_API_KEY Auto-selects an active sub-user with remaining traffic
sub_user PROXYHAT_SUBUSER Pick a specific sub-user by uuid or name (with an API key)
username PROXYHAT_USERNAME Explicit gateway proxy_username (skips the API)
password PROXYHAT_PASSWORD Explicit gateway proxy_password

Targeting

ProxyHatSession(
    protocol="http",   # or "socks5"
    country="us",      # ISO code or "any" (default)
    region="california",
    city="new_york",
    filter="high",     # AI IP-quality tier
    sticky="30m",      # session lifetime (default); sticky=False rotates every request
)

Sticky session vs rotation

A Session usually means "keep talking to this site as one visitor" — logging in, paging, keeping cookies. If the exit IP changed mid-session the site would see a user teleporting between cities and block it. So ProxyHatSession is sticky by default: one residential IP is pinned for the session (sticky="30m", set on session.proxies), keeping cookies and fingerprint coherent.

Want a fresh IP on every request instead (e.g. many independent one-shot fetches)? Turn stickiness off:

with ProxyHatSession(country="us", sticky=False) as session:   # rotating residential IP per request
    for url in urls:
        session.get(url)   # each request exits from a new IP

Set a custom lifetime with sticky="2h".

The standalone proxyhat_proxies(...) dict is stateless, so it rotates by default (sticky=None); pass sticky="30m" to pin one IP in that dict too.

How it works

ProxyHatSession resolves your gateway credentials (via the official proxyhat SDK — an API key auto-picks an active sub-user, or pass username/password), then builds a proxy URL where the username carries ProxyHat's targeting grammar (<user>-country-us-sid-<id>-ttl-30m) and points at the gateway (http://gate.proxyhat.com:8080, or socks5://…:1080). Sticky mode sets that URL on session.proxies once, so every request reuses one pinned residential IP. Rotating mode overrides Session.request() to mint a fresh gateway session per call — so each request exits from a new IP, and requests' connection pool can't pin you to one, since the proxy URL itself changes.

License

MIT © ProxyHat

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requests_proxyhat-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requests_proxyhat-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file requests_proxyhat-0.1.0.tar.gz.

File metadata

  • Download URL: requests_proxyhat-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for requests_proxyhat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5717daa3ec45b7e2432fa8226675a1c5bd36c7bda738d829884dc27aeb0302af
MD5 387178806b25ff3bb05ad9358d9e5229
BLAKE2b-256 92f6fa269ddf258412b9b04fa8370963b4ed64391631cdcdf089728fcf54229d

See more details on using hashes here.

Provenance

The following attestation bundles were made for requests_proxyhat-0.1.0.tar.gz:

Publisher: ci.yml on ProxyHatCom/requests-proxyhat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file requests_proxyhat-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for requests_proxyhat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 954e5baa4e88ae79b0272a3a4a9009b32fb6576eff6ab8f1b48fd6d0400eabdf
MD5 31ffc46fd27cb66492e0a8c7a7a834c1
BLAKE2b-256 56ac07c09d16a9ca45d51f7b67bccdd6a4449a46c11c4fcf9c278611191f141f

See more details on using hashes here.

Provenance

The following attestation bundles were made for requests_proxyhat-0.1.0-py3-none-any.whl:

Publisher: ci.yml on ProxyHatCom/requests-proxyhat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page