Skip to main content

The official Python SDK for the ProxyHat residential proxy API

Project description

ProxyHat Python SDK

The official Python SDK for the ProxyHat residential proxy API.

CI PyPI Python License: MIT

Features

  • One-call proxy connectionclient.connection_url() turns your API key into a ready-to-use residential proxy URL
  • Full coverage of the ProxyHat API
  • Local gateway URL builder (build_connection_url) — no network needed
  • Sync (ProxyHat) and async (AsyncProxyHat) clients
  • Typed responses using dataclasses
  • Comprehensive error handling with typed exceptions
  • Pagination support for location endpoints

Installation

pip install proxyhat

Quick Start

from proxyhat import ProxyHat

client = ProxyHat(api_key="ph_your_api_key")

# List sub-users
users = client.sub_users.list()
for user in users:
    print(user.proxy_username, user.lifecycle_status)

# Create a sub-user
new_user = client.sub_users.create(
    proxy_password="secure_pass",
    is_traffic_limited=True,
    traffic_limit="5GB",
    name="Scraper",
)
print(new_user.uuid)

Async Usage

import asyncio
from proxyhat import AsyncProxyHat

async def main():
    async with AsyncProxyHat(api_key="ph_your_api_key") as client:
        users = await client.sub_users.list()
        for user in users:
            print(user.proxy_username)

asyncio.run(main())

Connecting to a proxy

From an API key to actually routing traffic in one call — the SDK looks up an active sub-user and builds the gateway URL for you:

from proxyhat import ProxyHat

proxy = ProxyHat(api_key="ph_your_api_key")

# Rotating residential IP, US exit:
url = proxy.connection_url(country="us")
# → http://<user>-country-us:<pass>@gate.proxyhat.com:8080

# Sticky session (same IP for 30m), city-targeted, SOCKS5:
sticky = proxy.connection_url(country="de", city="berlin", sticky="30m", protocol="socks5")

# Use it with any HTTP client:
import httpx
resp = httpx.get("https://api.ipify.org", proxy=url)

Offline builder — if you already have a sub-user's credentials, build the URL with no network call:

from proxyhat import build_connection_url

url = build_connection_url(username="ph-8f2a1c", password="PxSecret123", country="gb", filter="high")

Server-built descriptor — let the API assemble it (validates the sub-user is active):

d = proxy.proxy_descriptors.create(
    sub_user_uuid=user.uuid,
    protocol="http",
    location={"country": "us", "city": "new_york"},
    session={"mode": "sticky", "ttl": "30m"},
)
print(d.url)

Authentication

Get your API key from the ProxyHat Dashboard.

See the Authentication Guide for details.

API Reference

Resource Methods
client.auth register, login, user, logout, supported_providers, social_accounts, disconnect_social, oauth_redirect
client.sub_users list, create, get, update, delete, reset_usage, bulk_delete, bulk_move_to_group
client.sub_user_groups list, create, get, update, delete
client.locations countries, regions, cities, isps, zipcodes
client.analytics traffic, traffic_total, requests, requests_total, domain_breakdown
client.proxy_presets list, create, get, update, delete
client.proxy_descriptors create
client.connection_url(...) build a ready proxy URL from an active sub-user
client.profile get_preferences, update_preferences, list_api_keys, create_api_key, delete_api_key, regenerate_api_key
client.two_factor status, enable, confirm, disable, qr_code, recovery_codes, disable_by_recovery, change_password
client.email request_change, confirm_change, cancel_change, resend_verification
client.coupons validate, apply, redeem
client.plans list_regular, list_subscriptions, get_regular, get_subscription, pricing_regular, pricing_subscriptions
client.payments list, create, get, check, invoice, cryptocurrencies

Error Handling

from proxyhat import ProxyHat, ProxyHatError, NotFoundError, RateLimitError, ValidationError

client = ProxyHat(api_key="ph_your_api_key")

try:
    user = client.sub_users.get("nonexistent-id")
except NotFoundError as e:
    print(f"Not found: {e.message}")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except ValidationError as e:
    print(f"Validation failed: {e.errors}")
except ProxyHatError as e:
    print(f"API error {e.status_code}: {e.message}")

See the Error Handling Guide for the full list of error codes.

Documentation

Links

  • ProxyHat — Residential & mobile proxy network
  • Dashboard — Manage proxies, sub-users, and API keys
  • GitHub — Source code & issue tracker

License

MIT — see LICENSE for details.

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

proxyhat-0.2.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

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

proxyhat-0.2.0-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file proxyhat-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for proxyhat-0.2.0.tar.gz
Algorithm Hash digest
SHA256 30862c559e6d01a53b6c1edab37d320c9e000cc1e47c74b87a289cdedac10f46
MD5 44973e30e294b74258c3649657db0f06
BLAKE2b-256 ce39f73a86d2a584578594c9377f509f03850bedc5cdeff9b785ad8cb1909a8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for proxyhat-0.2.0.tar.gz:

Publisher: ci.yml on ProxyHatCom/python-sdk

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

File details

Details for the file proxyhat-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: proxyhat-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for proxyhat-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b00e3d81d87feed92eb6bf5ecb5e5021212f96a51ae7d140e53b8952e99e667
MD5 596088ce8e8c74a878e94629a69debbf
BLAKE2b-256 58f6789e5b0bf7df30da5a46e8ef0cd477be517aee1bef8b700f2b37f1048e14

See more details on using hashes here.

Provenance

The following attestation bundles were made for proxyhat-0.2.0-py3-none-any.whl:

Publisher: ci.yml on ProxyHatCom/python-sdk

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