proxyhat 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- proxyhat-0.2.0/.github/workflows/ci.yml +56 -0
- proxyhat-0.2.0/.gitignore +29 -0
- proxyhat-0.2.0/.python-version +1 -0
- proxyhat-0.2.0/CHANGELOG.md +27 -0
- proxyhat-0.2.0/LICENSE +21 -0
- proxyhat-0.2.0/PKG-INFO +195 -0
- proxyhat-0.2.0/README.md +164 -0
- proxyhat-0.2.0/pyproject.toml +54 -0
- proxyhat-0.2.0/src/proxyhat/__init__.py +39 -0
- proxyhat-0.2.0/src/proxyhat/_base_client.py +104 -0
- proxyhat-0.2.0/src/proxyhat/async_client.py +124 -0
- proxyhat-0.2.0/src/proxyhat/client.py +129 -0
- proxyhat-0.2.0/src/proxyhat/connection.py +90 -0
- proxyhat-0.2.0/src/proxyhat/errors.py +72 -0
- proxyhat-0.2.0/src/proxyhat/py.typed +0 -0
- proxyhat-0.2.0/src/proxyhat/resources/__init__.py +0 -0
- proxyhat-0.2.0/src/proxyhat/resources/analytics.py +140 -0
- proxyhat-0.2.0/src/proxyhat/resources/auth.py +155 -0
- proxyhat-0.2.0/src/proxyhat/resources/coupons.py +99 -0
- proxyhat-0.2.0/src/proxyhat/resources/email.py +57 -0
- proxyhat-0.2.0/src/proxyhat/resources/locations.py +227 -0
- proxyhat-0.2.0/src/proxyhat/resources/payments.py +107 -0
- proxyhat-0.2.0/src/proxyhat/resources/plans.py +83 -0
- proxyhat-0.2.0/src/proxyhat/resources/profile.py +75 -0
- proxyhat-0.2.0/src/proxyhat/resources/proxy_descriptors.py +64 -0
- proxyhat-0.2.0/src/proxyhat/resources/proxy_presets.py +71 -0
- proxyhat-0.2.0/src/proxyhat/resources/sub_user_groups.py +77 -0
- proxyhat-0.2.0/src/proxyhat/resources/sub_users.py +171 -0
- proxyhat-0.2.0/src/proxyhat/resources/two_factor.py +107 -0
- proxyhat-0.2.0/src/proxyhat/types/__init__.py +49 -0
- proxyhat-0.2.0/src/proxyhat/types/analytics.py +52 -0
- proxyhat-0.2.0/src/proxyhat/types/auth.py +106 -0
- proxyhat-0.2.0/src/proxyhat/types/coupons.py +39 -0
- proxyhat-0.2.0/src/proxyhat/types/email.py +13 -0
- proxyhat-0.2.0/src/proxyhat/types/locations.py +101 -0
- proxyhat-0.2.0/src/proxyhat/types/payments.py +101 -0
- proxyhat-0.2.0/src/proxyhat/types/plans.py +59 -0
- proxyhat-0.2.0/src/proxyhat/types/profile.py +30 -0
- proxyhat-0.2.0/src/proxyhat/types/proxy_descriptor.py +33 -0
- proxyhat-0.2.0/src/proxyhat/types/proxy_presets.py +21 -0
- proxyhat-0.2.0/src/proxyhat/types/sub_user.py +69 -0
- proxyhat-0.2.0/src/proxyhat/types/sub_user_groups.py +25 -0
- proxyhat-0.2.0/src/proxyhat/types/two_factor.py +37 -0
- proxyhat-0.2.0/tests/__init__.py +0 -0
- proxyhat-0.2.0/tests/conftest.py +24 -0
- proxyhat-0.2.0/tests/test_analytics.py +70 -0
- proxyhat-0.2.0/tests/test_auth.py +120 -0
- proxyhat-0.2.0/tests/test_client.py +55 -0
- proxyhat-0.2.0/tests/test_connection.py +100 -0
- proxyhat-0.2.0/tests/test_errors.py +97 -0
- proxyhat-0.2.0/tests/test_locations.py +99 -0
- proxyhat-0.2.0/tests/test_sub_users.py +124 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
lint:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- name: Install dependencies
|
|
19
|
+
run: pip install ruff
|
|
20
|
+
- name: Lint
|
|
21
|
+
run: ruff check src/ tests/
|
|
22
|
+
- name: Format check
|
|
23
|
+
run: ruff format --check src/ tests/
|
|
24
|
+
|
|
25
|
+
test:
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
strategy:
|
|
28
|
+
matrix:
|
|
29
|
+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@v4
|
|
32
|
+
- uses: actions/setup-python@v5
|
|
33
|
+
with:
|
|
34
|
+
python-version: ${{ matrix.python-version }}
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: pip install -e ".[dev]"
|
|
37
|
+
- name: Run tests
|
|
38
|
+
run: pytest -v
|
|
39
|
+
|
|
40
|
+
publish:
|
|
41
|
+
needs: [lint, test]
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
44
|
+
permissions:
|
|
45
|
+
id-token: write
|
|
46
|
+
steps:
|
|
47
|
+
- uses: actions/checkout@v4
|
|
48
|
+
- uses: actions/setup-python@v5
|
|
49
|
+
with:
|
|
50
|
+
python-version: "3.12"
|
|
51
|
+
- name: Install build tools
|
|
52
|
+
run: pip install build
|
|
53
|
+
- name: Build package
|
|
54
|
+
run: python -m build
|
|
55
|
+
- name: Publish to PyPI
|
|
56
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*$py.class
|
|
4
|
+
*.so
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
*.egg-info/
|
|
8
|
+
*.egg
|
|
9
|
+
.eggs/
|
|
10
|
+
*.whl
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
env/
|
|
14
|
+
.env
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.ruff_cache/
|
|
17
|
+
.mypy_cache/
|
|
18
|
+
htmlcov/
|
|
19
|
+
.coverage
|
|
20
|
+
coverage.xml
|
|
21
|
+
*.log
|
|
22
|
+
.idea/
|
|
23
|
+
.vscode/
|
|
24
|
+
*.swp
|
|
25
|
+
*.swo
|
|
26
|
+
*~
|
|
27
|
+
.DS_Store
|
|
28
|
+
Thumbs.db
|
|
29
|
+
SDK_PROMPT.md
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2026-07-13
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Proxy connection helpers** — turn an API key or sub-user credentials into a ready proxy URL:
|
|
13
|
+
- `client.connection_url(...)` (sync + async) — picks an active sub-user and builds the gateway URL
|
|
14
|
+
- `build_connection_url()` / `build_proxy_username()` — offline gateway URL/username builder
|
|
15
|
+
- `client.proxy_descriptors.create()` — server-built connection descriptor (`POST /v1/proxy-descriptors`)
|
|
16
|
+
- `SubUser.proxy_password` and `SubUser.suspended_at` fields
|
|
17
|
+
|
|
18
|
+
## [0.1.0] - 2026-02-13
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- Initial release of the ProxyHat Python SDK
|
|
23
|
+
- Sync (`ProxyHat`) and async (`AsyncProxyHat`) clients
|
|
24
|
+
- Full coverage of ProxyHat API v1 endpoints
|
|
25
|
+
- Typed responses using dataclasses
|
|
26
|
+
- Comprehensive error handling with typed exceptions
|
|
27
|
+
- Pagination support for location endpoints
|
proxyhat-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ProxyHat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
proxyhat-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: proxyhat
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: The official Python SDK for the ProxyHat residential proxy API
|
|
5
|
+
Project-URL: Homepage, https://proxyhat.com
|
|
6
|
+
Project-URL: Documentation, https://docs.proxyhat.com
|
|
7
|
+
Project-URL: Repository, https://github.com/ProxyHatCom/python-sdk
|
|
8
|
+
Project-URL: Changelog, https://github.com/ProxyHatCom/python-sdk/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: ProxyHat <support@proxyhat.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,proxy,proxyhat,residential-proxy,sdk
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Requires-Dist: httpx>=0.24.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: respx>=0.20; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# ProxyHat Python SDK
|
|
33
|
+
|
|
34
|
+
The official Python SDK for the [ProxyHat](https://proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=hero) residential proxy API.
|
|
35
|
+
|
|
36
|
+
[](https://github.com/ProxyHatCom/python-sdk/actions/workflows/ci.yml)
|
|
37
|
+
[](https://pypi.org/project/proxyhat/)
|
|
38
|
+
[](https://pypi.org/project/proxyhat/)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **One-call proxy connection** — `client.connection_url()` turns your API key into a ready-to-use residential proxy URL
|
|
44
|
+
- Full coverage of the ProxyHat API
|
|
45
|
+
- Local gateway URL builder (`build_connection_url`) — no network needed
|
|
46
|
+
- Sync (`ProxyHat`) and async (`AsyncProxyHat`) clients
|
|
47
|
+
- Typed responses using dataclasses
|
|
48
|
+
- Comprehensive error handling with typed exceptions
|
|
49
|
+
- Pagination support for location endpoints
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install proxyhat
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from proxyhat import ProxyHat
|
|
61
|
+
|
|
62
|
+
client = ProxyHat(api_key="ph_your_api_key")
|
|
63
|
+
|
|
64
|
+
# List sub-users
|
|
65
|
+
users = client.sub_users.list()
|
|
66
|
+
for user in users:
|
|
67
|
+
print(user.proxy_username, user.lifecycle_status)
|
|
68
|
+
|
|
69
|
+
# Create a sub-user
|
|
70
|
+
new_user = client.sub_users.create(
|
|
71
|
+
proxy_password="secure_pass",
|
|
72
|
+
is_traffic_limited=True,
|
|
73
|
+
traffic_limit="5GB",
|
|
74
|
+
name="Scraper",
|
|
75
|
+
)
|
|
76
|
+
print(new_user.uuid)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Async Usage
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import asyncio
|
|
83
|
+
from proxyhat import AsyncProxyHat
|
|
84
|
+
|
|
85
|
+
async def main():
|
|
86
|
+
async with AsyncProxyHat(api_key="ph_your_api_key") as client:
|
|
87
|
+
users = await client.sub_users.list()
|
|
88
|
+
for user in users:
|
|
89
|
+
print(user.proxy_username)
|
|
90
|
+
|
|
91
|
+
asyncio.run(main())
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Connecting to a proxy
|
|
95
|
+
|
|
96
|
+
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:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from proxyhat import ProxyHat
|
|
100
|
+
|
|
101
|
+
proxy = ProxyHat(api_key="ph_your_api_key")
|
|
102
|
+
|
|
103
|
+
# Rotating residential IP, US exit:
|
|
104
|
+
url = proxy.connection_url(country="us")
|
|
105
|
+
# → http://<user>-country-us:<pass>@gate.proxyhat.com:8080
|
|
106
|
+
|
|
107
|
+
# Sticky session (same IP for 30m), city-targeted, SOCKS5:
|
|
108
|
+
sticky = proxy.connection_url(country="de", city="berlin", sticky="30m", protocol="socks5")
|
|
109
|
+
|
|
110
|
+
# Use it with any HTTP client:
|
|
111
|
+
import httpx
|
|
112
|
+
resp = httpx.get("https://api.ipify.org", proxy=url)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Offline builder** — if you already have a sub-user's credentials, build the URL with no network call:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from proxyhat import build_connection_url
|
|
119
|
+
|
|
120
|
+
url = build_connection_url(username="ph-8f2a1c", password="PxSecret123", country="gb", filter="high")
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Server-built descriptor** — let the API assemble it (validates the sub-user is active):
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
d = proxy.proxy_descriptors.create(
|
|
127
|
+
sub_user_uuid=user.uuid,
|
|
128
|
+
protocol="http",
|
|
129
|
+
location={"country": "us", "city": "new_york"},
|
|
130
|
+
session={"mode": "sticky", "ttl": "30m"},
|
|
131
|
+
)
|
|
132
|
+
print(d.url)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Authentication
|
|
136
|
+
|
|
137
|
+
Get your API key from the [ProxyHat Dashboard](https://dashboard.proxyhat.com/register?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=signup).
|
|
138
|
+
|
|
139
|
+
See the [Authentication Guide](https://docs.proxyhat.com/authentication?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=auth-guide) for details.
|
|
140
|
+
|
|
141
|
+
## API Reference
|
|
142
|
+
|
|
143
|
+
| Resource | Methods |
|
|
144
|
+
|----------|---------|
|
|
145
|
+
| `client.auth` | `register`, `login`, `user`, `logout`, `supported_providers`, `social_accounts`, `disconnect_social`, `oauth_redirect` |
|
|
146
|
+
| `client.sub_users` | `list`, `create`, `get`, `update`, `delete`, `reset_usage`, `bulk_delete`, `bulk_move_to_group` |
|
|
147
|
+
| `client.sub_user_groups` | `list`, `create`, `get`, `update`, `delete` |
|
|
148
|
+
| `client.locations` | `countries`, `regions`, `cities`, `isps`, `zipcodes` |
|
|
149
|
+
| `client.analytics` | `traffic`, `traffic_total`, `requests`, `requests_total`, `domain_breakdown` |
|
|
150
|
+
| `client.proxy_presets` | `list`, `create`, `get`, `update`, `delete` |
|
|
151
|
+
| `client.proxy_descriptors` | `create` |
|
|
152
|
+
| `client.connection_url(...)` | build a ready proxy URL from an active sub-user |
|
|
153
|
+
| `client.profile` | `get_preferences`, `update_preferences`, `list_api_keys`, `create_api_key`, `delete_api_key`, `regenerate_api_key` |
|
|
154
|
+
| `client.two_factor` | `status`, `enable`, `confirm`, `disable`, `qr_code`, `recovery_codes`, `disable_by_recovery`, `change_password` |
|
|
155
|
+
| `client.email` | `request_change`, `confirm_change`, `cancel_change`, `resend_verification` |
|
|
156
|
+
| `client.coupons` | `validate`, `apply`, `redeem` |
|
|
157
|
+
| `client.plans` | `list_regular`, `list_subscriptions`, `get_regular`, `get_subscription`, `pricing_regular`, `pricing_subscriptions` |
|
|
158
|
+
| `client.payments` | `list`, `create`, `get`, `check`, `invoice`, `cryptocurrencies` |
|
|
159
|
+
|
|
160
|
+
## Error Handling
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from proxyhat import ProxyHat, ProxyHatError, NotFoundError, RateLimitError, ValidationError
|
|
164
|
+
|
|
165
|
+
client = ProxyHat(api_key="ph_your_api_key")
|
|
166
|
+
|
|
167
|
+
try:
|
|
168
|
+
user = client.sub_users.get("nonexistent-id")
|
|
169
|
+
except NotFoundError as e:
|
|
170
|
+
print(f"Not found: {e.message}")
|
|
171
|
+
except RateLimitError as e:
|
|
172
|
+
print(f"Rate limited. Retry after {e.retry_after}s")
|
|
173
|
+
except ValidationError as e:
|
|
174
|
+
print(f"Validation failed: {e.errors}")
|
|
175
|
+
except ProxyHatError as e:
|
|
176
|
+
print(f"API error {e.status_code}: {e.message}")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
See the [Error Handling Guide](https://docs.proxyhat.com/errors?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=error-handling) for the full list of error codes.
|
|
180
|
+
|
|
181
|
+
## Documentation
|
|
182
|
+
|
|
183
|
+
- [Getting Started](https://docs.proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=getting-started)
|
|
184
|
+
- [API Reference](https://docs.proxyhat.com/api/auth?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=api-reference)
|
|
185
|
+
- [Full Documentation](https://docs.proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=docs-home)
|
|
186
|
+
|
|
187
|
+
## Links
|
|
188
|
+
|
|
189
|
+
- [ProxyHat](https://proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=links) — Residential & mobile proxy network
|
|
190
|
+
- [Dashboard](https://dashboard.proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=links) — Manage proxies, sub-users, and API keys
|
|
191
|
+
- [GitHub](https://github.com/ProxyHatCom/python-sdk) — Source code & issue tracker
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT — see [LICENSE](LICENSE) for details.
|
proxyhat-0.2.0/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# ProxyHat Python SDK
|
|
2
|
+
|
|
3
|
+
The official Python SDK for the [ProxyHat](https://proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=hero) residential proxy API.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/ProxyHatCom/python-sdk/actions/workflows/ci.yml)
|
|
6
|
+
[](https://pypi.org/project/proxyhat/)
|
|
7
|
+
[](https://pypi.org/project/proxyhat/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **One-call proxy connection** — `client.connection_url()` turns your API key into a ready-to-use residential proxy URL
|
|
13
|
+
- Full coverage of the ProxyHat API
|
|
14
|
+
- Local gateway URL builder (`build_connection_url`) — no network needed
|
|
15
|
+
- Sync (`ProxyHat`) and async (`AsyncProxyHat`) clients
|
|
16
|
+
- Typed responses using dataclasses
|
|
17
|
+
- Comprehensive error handling with typed exceptions
|
|
18
|
+
- Pagination support for location endpoints
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install proxyhat
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from proxyhat import ProxyHat
|
|
30
|
+
|
|
31
|
+
client = ProxyHat(api_key="ph_your_api_key")
|
|
32
|
+
|
|
33
|
+
# List sub-users
|
|
34
|
+
users = client.sub_users.list()
|
|
35
|
+
for user in users:
|
|
36
|
+
print(user.proxy_username, user.lifecycle_status)
|
|
37
|
+
|
|
38
|
+
# Create a sub-user
|
|
39
|
+
new_user = client.sub_users.create(
|
|
40
|
+
proxy_password="secure_pass",
|
|
41
|
+
is_traffic_limited=True,
|
|
42
|
+
traffic_limit="5GB",
|
|
43
|
+
name="Scraper",
|
|
44
|
+
)
|
|
45
|
+
print(new_user.uuid)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Async Usage
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import asyncio
|
|
52
|
+
from proxyhat import AsyncProxyHat
|
|
53
|
+
|
|
54
|
+
async def main():
|
|
55
|
+
async with AsyncProxyHat(api_key="ph_your_api_key") as client:
|
|
56
|
+
users = await client.sub_users.list()
|
|
57
|
+
for user in users:
|
|
58
|
+
print(user.proxy_username)
|
|
59
|
+
|
|
60
|
+
asyncio.run(main())
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Connecting to a proxy
|
|
64
|
+
|
|
65
|
+
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:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from proxyhat import ProxyHat
|
|
69
|
+
|
|
70
|
+
proxy = ProxyHat(api_key="ph_your_api_key")
|
|
71
|
+
|
|
72
|
+
# Rotating residential IP, US exit:
|
|
73
|
+
url = proxy.connection_url(country="us")
|
|
74
|
+
# → http://<user>-country-us:<pass>@gate.proxyhat.com:8080
|
|
75
|
+
|
|
76
|
+
# Sticky session (same IP for 30m), city-targeted, SOCKS5:
|
|
77
|
+
sticky = proxy.connection_url(country="de", city="berlin", sticky="30m", protocol="socks5")
|
|
78
|
+
|
|
79
|
+
# Use it with any HTTP client:
|
|
80
|
+
import httpx
|
|
81
|
+
resp = httpx.get("https://api.ipify.org", proxy=url)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Offline builder** — if you already have a sub-user's credentials, build the URL with no network call:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from proxyhat import build_connection_url
|
|
88
|
+
|
|
89
|
+
url = build_connection_url(username="ph-8f2a1c", password="PxSecret123", country="gb", filter="high")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Server-built descriptor** — let the API assemble it (validates the sub-user is active):
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
d = proxy.proxy_descriptors.create(
|
|
96
|
+
sub_user_uuid=user.uuid,
|
|
97
|
+
protocol="http",
|
|
98
|
+
location={"country": "us", "city": "new_york"},
|
|
99
|
+
session={"mode": "sticky", "ttl": "30m"},
|
|
100
|
+
)
|
|
101
|
+
print(d.url)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Authentication
|
|
105
|
+
|
|
106
|
+
Get your API key from the [ProxyHat Dashboard](https://dashboard.proxyhat.com/register?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=signup).
|
|
107
|
+
|
|
108
|
+
See the [Authentication Guide](https://docs.proxyhat.com/authentication?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=auth-guide) for details.
|
|
109
|
+
|
|
110
|
+
## API Reference
|
|
111
|
+
|
|
112
|
+
| Resource | Methods |
|
|
113
|
+
|----------|---------|
|
|
114
|
+
| `client.auth` | `register`, `login`, `user`, `logout`, `supported_providers`, `social_accounts`, `disconnect_social`, `oauth_redirect` |
|
|
115
|
+
| `client.sub_users` | `list`, `create`, `get`, `update`, `delete`, `reset_usage`, `bulk_delete`, `bulk_move_to_group` |
|
|
116
|
+
| `client.sub_user_groups` | `list`, `create`, `get`, `update`, `delete` |
|
|
117
|
+
| `client.locations` | `countries`, `regions`, `cities`, `isps`, `zipcodes` |
|
|
118
|
+
| `client.analytics` | `traffic`, `traffic_total`, `requests`, `requests_total`, `domain_breakdown` |
|
|
119
|
+
| `client.proxy_presets` | `list`, `create`, `get`, `update`, `delete` |
|
|
120
|
+
| `client.proxy_descriptors` | `create` |
|
|
121
|
+
| `client.connection_url(...)` | build a ready proxy URL from an active sub-user |
|
|
122
|
+
| `client.profile` | `get_preferences`, `update_preferences`, `list_api_keys`, `create_api_key`, `delete_api_key`, `regenerate_api_key` |
|
|
123
|
+
| `client.two_factor` | `status`, `enable`, `confirm`, `disable`, `qr_code`, `recovery_codes`, `disable_by_recovery`, `change_password` |
|
|
124
|
+
| `client.email` | `request_change`, `confirm_change`, `cancel_change`, `resend_verification` |
|
|
125
|
+
| `client.coupons` | `validate`, `apply`, `redeem` |
|
|
126
|
+
| `client.plans` | `list_regular`, `list_subscriptions`, `get_regular`, `get_subscription`, `pricing_regular`, `pricing_subscriptions` |
|
|
127
|
+
| `client.payments` | `list`, `create`, `get`, `check`, `invoice`, `cryptocurrencies` |
|
|
128
|
+
|
|
129
|
+
## Error Handling
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from proxyhat import ProxyHat, ProxyHatError, NotFoundError, RateLimitError, ValidationError
|
|
133
|
+
|
|
134
|
+
client = ProxyHat(api_key="ph_your_api_key")
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
user = client.sub_users.get("nonexistent-id")
|
|
138
|
+
except NotFoundError as e:
|
|
139
|
+
print(f"Not found: {e.message}")
|
|
140
|
+
except RateLimitError as e:
|
|
141
|
+
print(f"Rate limited. Retry after {e.retry_after}s")
|
|
142
|
+
except ValidationError as e:
|
|
143
|
+
print(f"Validation failed: {e.errors}")
|
|
144
|
+
except ProxyHatError as e:
|
|
145
|
+
print(f"API error {e.status_code}: {e.message}")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
See the [Error Handling Guide](https://docs.proxyhat.com/errors?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=error-handling) for the full list of error codes.
|
|
149
|
+
|
|
150
|
+
## Documentation
|
|
151
|
+
|
|
152
|
+
- [Getting Started](https://docs.proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=getting-started)
|
|
153
|
+
- [API Reference](https://docs.proxyhat.com/api/auth?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=api-reference)
|
|
154
|
+
- [Full Documentation](https://docs.proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=docs-home)
|
|
155
|
+
|
|
156
|
+
## Links
|
|
157
|
+
|
|
158
|
+
- [ProxyHat](https://proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=links) — Residential & mobile proxy network
|
|
159
|
+
- [Dashboard](https://dashboard.proxyhat.com?utm_source=github&utm_medium=readme&utm_campaign=sdk-python&utm_content=links) — Manage proxies, sub-users, and API keys
|
|
160
|
+
- [GitHub](https://github.com/ProxyHatCom/python-sdk) — Source code & issue tracker
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "proxyhat"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "The official Python SDK for the ProxyHat residential proxy API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "ProxyHat", email = "support@proxyhat.com" }]
|
|
13
|
+
keywords = ["proxy", "residential-proxy", "proxyhat", "sdk", "api"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
dependencies = ["httpx>=0.24.0"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://proxyhat.com"
|
|
30
|
+
Documentation = "https://docs.proxyhat.com"
|
|
31
|
+
Repository = "https://github.com/ProxyHatCom/python-sdk"
|
|
32
|
+
Changelog = "https://github.com/ProxyHatCom/python-sdk/blob/main/CHANGELOG.md"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=7.0",
|
|
37
|
+
"pytest-asyncio>=0.21",
|
|
38
|
+
"respx>=0.20",
|
|
39
|
+
"ruff>=0.4",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/proxyhat"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff]
|
|
46
|
+
target-version = "py39"
|
|
47
|
+
line-length = 120
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint]
|
|
50
|
+
select = ["E", "F", "I", "N", "W", "UP"]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
asyncio_mode = "auto"
|
|
54
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""ProxyHat Python SDK — official client for the ProxyHat residential proxy API."""
|
|
2
|
+
|
|
3
|
+
from proxyhat.async_client import AsyncProxyHat
|
|
4
|
+
from proxyhat.client import ProxyHat
|
|
5
|
+
from proxyhat.connection import (
|
|
6
|
+
PROXYHAT_GATEWAY,
|
|
7
|
+
PROXYHAT_PORT_HTTP,
|
|
8
|
+
PROXYHAT_PORT_SOCKS5,
|
|
9
|
+
build_connection_url,
|
|
10
|
+
build_proxy_username,
|
|
11
|
+
)
|
|
12
|
+
from proxyhat.errors import (
|
|
13
|
+
APIError,
|
|
14
|
+
AuthenticationError,
|
|
15
|
+
NotFoundError,
|
|
16
|
+
PermissionError,
|
|
17
|
+
ProxyHatError,
|
|
18
|
+
RateLimitError,
|
|
19
|
+
ValidationError,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"PROXYHAT_GATEWAY",
|
|
24
|
+
"PROXYHAT_PORT_HTTP",
|
|
25
|
+
"PROXYHAT_PORT_SOCKS5",
|
|
26
|
+
"APIError",
|
|
27
|
+
"AsyncProxyHat",
|
|
28
|
+
"AuthenticationError",
|
|
29
|
+
"NotFoundError",
|
|
30
|
+
"PermissionError",
|
|
31
|
+
"ProxyHat",
|
|
32
|
+
"ProxyHatError",
|
|
33
|
+
"RateLimitError",
|
|
34
|
+
"ValidationError",
|
|
35
|
+
"build_connection_url",
|
|
36
|
+
"build_proxy_username",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
__version__ = "0.2.0"
|