Python SDK

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

View on GitHub

Requirements

Installation

pip install proxyhat

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}")
print(f"Traffic balance: {user.traffic_balance} bytes")

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

Sub-User Management

Create a Sub-User

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

Update a Sub-User

client.sub_users.update(
    sub_user_id=sub_user.id,
    traffic_limit=2147483648  # 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