proxyhubb 0.1.0__py3-none-any.whl
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.
- proxyhubb/__init__.py +7 -0
- proxyhubb/client.py +106 -0
- proxyhubb/proxy.py +47 -0
- proxyhubb-0.1.0.dist-info/METADATA +54 -0
- proxyhubb-0.1.0.dist-info/RECORD +8 -0
- proxyhubb-0.1.0.dist-info/WHEEL +5 -0
- proxyhubb-0.1.0.dist-info/licenses/LICENSE +21 -0
- proxyhubb-0.1.0.dist-info/top_level.txt +1 -0
proxyhubb/__init__.py
ADDED
proxyhubb/client.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""ProxyHubb Python SDK — Bulk Proxy Pool Control API client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import requests
|
|
8
|
+
|
|
9
|
+
DEFAULT_BASE_URL = "https://api.proxyhubb.com"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ProxyHubClient:
|
|
13
|
+
"""Client for the ProxyHubb Bulk Proxy Pool API.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
api_key:
|
|
18
|
+
A ProxyHubb API key starting with ``phub_`` (or ``pk_``).
|
|
19
|
+
base_url:
|
|
20
|
+
Base URL of the Control API. Defaults to production.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
api_key: str,
|
|
26
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
27
|
+
) -> None:
|
|
28
|
+
if not api_key:
|
|
29
|
+
raise ValueError("api_key is required")
|
|
30
|
+
self._api_key = api_key
|
|
31
|
+
self._base_url = base_url.rstrip("/")
|
|
32
|
+
self._session = requests.Session()
|
|
33
|
+
self._session.headers.update({"X-API-Key": self._api_key})
|
|
34
|
+
|
|
35
|
+
def _url(self, path: str) -> str:
|
|
36
|
+
return f"{self._base_url}{path}"
|
|
37
|
+
|
|
38
|
+
def _get(self, path: str) -> dict[str, Any]:
|
|
39
|
+
resp = self._session.get(self._url(path))
|
|
40
|
+
resp.raise_for_status()
|
|
41
|
+
return resp.json()
|
|
42
|
+
|
|
43
|
+
def _post(self, path: str, payload: dict[str, Any]) -> dict[str, Any]:
|
|
44
|
+
resp = self._session.post(self._url(path), json=payload)
|
|
45
|
+
resp.raise_for_status()
|
|
46
|
+
return resp.json()
|
|
47
|
+
|
|
48
|
+
def _delete(self, path: str) -> None:
|
|
49
|
+
resp = self._session.delete(self._url(path))
|
|
50
|
+
resp.raise_for_status()
|
|
51
|
+
|
|
52
|
+
def create_pool(
|
|
53
|
+
self,
|
|
54
|
+
name: str,
|
|
55
|
+
size: int = 10,
|
|
56
|
+
session_type: str = "rotating",
|
|
57
|
+
description: str = "",
|
|
58
|
+
bytes_limit: int = 0,
|
|
59
|
+
) -> dict[str, Any]:
|
|
60
|
+
"""Create a new proxy pool."""
|
|
61
|
+
return self._post(
|
|
62
|
+
"/v1/bulk/pools",
|
|
63
|
+
{
|
|
64
|
+
"name": name,
|
|
65
|
+
"size": size,
|
|
66
|
+
"session_type": session_type,
|
|
67
|
+
"description": description,
|
|
68
|
+
"bytes_limit": bytes_limit,
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def list_pools(self) -> dict[str, Any]:
|
|
73
|
+
"""List proxy pools for the authenticated account."""
|
|
74
|
+
return self._get("/v1/bulk/pools")
|
|
75
|
+
|
|
76
|
+
def get_pool(self, pool_id: str) -> dict[str, Any]:
|
|
77
|
+
"""Retrieve the endpoints of a proxy pool."""
|
|
78
|
+
return self._get(f"/v1/bulk/pools/{pool_id}/endpoints")
|
|
79
|
+
|
|
80
|
+
def get_proxies(self, pool_id: str) -> list[dict[str, Any]]:
|
|
81
|
+
"""Return the list of endpoint dicts for a pool."""
|
|
82
|
+
data = self.get_pool(pool_id)
|
|
83
|
+
return data.get("endpoints", [])
|
|
84
|
+
|
|
85
|
+
def revoke_pool(self, pool_id: str) -> None:
|
|
86
|
+
"""Soft-delete a proxy pool."""
|
|
87
|
+
self._delete(f"/v1/bulk/pools/{pool_id}")
|
|
88
|
+
|
|
89
|
+
def as_requests_proxy(self, pool_id: str, index: int = 0) -> dict[str, str]:
|
|
90
|
+
"""Return a ``proxies`` dict compatible with the ``requests`` library.
|
|
91
|
+
|
|
92
|
+
Endpoint host/port come from the API (production buyer proxy is
|
|
93
|
+
``proxy.proxyhubb.com:8090``).
|
|
94
|
+
"""
|
|
95
|
+
endpoints = self.get_proxies(pool_id)
|
|
96
|
+
if not endpoints:
|
|
97
|
+
raise ValueError(f"Pool {pool_id!r} has no endpoints")
|
|
98
|
+
if index >= len(endpoints):
|
|
99
|
+
raise IndexError(
|
|
100
|
+
f"index {index} is out of range for pool with {len(endpoints)} endpoints"
|
|
101
|
+
)
|
|
102
|
+
ep = endpoints[index]
|
|
103
|
+
proxy_url = (
|
|
104
|
+
f"http://{ep['username']}:{ep['password']}@{ep['host']}:{ep['port']}"
|
|
105
|
+
)
|
|
106
|
+
return {"http": proxy_url, "https": proxy_url}
|
proxyhubb/proxy.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Gateway helper for routing HTTP via the ProxyHubb buyer proxy."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
import uuid
|
|
7
|
+
from typing import Any, Optional
|
|
8
|
+
|
|
9
|
+
import requests
|
|
10
|
+
|
|
11
|
+
DEFAULT_GATEWAY = "http://proxy.proxyhubb.com:8090"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ProxyClient:
|
|
15
|
+
"""Thin helper that builds ``requests``-compatible proxy URLs for the gateway.
|
|
16
|
+
|
|
17
|
+
Prefer :class:`proxyhubb.ProxyHubClient` to create pools and obtain credentials.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
gateway_url: str = DEFAULT_GATEWAY,
|
|
23
|
+
proxy_auth: Optional[str] = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
self.gateway_url = gateway_url
|
|
26
|
+
self.proxy_auth = proxy_auth
|
|
27
|
+
self.current_session_id = str(uuid.uuid4())
|
|
28
|
+
self.session_start = time.time()
|
|
29
|
+
|
|
30
|
+
def get_proxy_config(self, rotate: bool = False) -> dict[str, str]:
|
|
31
|
+
if rotate:
|
|
32
|
+
self.current_session_id = str(uuid.uuid4())
|
|
33
|
+
self.session_start = time.time()
|
|
34
|
+
|
|
35
|
+
auth_str = self.proxy_auth if self.proxy_auth else "anonymous"
|
|
36
|
+
host = self.gateway_url.split("//")[-1]
|
|
37
|
+
proxy_str = f"http://{auth_str}:{self.current_session_id}@{host}"
|
|
38
|
+
return {"http": proxy_str, "https": proxy_str}
|
|
39
|
+
|
|
40
|
+
def request(self, method: str, url: str, rotate: bool = False, **kwargs: Any):
|
|
41
|
+
proxies = self.get_proxy_config(rotate=rotate)
|
|
42
|
+
try:
|
|
43
|
+
return requests.request(method, url, proxies=proxies, **kwargs)
|
|
44
|
+
except Exception:
|
|
45
|
+
return requests.request(
|
|
46
|
+
method, url, proxies=self.get_proxy_config(rotate=True), **kwargs
|
|
47
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: proxyhubb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the ProxyHubb Bulk Proxy Pool API
|
|
5
|
+
Author: ProxyHubb
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://proxyhubb.com
|
|
8
|
+
Project-URL: Repository, https://github.com/proxyhubb/proxyhubb
|
|
9
|
+
Project-URL: Issues, https://github.com/proxyhubb/proxyhubb/issues
|
|
10
|
+
Keywords: proxyhubb,proxy,sdk,api
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: requests>=2.31.0
|
|
18
|
+
Requires-Dist: urllib3>=2.0.0
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# proxyhubb
|
|
22
|
+
|
|
23
|
+
Official Python client for the ProxyHubb Bulk Proxy Pool API.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install proxyhubb
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from proxyhubb import ProxyHubClient
|
|
35
|
+
|
|
36
|
+
client = ProxyHubClient("phub_...") # default: https://api.proxyhubb.com
|
|
37
|
+
pool = client.create_pool("scrapers", size=5)
|
|
38
|
+
proxies = client.as_requests_proxy(pool["id"])
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Create an API key in the dashboard (`phub_…`).
|
|
42
|
+
|
|
43
|
+
Gateway helper (optional):
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from proxyhubb import ProxyClient
|
|
47
|
+
|
|
48
|
+
gw = ProxyClient(proxy_auth="user:pass")
|
|
49
|
+
resp = gw.request("GET", "https://api.ipify.org")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
proxyhubb/__init__.py,sha256=L_QeDYNF0wQSbW_GIJxxAYFzUeLd97p3Haz_wuyGEmI,227
|
|
2
|
+
proxyhubb/client.py,sha256=YMPbe-ZG6TH2C_MWP_KWH4oS26cf5bKQUpUuX-VBKho,3402
|
|
3
|
+
proxyhubb/proxy.py,sha256=10kAgSl8CLvgshXa9-eW3ORq6N9JsNsxFhS9ZzQSP5U,1563
|
|
4
|
+
proxyhubb-0.1.0.dist-info/licenses/LICENSE,sha256=RWizfvLDLh8xaESHQTymcdJFj54ZxbVn9keRWk-kvvs,1066
|
|
5
|
+
proxyhubb-0.1.0.dist-info/METADATA,sha256=_8PIjlupQRk-AlKJ4WjZmsV39G9dMfra9KWo_qGygWw,1265
|
|
6
|
+
proxyhubb-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
7
|
+
proxyhubb-0.1.0.dist-info/top_level.txt,sha256=eVFMxnGN3Ya8BD2GrnHppVOLbqbceZ0z6hXl5jApYNI,10
|
|
8
|
+
proxyhubb-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ProxyHubb
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
proxyhubb
|