proxyzen 0.1.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.
- proxyzen-0.1.0/LICENSE +21 -0
- proxyzen-0.1.0/PKG-INFO +109 -0
- proxyzen-0.1.0/README.md +89 -0
- proxyzen-0.1.0/pyproject.toml +28 -0
- proxyzen-0.1.0/src/proxyzen/__init__.py +5 -0
- proxyzen-0.1.0/src/proxyzen/client.py +160 -0
proxyzen-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ProxyZen
|
|
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.
|
proxyzen-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: proxyzen
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python client for the ProxyZen proxy API: buy, renew and list IPv4/IPv6, residential and mobile proxies.
|
|
5
|
+
Project-URL: Homepage, https://proxyzen.net/
|
|
6
|
+
Project-URL: Documentation, https://proxyzen.net/en/api
|
|
7
|
+
Project-URL: Buy proxies, https://proxyzen.net/en/prices
|
|
8
|
+
Project-URL: Source, https://github.com/ProxyZen-net/proxyzen-python
|
|
9
|
+
Author: ProxyZen
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,http proxy,ipv4,ipv6,mobile proxies,proxies,proxy,proxyzen,residential proxies,socks5
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Internet :: Proxy Servers
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# proxyzen — Python client for the ProxyZen proxy API
|
|
22
|
+
|
|
23
|
+
Official, dependency-free Python client for the [ProxyZen](https://proxyzen.net/) API. Buy, renew and list private **IPv4 / IPv6** proxies and **residential / mobile** traffic from your own code, scripts or bots.
|
|
24
|
+
|
|
25
|
+
- Private IPv4 and IPv6 proxies in many countries, HTTP(S) and SOCKS5 on every proxy
|
|
26
|
+
- Residential (140+ countries) and mobile proxies billed per GB, traffic never expires
|
|
27
|
+
- Standard library only, Python 3.8+
|
|
28
|
+
|
|
29
|
+
Docs: **https://proxyzen.net/en/api** · Prices: **https://proxyzen.net/en/prices**
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install proxyzen
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
Create an API key in your dashboard: https://proxyzen.net/cabinet/api
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from proxyzen import ProxyZen
|
|
43
|
+
|
|
44
|
+
pz = ProxyZen("pz_your_key") # or set the PROXYZEN_KEY environment variable
|
|
45
|
+
|
|
46
|
+
print(pz.balance())
|
|
47
|
+
|
|
48
|
+
# countries with IPv4 in stock and prices
|
|
49
|
+
in_stock = [c["code"] for c in pz.countries() if c["available"]["ipv4"] > 0]
|
|
50
|
+
print(in_stock)
|
|
51
|
+
print(pz.prices("DE", "ipv4"))
|
|
52
|
+
|
|
53
|
+
# buy 2 IPv4 proxies in Germany for 30 days (spends money from the balance)
|
|
54
|
+
order = pz.buy("DE", quantity=2, days=30)
|
|
55
|
+
for p in order["proxies"]:
|
|
56
|
+
print(ProxyZen.proxy_url(p)) # http://login:pass@host:port
|
|
57
|
+
print(ProxyZen.proxy_url(p, "socks5")) # socks5://login:pass@host:port
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Manage your proxies
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
for p in pz.iter_proxies(status="active"):
|
|
64
|
+
print(p["host"], p["http_port"], p["expires_at"])
|
|
65
|
+
|
|
66
|
+
pz.renew([123, 124], days=30) # renew by id
|
|
67
|
+
pz.set_auto_renew(123, True) # auto-renew from the balance
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Residential and mobile proxies (per GB)
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
print(pz.traffic_products()) # prices
|
|
74
|
+
pz.buy_traffic(1, "residential") # 1 GB, spends money
|
|
75
|
+
for plan in pz.traffic_plans():
|
|
76
|
+
user = f"{plan['username']}-country-US-session-ab12cd-time-10" # US, sticky IP for 10 minutes
|
|
77
|
+
print(f"http://{user}:{plan['password']}@{plan['host']}:{plan['http_port']}")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Use with requests
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import requests
|
|
84
|
+
proxy = ProxyZen.proxy_url(order["proxies"][0])
|
|
85
|
+
print(requests.get("https://api.ipify.org", proxies={"http": proxy, "https": proxy}).text)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
More examples: [how to use proxies in Python and Node.js](https://proxyzen.net/en/blog/proxy-in-python-nodejs), [Puppeteer, Playwright, Selenium and curl](https://proxyzen.net/en/blog/proxy-puppeteer-playwright-curl).
|
|
89
|
+
|
|
90
|
+
## Errors
|
|
91
|
+
|
|
92
|
+
API errors raise `ProxyZenError` with `.status`, `.code` and `.message`:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from proxyzen import ProxyZenError
|
|
96
|
+
try:
|
|
97
|
+
pz.buy("DE", quantity=1, days=30)
|
|
98
|
+
except ProxyZenError as e:
|
|
99
|
+
print(e.code, e.message) # e.g. insufficient_funds
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Links
|
|
103
|
+
|
|
104
|
+
- Website: https://proxyzen.net/
|
|
105
|
+
- API documentation: https://proxyzen.net/en/api
|
|
106
|
+
- Free tools: [My IP](https://proxyzen.net/en/tools/my-ip), [proxy checker](https://proxyzen.net/en/tools/proxy-checker), [IP check](https://proxyzen.net/en/tools/ip-check)
|
|
107
|
+
- Telegram bot: https://t.me/proxyzen_app
|
|
108
|
+
|
|
109
|
+
MIT License.
|
proxyzen-0.1.0/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# proxyzen — Python client for the ProxyZen proxy API
|
|
2
|
+
|
|
3
|
+
Official, dependency-free Python client for the [ProxyZen](https://proxyzen.net/) API. Buy, renew and list private **IPv4 / IPv6** proxies and **residential / mobile** traffic from your own code, scripts or bots.
|
|
4
|
+
|
|
5
|
+
- Private IPv4 and IPv6 proxies in many countries, HTTP(S) and SOCKS5 on every proxy
|
|
6
|
+
- Residential (140+ countries) and mobile proxies billed per GB, traffic never expires
|
|
7
|
+
- Standard library only, Python 3.8+
|
|
8
|
+
|
|
9
|
+
Docs: **https://proxyzen.net/en/api** · Prices: **https://proxyzen.net/en/prices**
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install proxyzen
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
Create an API key in your dashboard: https://proxyzen.net/cabinet/api
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from proxyzen import ProxyZen
|
|
23
|
+
|
|
24
|
+
pz = ProxyZen("pz_your_key") # or set the PROXYZEN_KEY environment variable
|
|
25
|
+
|
|
26
|
+
print(pz.balance())
|
|
27
|
+
|
|
28
|
+
# countries with IPv4 in stock and prices
|
|
29
|
+
in_stock = [c["code"] for c in pz.countries() if c["available"]["ipv4"] > 0]
|
|
30
|
+
print(in_stock)
|
|
31
|
+
print(pz.prices("DE", "ipv4"))
|
|
32
|
+
|
|
33
|
+
# buy 2 IPv4 proxies in Germany for 30 days (spends money from the balance)
|
|
34
|
+
order = pz.buy("DE", quantity=2, days=30)
|
|
35
|
+
for p in order["proxies"]:
|
|
36
|
+
print(ProxyZen.proxy_url(p)) # http://login:pass@host:port
|
|
37
|
+
print(ProxyZen.proxy_url(p, "socks5")) # socks5://login:pass@host:port
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Manage your proxies
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
for p in pz.iter_proxies(status="active"):
|
|
44
|
+
print(p["host"], p["http_port"], p["expires_at"])
|
|
45
|
+
|
|
46
|
+
pz.renew([123, 124], days=30) # renew by id
|
|
47
|
+
pz.set_auto_renew(123, True) # auto-renew from the balance
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Residential and mobile proxies (per GB)
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
print(pz.traffic_products()) # prices
|
|
54
|
+
pz.buy_traffic(1, "residential") # 1 GB, spends money
|
|
55
|
+
for plan in pz.traffic_plans():
|
|
56
|
+
user = f"{plan['username']}-country-US-session-ab12cd-time-10" # US, sticky IP for 10 minutes
|
|
57
|
+
print(f"http://{user}:{plan['password']}@{plan['host']}:{plan['http_port']}")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Use with requests
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import requests
|
|
64
|
+
proxy = ProxyZen.proxy_url(order["proxies"][0])
|
|
65
|
+
print(requests.get("https://api.ipify.org", proxies={"http": proxy, "https": proxy}).text)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
More examples: [how to use proxies in Python and Node.js](https://proxyzen.net/en/blog/proxy-in-python-nodejs), [Puppeteer, Playwright, Selenium and curl](https://proxyzen.net/en/blog/proxy-puppeteer-playwright-curl).
|
|
69
|
+
|
|
70
|
+
## Errors
|
|
71
|
+
|
|
72
|
+
API errors raise `ProxyZenError` with `.status`, `.code` and `.message`:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from proxyzen import ProxyZenError
|
|
76
|
+
try:
|
|
77
|
+
pz.buy("DE", quantity=1, days=30)
|
|
78
|
+
except ProxyZenError as e:
|
|
79
|
+
print(e.code, e.message) # e.g. insufficient_funds
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Links
|
|
83
|
+
|
|
84
|
+
- Website: https://proxyzen.net/
|
|
85
|
+
- API documentation: https://proxyzen.net/en/api
|
|
86
|
+
- Free tools: [My IP](https://proxyzen.net/en/tools/my-ip), [proxy checker](https://proxyzen.net/en/tools/proxy-checker), [IP check](https://proxyzen.net/en/tools/ip-check)
|
|
87
|
+
- Telegram bot: https://t.me/proxyzen_app
|
|
88
|
+
|
|
89
|
+
MIT License.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "proxyzen"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python client for the ProxyZen proxy API: buy, renew and list IPv4/IPv6, residential and mobile proxies."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
authors = [{ name = "ProxyZen" }]
|
|
14
|
+
keywords = ["proxy", "proxies", "socks5", "http proxy", "residential proxies", "mobile proxies", "ipv4", "ipv6", "api", "proxyzen"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Topic :: Internet :: Proxy Servers",
|
|
20
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
21
|
+
]
|
|
22
|
+
dependencies = []
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://proxyzen.net/"
|
|
26
|
+
Documentation = "https://proxyzen.net/en/api"
|
|
27
|
+
"Buy proxies" = "https://proxyzen.net/en/prices"
|
|
28
|
+
Source = "https://github.com/ProxyZen-net/proxyzen-python"
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""ProxyZen API client. Standard library only, no dependencies.
|
|
2
|
+
|
|
3
|
+
Docs: https://proxyzen.net/en/api
|
|
4
|
+
"""
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import urllib.error
|
|
8
|
+
import urllib.parse
|
|
9
|
+
import urllib.request
|
|
10
|
+
from typing import Any, Dict, Iterable, List, Optional
|
|
11
|
+
|
|
12
|
+
DEFAULT_BASE_URL = "https://proxyzen.net/api/v1"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ProxyZenError(Exception):
|
|
16
|
+
"""API error: HTTP status, machine-readable code and human-readable message."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, status: int, code: str, message: str):
|
|
19
|
+
super().__init__(f"{status} {code}: {message}")
|
|
20
|
+
self.status = status
|
|
21
|
+
self.code = code
|
|
22
|
+
self.message = message
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ProxyZen:
|
|
26
|
+
"""Client for https://proxyzen.net/api/v1.
|
|
27
|
+
|
|
28
|
+
>>> pz = ProxyZen("pz_...") # or set PROXYZEN_KEY
|
|
29
|
+
>>> pz.balance()
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(self, api_key: Optional[str] = None, base_url: str = DEFAULT_BASE_URL,
|
|
33
|
+
timeout: float = 60, lang: Optional[str] = None):
|
|
34
|
+
self.api_key = api_key or os.environ.get("PROXYZEN_KEY")
|
|
35
|
+
if not self.api_key:
|
|
36
|
+
raise ValueError("API key required: pass api_key or set PROXYZEN_KEY "
|
|
37
|
+
"(create one at https://proxyzen.net/cabinet/api)")
|
|
38
|
+
self.base_url = base_url.rstrip("/")
|
|
39
|
+
self.timeout = timeout
|
|
40
|
+
self.lang = lang
|
|
41
|
+
|
|
42
|
+
# --- low level -------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
def request(self, method: str, path: str, params: Optional[Dict[str, Any]] = None,
|
|
45
|
+
body: Optional[Dict[str, Any]] = None) -> Any:
|
|
46
|
+
url = self.base_url + path
|
|
47
|
+
params = {k: v for k, v in (params or {}).items() if v is not None}
|
|
48
|
+
if self.lang:
|
|
49
|
+
params.setdefault("lang", self.lang)
|
|
50
|
+
if params:
|
|
51
|
+
url += "?" + urllib.parse.urlencode(params)
|
|
52
|
+
data = json.dumps(body).encode() if body is not None else None
|
|
53
|
+
req = urllib.request.Request(url, data=data, method=method, headers={
|
|
54
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
55
|
+
"Accept": "application/json",
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
"User-Agent": "proxyzen-python/0.1.0",
|
|
58
|
+
})
|
|
59
|
+
try:
|
|
60
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
61
|
+
return json.loads(resp.read().decode() or "null")
|
|
62
|
+
except urllib.error.HTTPError as e:
|
|
63
|
+
raw = e.read().decode(errors="replace")
|
|
64
|
+
try:
|
|
65
|
+
err = json.loads(raw).get("error", {})
|
|
66
|
+
except ValueError:
|
|
67
|
+
err = {}
|
|
68
|
+
raise ProxyZenError(e.code, err.get("code", "http_error"), err.get("message", raw[:200])) from None
|
|
69
|
+
|
|
70
|
+
# --- account ---------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
def balance(self) -> Dict[str, Any]:
|
|
73
|
+
"""Account balance."""
|
|
74
|
+
return self.request("GET", "/balance")
|
|
75
|
+
|
|
76
|
+
# --- IPv4 / IPv6 -----------------------------------------------------
|
|
77
|
+
|
|
78
|
+
def countries(self) -> List[Dict[str, Any]]:
|
|
79
|
+
"""Countries with the number of available IPv4/IPv6 addresses."""
|
|
80
|
+
return self.request("GET", "/countries")["data"]
|
|
81
|
+
|
|
82
|
+
def prices(self, country: str, type: str = "ipv4") -> Any:
|
|
83
|
+
"""Prices per IP for each rental period. type: 'ipv4' or 'ipv6'."""
|
|
84
|
+
return self.request("GET", "/prices", {"country": country.upper(), "type": type})["data"]
|
|
85
|
+
|
|
86
|
+
def buy(self, country: str, quantity: int, days: int, type: str = "ipv4",
|
|
87
|
+
auto_renew: Optional[bool] = None) -> Dict[str, Any]:
|
|
88
|
+
"""Buy private proxies. Spends money from the balance. Returns the order with its proxies."""
|
|
89
|
+
body: Dict[str, Any] = {"country": country.upper(), "type": type, "quantity": quantity, "days": days}
|
|
90
|
+
if auto_renew is not None:
|
|
91
|
+
body["auto_renew"] = auto_renew
|
|
92
|
+
return self.request("POST", "/orders", body=body)
|
|
93
|
+
|
|
94
|
+
def order(self, order_id: int) -> Dict[str, Any]:
|
|
95
|
+
"""Order details."""
|
|
96
|
+
return self.request("GET", f"/orders/{int(order_id)}")
|
|
97
|
+
|
|
98
|
+
def proxies(self, status: Optional[str] = None, type: Optional[str] = None,
|
|
99
|
+
country: Optional[str] = None, order_id: Optional[int] = None,
|
|
100
|
+
per_page: int = 100, page: int = 1) -> Dict[str, Any]:
|
|
101
|
+
"""One page of your proxies: {'data': [...], 'meta': {...}}.
|
|
102
|
+
status: 'active', 'grace', 'expired' or 'all' (default: renewable ones)."""
|
|
103
|
+
return self.request("GET", "/proxies", {
|
|
104
|
+
"status": status, "type": type, "country": country.upper() if country else None,
|
|
105
|
+
"order_id": order_id, "per_page": per_page, "page": page,
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
def iter_proxies(self, **filters: Any) -> Iterable[Dict[str, Any]]:
|
|
109
|
+
"""All your proxies across pages."""
|
|
110
|
+
page = 1
|
|
111
|
+
while True:
|
|
112
|
+
res = self.proxies(page=page, **filters)
|
|
113
|
+
yield from res["data"]
|
|
114
|
+
if page >= res["meta"]["last_page"]:
|
|
115
|
+
break
|
|
116
|
+
page += 1
|
|
117
|
+
|
|
118
|
+
def renew(self, ids: List[int], days: int) -> Dict[str, Any]:
|
|
119
|
+
"""Renew proxies by id. Spends money from the balance."""
|
|
120
|
+
return self.request("POST", "/proxies/renew", body={"ids": list(ids), "days": days})
|
|
121
|
+
|
|
122
|
+
def set_auto_renew(self, proxy_id: int, enabled: bool) -> Dict[str, Any]:
|
|
123
|
+
"""Turn auto-renewal on or off for a proxy."""
|
|
124
|
+
return self.request("POST", f"/proxies/{int(proxy_id)}/auto-renew", body={"enabled": enabled})
|
|
125
|
+
|
|
126
|
+
# --- residential / mobile (per GB) -----------------------------------
|
|
127
|
+
|
|
128
|
+
def traffic_products(self) -> Any:
|
|
129
|
+
"""Residential and mobile traffic prices."""
|
|
130
|
+
return self.request("GET", "/traffic/products")["data"]
|
|
131
|
+
|
|
132
|
+
def traffic_countries(self, type: str = "residential") -> Any:
|
|
133
|
+
"""Countries available for 'residential' or 'mobile' traffic."""
|
|
134
|
+
return self.request("GET", "/traffic/countries", {"type": type})["data"]
|
|
135
|
+
|
|
136
|
+
def traffic_country(self, code: str, type: str = "residential") -> Dict[str, Any]:
|
|
137
|
+
"""Regions and cities of a country for residential or mobile traffic."""
|
|
138
|
+
return self.request("GET", f"/traffic/countries/{code.upper()}", {"type": type})
|
|
139
|
+
|
|
140
|
+
def buy_traffic(self, gb: int, type: str = "residential") -> Dict[str, Any]:
|
|
141
|
+
"""Buy residential or mobile traffic in GB. Spends money. Traffic never expires."""
|
|
142
|
+
return self.request("POST", "/traffic/orders", body={"type": type, "gb": gb})
|
|
143
|
+
|
|
144
|
+
def traffic_plans(self) -> List[Dict[str, Any]]:
|
|
145
|
+
"""Your traffic plans with username, password, host, ports and remaining GB."""
|
|
146
|
+
return self.request("GET", "/traffic/plans")["data"]
|
|
147
|
+
|
|
148
|
+
def reset_traffic_password(self, type: str = "residential") -> Dict[str, Any]:
|
|
149
|
+
"""Generate a new password for the residential or mobile plan."""
|
|
150
|
+
return self.request("POST", f"/traffic/plans/{type}/reset-password")
|
|
151
|
+
|
|
152
|
+
# --- helpers ---------------------------------------------------------
|
|
153
|
+
|
|
154
|
+
@staticmethod
|
|
155
|
+
def proxy_url(proxy: Dict[str, Any], scheme: str = "http") -> str:
|
|
156
|
+
"""Build 'http://login:password@host:port' (or socks5://) from a proxy returned by the API."""
|
|
157
|
+
port = proxy.get("socks5_port") if scheme.startswith("socks") else proxy.get("http_port")
|
|
158
|
+
user = urllib.parse.quote(str(proxy["login"]), safe="")
|
|
159
|
+
pwd = urllib.parse.quote(str(proxy["password"]), safe="")
|
|
160
|
+
return f"{scheme}://{user}:{pwd}@{proxy['host']}:{port}"
|