Python SDK

The official ProxyHat Python SDK provides a convenient, Pythonic interface for the ProxyHat API.

View on GitHub

Requirements

Installation

Not on PyPI yet. The SDK is distributed from its GitHub repository. Install it straight from Git:
pip install "git+https://github.com/ProxyHatCom/python-sdk"

Quick Start

from proxyhat import ProxyHat

client = ProxyHat(api_key="YOUR_API_KEY")

# Get account info
user = client.auth.user()
print(f"Email: {user.email}")
# Balance lives under the `traffic` object on GET /v1/auth/user
print(f"Total balance: {user.traffic.total_bytes} bytes")
print(f"Regular balance: {user.traffic.regular_bytes} bytes")

# List sub-users
sub_users = client.sub_users.list()
for su in sub_users:
    print(f"{su.username} — {su.used_traffic} bytes used")

Sub-User Management

Create a Sub-User

sub_user = client.sub_users.create(
    username="user1",
    password="securePass123",
    traffic_limit=1000000000  # 1 GB
)
print(f"Created: {sub_user.username}")

Update a Sub-User

client.sub_users.update(
    sub_user_id=sub_user.id,
    traffic_limit=2000000000  # 2 GB
)

Delete a Sub-User

client.sub_users.delete(sub_user_id=sub_user.id)

Locations

# List available countries
countries = client.locations.countries()
for country in countries:
    print(f"{country.name}: {country.proxy_count} proxies")

# List cities in a country
cities = client.locations.cities(country_code="US")
for city in cities:
    print(f"{city.name}, {city.region}")

Proxy Presets

# Create a preset
preset = client.proxy_presets.create(
    name="US Residential",
    country_code="US",
    connection_type="residential"
)

# List presets
presets = client.proxy_presets.list()
for p in presets:
    print(f"{p.name}: {p.country_code}")

Analytics

# Get traffic usage chart
chart = client.analytics.traffic_chart(period="7d")
for point in chart:
    print(f"{point.date}: {point.bytes_used} bytes")

Error Handling

from proxyhat.exceptions import ProxyHatError, AuthenticationError, RateLimitError

try:
    user = client.auth.user()
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except ProxyHatError as e:
    print(f"API error: {e.message}")

Resources