thordata-sdk 1.3.0__py3-none-any.whl → 1.5.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.
- thordata/__init__.py +4 -40
- thordata/async_client.py +572 -1241
- thordata/async_unlimited.py +130 -0
- thordata/client.py +1184 -1309
- thordata/core/__init__.py +23 -0
- thordata/core/async_http_client.py +91 -0
- thordata/core/http_client.py +79 -0
- thordata/core/tunnel.py +287 -0
- thordata/demo.py +2 -2
- thordata/enums.py +41 -380
- thordata/models.py +37 -1193
- thordata/tools/__init__.py +28 -0
- thordata/tools/base.py +42 -0
- thordata/tools/code.py +26 -0
- thordata/tools/ecommerce.py +67 -0
- thordata/tools/search.py +73 -0
- thordata/tools/social.py +190 -0
- thordata/tools/video.py +81 -0
- thordata/types/__init__.py +77 -0
- thordata/types/common.py +141 -0
- thordata/types/proxy.py +340 -0
- thordata/types/serp.py +224 -0
- thordata/types/task.py +144 -0
- thordata/types/universal.py +66 -0
- thordata/unlimited.py +169 -0
- {thordata_sdk-1.3.0.dist-info → thordata_sdk-1.5.0.dist-info}/METADATA +74 -51
- thordata_sdk-1.5.0.dist-info/RECORD +35 -0
- {thordata_sdk-1.3.0.dist-info → thordata_sdk-1.5.0.dist-info}/WHEEL +1 -1
- thordata_sdk-1.3.0.dist-info/RECORD +0 -16
- {thordata_sdk-1.3.0.dist-info → thordata_sdk-1.5.0.dist-info}/licenses/LICENSE +0 -0
- {thordata_sdk-1.3.0.dist-info → thordata_sdk-1.5.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Async interface for Unlimited Residential Proxy management.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import asyncio
|
|
8
|
+
from typing import TYPE_CHECKING, Any
|
|
9
|
+
|
|
10
|
+
import aiohttp
|
|
11
|
+
|
|
12
|
+
from ._utils import build_public_api_headers, extract_error_message
|
|
13
|
+
from .exceptions import (
|
|
14
|
+
ThordataNetworkError,
|
|
15
|
+
ThordataTimeoutError,
|
|
16
|
+
raise_for_code,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
from .async_client import AsyncThordataClient
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AsyncUnlimitedNamespace:
|
|
24
|
+
"""
|
|
25
|
+
Async Namespace for Unlimited Residential Proxy operations.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, client: AsyncThordataClient):
|
|
29
|
+
self._client = client
|
|
30
|
+
self._api_base = client._locations_base_url.replace("/locations", "")
|
|
31
|
+
|
|
32
|
+
async def list_servers(self) -> list[dict[str, Any]]:
|
|
33
|
+
"""Get the list of unlimited proxy servers."""
|
|
34
|
+
self._client._require_public_credentials()
|
|
35
|
+
params = {
|
|
36
|
+
"token": self._client.public_token or "",
|
|
37
|
+
"key": self._client.public_key or "",
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
async with self._client._get_session().get(
|
|
42
|
+
f"{self._api_base}/unlimited/server-list",
|
|
43
|
+
params=params,
|
|
44
|
+
timeout=self._client._api_timeout,
|
|
45
|
+
) as response:
|
|
46
|
+
response.raise_for_status()
|
|
47
|
+
data = await response.json()
|
|
48
|
+
|
|
49
|
+
if isinstance(data, dict):
|
|
50
|
+
if data.get("code") != 200:
|
|
51
|
+
msg = extract_error_message(data)
|
|
52
|
+
raise_for_code(
|
|
53
|
+
f"List servers failed: {msg}",
|
|
54
|
+
code=data.get("code"),
|
|
55
|
+
payload=data,
|
|
56
|
+
)
|
|
57
|
+
return data.get("data") or []
|
|
58
|
+
return []
|
|
59
|
+
|
|
60
|
+
except aiohttp.ClientError as e:
|
|
61
|
+
raise ThordataNetworkError(
|
|
62
|
+
f"List servers failed: {e}", original_error=e
|
|
63
|
+
) from e
|
|
64
|
+
|
|
65
|
+
async def restart_server(self, plan_name: str) -> dict[str, Any]:
|
|
66
|
+
return await self._post_action(
|
|
67
|
+
"/unlimited/restart-server", {"plan_name": plan_name}
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
async def renew(self, plan_name: str, month: int) -> dict[str, Any]:
|
|
71
|
+
return await self._post_action(
|
|
72
|
+
"/unlimited/renew", {"plan_name": plan_name, "month": str(month)}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
async def upgrade(self, plan_name: str, target_plan: str) -> dict[str, Any]:
|
|
76
|
+
return await self._post_action(
|
|
77
|
+
"/unlimited/upgrade",
|
|
78
|
+
{"plan_name": plan_name, "target_plan": target_plan},
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
async def list_bound_users(self, ip: str) -> list[dict[str, Any]]:
|
|
82
|
+
data = await self._post_action("/get_unlimited_servers_bind_user", {"ip": ip})
|
|
83
|
+
return data.get("list") or [] if isinstance(data, dict) else []
|
|
84
|
+
|
|
85
|
+
async def bind_user(self, ip: str, username: str) -> dict[str, Any]:
|
|
86
|
+
return await self._post_action(
|
|
87
|
+
"/add_unlimited_servers_bind_user", {"ip": ip, "username": username}
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
async def unbind_user(self, ip: str, username: str) -> dict[str, Any]:
|
|
91
|
+
return await self._post_action(
|
|
92
|
+
"/del_unlimited_servers_bind_user", {"ip": ip, "username": username}
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
async def _post_action(
|
|
96
|
+
self, endpoint: str, payload: dict[str, Any]
|
|
97
|
+
) -> dict[str, Any]:
|
|
98
|
+
self._client._require_public_credentials()
|
|
99
|
+
headers = build_public_api_headers(
|
|
100
|
+
self._client.public_token or "", self._client.public_key or ""
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
async with self._client._get_session().post(
|
|
105
|
+
f"{self._api_base}{endpoint}",
|
|
106
|
+
data=payload,
|
|
107
|
+
headers=headers,
|
|
108
|
+
timeout=self._client._api_timeout,
|
|
109
|
+
) as response:
|
|
110
|
+
response.raise_for_status()
|
|
111
|
+
data = await response.json()
|
|
112
|
+
|
|
113
|
+
if data.get("code") != 200:
|
|
114
|
+
msg = extract_error_message(data)
|
|
115
|
+
raise_for_code(
|
|
116
|
+
f"Action {endpoint} failed: {msg}",
|
|
117
|
+
code=data.get("code"),
|
|
118
|
+
payload=data,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
return data.get("data", {})
|
|
122
|
+
|
|
123
|
+
except asyncio.TimeoutError as e:
|
|
124
|
+
raise ThordataTimeoutError(
|
|
125
|
+
f"Action {endpoint} timed out: {e}", original_error=e
|
|
126
|
+
) from e
|
|
127
|
+
except aiohttp.ClientError as e:
|
|
128
|
+
raise ThordataNetworkError(
|
|
129
|
+
f"Action {endpoint} failed: {e}", original_error=e
|
|
130
|
+
) from e
|