thordata-sdk 0.2.4__py3-none-any.whl → 1.2.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 +151 -0
- thordata/_example_utils.py +77 -0
- thordata/_utils.py +190 -0
- thordata/async_client.py +1675 -0
- thordata/client.py +1644 -0
- thordata/demo.py +138 -0
- thordata/enums.py +384 -0
- thordata/exceptions.py +355 -0
- thordata/models.py +1197 -0
- thordata/retry.py +382 -0
- thordata/serp_engines.py +166 -0
- thordata_sdk-1.2.0.dist-info/METADATA +208 -0
- thordata_sdk-1.2.0.dist-info/RECORD +16 -0
- {thordata_sdk-0.2.4.dist-info → thordata_sdk-1.2.0.dist-info}/WHEEL +1 -1
- thordata_sdk-1.2.0.dist-info/licenses/LICENSE +21 -0
- thordata_sdk-1.2.0.dist-info/top_level.txt +1 -0
- thordata_sdk/__init__.py +0 -9
- thordata_sdk/async_client.py +0 -247
- thordata_sdk/client.py +0 -303
- thordata_sdk/enums.py +0 -20
- thordata_sdk/parameters.py +0 -41
- thordata_sdk-0.2.4.dist-info/LICENSE +0 -201
- thordata_sdk-0.2.4.dist-info/METADATA +0 -113
- thordata_sdk-0.2.4.dist-info/RECORD +0 -10
- thordata_sdk-0.2.4.dist-info/top_level.txt +0 -1
thordata_sdk/client.py
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import logging
|
|
3
|
-
import json
|
|
4
|
-
import base64
|
|
5
|
-
from typing import Dict, Any, Union, Optional
|
|
6
|
-
|
|
7
|
-
from .enums import Engine
|
|
8
|
-
from .parameters import normalize_serp_params
|
|
9
|
-
|
|
10
|
-
# Configure a library-specific logger
|
|
11
|
-
logger = logging.getLogger(__name__)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class ThordataClient:
|
|
15
|
-
"""
|
|
16
|
-
The official synchronous Python client for Thordata.
|
|
17
|
-
|
|
18
|
-
Handles authentication for:
|
|
19
|
-
1. Proxy Network (HTTP/HTTPS)
|
|
20
|
-
2. SERP API (Real-time Search)
|
|
21
|
-
3. Universal Scraping API (Single Page)
|
|
22
|
-
4. Web Scraper API (Async Task Management)
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
def __init__(
|
|
26
|
-
self,
|
|
27
|
-
scraper_token: str,
|
|
28
|
-
public_token: str,
|
|
29
|
-
public_key: str,
|
|
30
|
-
proxy_host: str = "gate.thordata.com",
|
|
31
|
-
proxy_port: int = 22225
|
|
32
|
-
):
|
|
33
|
-
"""
|
|
34
|
-
Initialize the Thordata Client.
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
scraper_token (str): Token from Dashboard bottom.
|
|
38
|
-
public_token (str): Token from Public API section.
|
|
39
|
-
public_key (str): Key from Public API section.
|
|
40
|
-
proxy_host (str): Proxy gateway host.
|
|
41
|
-
proxy_port (int): Proxy gateway port.
|
|
42
|
-
"""
|
|
43
|
-
self.scraper_token = scraper_token
|
|
44
|
-
self.public_token = public_token
|
|
45
|
-
self.public_key = public_key
|
|
46
|
-
|
|
47
|
-
# Proxy Configuration
|
|
48
|
-
self.proxy_url = (
|
|
49
|
-
f"http://{self.scraper_token}:@{proxy_host}:{proxy_port}"
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
# API Endpoints
|
|
53
|
-
self.base_url = "https://scraperapi.thordata.com"
|
|
54
|
-
self.universal_url = "https://universalapi.thordata.com"
|
|
55
|
-
self.api_url = "https://api.thordata.com/api/web-scraper-api"
|
|
56
|
-
|
|
57
|
-
self.SERP_API_URL = f"{self.base_url}/request"
|
|
58
|
-
self.UNIVERSAL_API_URL = f"{self.universal_url}/request"
|
|
59
|
-
self.SCRAPER_BUILDER_URL = f"{self.base_url}/builder"
|
|
60
|
-
self.SCRAPER_STATUS_URL = f"{self.api_url}/tasks-status"
|
|
61
|
-
self.SCRAPER_DOWNLOAD_URL = f"{self.api_url}/tasks-download"
|
|
62
|
-
|
|
63
|
-
self.session = requests.Session()
|
|
64
|
-
self.session.proxies = {
|
|
65
|
-
"http": self.proxy_url,
|
|
66
|
-
"https": self.proxy_url,
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
def get(self, url: str, **kwargs) -> requests.Response:
|
|
70
|
-
"""
|
|
71
|
-
Send a GET request through the Thordata Proxy Network.
|
|
72
|
-
"""
|
|
73
|
-
logger.debug(f"Proxy Request: {url}")
|
|
74
|
-
kwargs.setdefault("timeout", 30)
|
|
75
|
-
return self.session.get(url, **kwargs)
|
|
76
|
-
|
|
77
|
-
def serp_search(
|
|
78
|
-
self,
|
|
79
|
-
query: str,
|
|
80
|
-
engine: Union[Engine, str] = Engine.GOOGLE, # 既可以是枚举,也可以是字符串
|
|
81
|
-
num: int = 10,
|
|
82
|
-
**kwargs # 这里接收所有额外参数 (比如 type="maps")
|
|
83
|
-
) -> Dict[str, Any]:
|
|
84
|
-
"""
|
|
85
|
-
Execute a real-time SERP search.
|
|
86
|
-
|
|
87
|
-
Args:
|
|
88
|
-
query: Keywords
|
|
89
|
-
engine: 'google', 'bing', 'yandex' etc.
|
|
90
|
-
num: Number of results (default 10)
|
|
91
|
-
**kwargs: Extra parameters (e.g., type="shopping", location="London")
|
|
92
|
-
"""
|
|
93
|
-
# 兼容处理:如果用户传的是枚举对象,取它的值;如果是字符串,转小写
|
|
94
|
-
engine_str = engine.value if isinstance(engine, Engine) else engine.lower()
|
|
95
|
-
|
|
96
|
-
# 调用 parameters.py 里的逻辑
|
|
97
|
-
payload = normalize_serp_params(engine_str, query, num=num, **kwargs)
|
|
98
|
-
|
|
99
|
-
headers = {
|
|
100
|
-
"Authorization": f"Bearer {self.scraper_token}",
|
|
101
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
logger.info(f"SERP Search: {engine_str} - {query}")
|
|
105
|
-
try:
|
|
106
|
-
response = self.session.post(
|
|
107
|
-
self.SERP_API_URL,
|
|
108
|
-
data=payload,
|
|
109
|
-
headers=headers,
|
|
110
|
-
timeout=60
|
|
111
|
-
)
|
|
112
|
-
response.raise_for_status()
|
|
113
|
-
|
|
114
|
-
data = response.json()
|
|
115
|
-
if isinstance(data, str):
|
|
116
|
-
try: data = json.loads(data)
|
|
117
|
-
except: pass
|
|
118
|
-
return data
|
|
119
|
-
except Exception as e:
|
|
120
|
-
logger.error(f"SERP Request Failed: {e}")
|
|
121
|
-
raise
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def universal_scrape(
|
|
125
|
-
self,
|
|
126
|
-
url: str,
|
|
127
|
-
js_render: bool = False,
|
|
128
|
-
output_format: str = "HTML",
|
|
129
|
-
country: str = None,
|
|
130
|
-
block_resources: bool = False
|
|
131
|
-
) -> Union[str, bytes]:
|
|
132
|
-
"""
|
|
133
|
-
Unlock target pages via the Universal Scraping API.
|
|
134
|
-
"""
|
|
135
|
-
headers = {
|
|
136
|
-
"Authorization": f"Bearer {self.scraper_token}",
|
|
137
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
payload = {
|
|
141
|
-
"url": url,
|
|
142
|
-
"js_render": "True" if js_render else "False",
|
|
143
|
-
"type": output_format.lower(),
|
|
144
|
-
"block_resources": "True" if block_resources else "False"
|
|
145
|
-
}
|
|
146
|
-
if country:
|
|
147
|
-
payload["country"] = country
|
|
148
|
-
|
|
149
|
-
logger.info(f"Universal Scrape: {url}")
|
|
150
|
-
|
|
151
|
-
try:
|
|
152
|
-
response = self.session.post(
|
|
153
|
-
self.UNIVERSAL_API_URL,
|
|
154
|
-
data=payload,
|
|
155
|
-
headers=headers,
|
|
156
|
-
timeout=60
|
|
157
|
-
)
|
|
158
|
-
response.raise_for_status()
|
|
159
|
-
|
|
160
|
-
# Parse JSON wrapper
|
|
161
|
-
try:
|
|
162
|
-
resp_json = response.json()
|
|
163
|
-
except json.JSONDecodeError:
|
|
164
|
-
# Fallback for raw response
|
|
165
|
-
if output_format.upper() == "PNG":
|
|
166
|
-
return response.content
|
|
167
|
-
return response.text
|
|
168
|
-
|
|
169
|
-
# Check API errors
|
|
170
|
-
if isinstance(resp_json, dict) and resp_json.get("code") \
|
|
171
|
-
and resp_json.get("code") != 200:
|
|
172
|
-
raise Exception(f"Universal API Error: {resp_json}")
|
|
173
|
-
|
|
174
|
-
# Extract HTML
|
|
175
|
-
if "html" in resp_json:
|
|
176
|
-
return resp_json["html"]
|
|
177
|
-
|
|
178
|
-
# Extract PNG
|
|
179
|
-
if "png" in resp_json:
|
|
180
|
-
png_str = resp_json["png"]
|
|
181
|
-
if not png_str:
|
|
182
|
-
raise Exception("API returned empty PNG data")
|
|
183
|
-
|
|
184
|
-
# 🛠️ FIX: 移除 Data URI Scheme 前缀 (data:image/png;base64,)
|
|
185
|
-
if "," in png_str:
|
|
186
|
-
png_str = png_str.split(",", 1)[1]
|
|
187
|
-
|
|
188
|
-
# Base64 解码 (处理 padding)
|
|
189
|
-
png_str = png_str.replace("\n", "").replace("\r", "")
|
|
190
|
-
missing_padding = len(png_str) % 4
|
|
191
|
-
if missing_padding:
|
|
192
|
-
png_str += '=' * (4 - missing_padding)
|
|
193
|
-
|
|
194
|
-
return base64.b64decode(png_str)
|
|
195
|
-
|
|
196
|
-
return str(resp_json)
|
|
197
|
-
|
|
198
|
-
except Exception as e:
|
|
199
|
-
logger.error(f"Universal Scrape Failed: {e}")
|
|
200
|
-
raise
|
|
201
|
-
|
|
202
|
-
def create_scraper_task(
|
|
203
|
-
self,
|
|
204
|
-
file_name: str,
|
|
205
|
-
spider_id: str, # 必须传,用户从仪表板获取
|
|
206
|
-
spider_name: str, # 必须传,例如 "youtube.com"
|
|
207
|
-
individual_params: Dict[str, Any], # 用户把具体的参数打包在这个字典里传进来
|
|
208
|
-
universal_params: Dict[str, Any] = None
|
|
209
|
-
) -> str:
|
|
210
|
-
"""
|
|
211
|
-
Create a generic Web Scraper Task.
|
|
212
|
-
|
|
213
|
-
Note: Check the Thordata Dashboard to get the correct 'spider_id' and 'spider_name'.
|
|
214
|
-
"""
|
|
215
|
-
headers = {
|
|
216
|
-
"Authorization": f"Bearer {self.scraper_token}",
|
|
217
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
# 直接打包发送,不替用户做太多复杂的校验,保证兼容性
|
|
221
|
-
payload = {
|
|
222
|
-
"spider_name": spider_name,
|
|
223
|
-
"spider_id": spider_id,
|
|
224
|
-
"spider_parameters": json.dumps([individual_params]),
|
|
225
|
-
"spider_errors": "true",
|
|
226
|
-
"file_name": file_name
|
|
227
|
-
}
|
|
228
|
-
if universal_params:
|
|
229
|
-
payload["spider_universal"] = json.dumps(universal_params)
|
|
230
|
-
|
|
231
|
-
logger.info(f"Creating Scraper Task: {spider_name} (ID: {spider_id})")
|
|
232
|
-
try:
|
|
233
|
-
response = self.session.post(
|
|
234
|
-
self.SCRAPER_BUILDER_URL,
|
|
235
|
-
data=payload,
|
|
236
|
-
headers=headers
|
|
237
|
-
)
|
|
238
|
-
response.raise_for_status()
|
|
239
|
-
data = response.json()
|
|
240
|
-
|
|
241
|
-
if data.get("code") != 200:
|
|
242
|
-
raise Exception(f"Creation failed: {data}")
|
|
243
|
-
return data["data"]["task_id"]
|
|
244
|
-
except Exception as e:
|
|
245
|
-
logger.error(f"Task Creation Failed: {e}")
|
|
246
|
-
raise
|
|
247
|
-
|
|
248
|
-
def get_task_status(self, task_id: str) -> str:
|
|
249
|
-
"""
|
|
250
|
-
Check the status of a task.
|
|
251
|
-
"""
|
|
252
|
-
headers = {
|
|
253
|
-
"token": self.public_token,
|
|
254
|
-
"key": self.public_key,
|
|
255
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
256
|
-
}
|
|
257
|
-
payload = {"tasks_ids": task_id}
|
|
258
|
-
|
|
259
|
-
try:
|
|
260
|
-
response = self.session.post(
|
|
261
|
-
self.SCRAPER_STATUS_URL,
|
|
262
|
-
data=payload,
|
|
263
|
-
headers=headers
|
|
264
|
-
)
|
|
265
|
-
response.raise_for_status()
|
|
266
|
-
data = response.json()
|
|
267
|
-
|
|
268
|
-
if data.get("code") == 200 and data.get("data"):
|
|
269
|
-
for item in data["data"]:
|
|
270
|
-
if str(item.get("task_id")) == str(task_id):
|
|
271
|
-
return item["status"]
|
|
272
|
-
return "Unknown"
|
|
273
|
-
except Exception as e:
|
|
274
|
-
logger.error(f"Status Check Failed: {e}")
|
|
275
|
-
return "Error"
|
|
276
|
-
|
|
277
|
-
def get_task_result(self, task_id: str, file_type: str = "json") -> str:
|
|
278
|
-
"""
|
|
279
|
-
Retrieve the download URL for a completed task.
|
|
280
|
-
"""
|
|
281
|
-
headers = {
|
|
282
|
-
"token": self.public_token,
|
|
283
|
-
"key": self.public_key,
|
|
284
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
285
|
-
}
|
|
286
|
-
payload = {"tasks_id": task_id, "type": file_type}
|
|
287
|
-
|
|
288
|
-
logger.info(f"Getting result URL: {task_id}")
|
|
289
|
-
try:
|
|
290
|
-
response = self.session.post(
|
|
291
|
-
self.SCRAPER_DOWNLOAD_URL,
|
|
292
|
-
data=payload,
|
|
293
|
-
headers=headers
|
|
294
|
-
)
|
|
295
|
-
response.raise_for_status()
|
|
296
|
-
data = response.json()
|
|
297
|
-
|
|
298
|
-
if data.get("code") == 200 and data.get("data"):
|
|
299
|
-
return data["data"]["download"]
|
|
300
|
-
raise Exception(f"API returned error: {data}")
|
|
301
|
-
except Exception as e:
|
|
302
|
-
logger.error(f"Get Result Failed: {e}")
|
|
303
|
-
raise
|
thordata_sdk/enums.py
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# thordata_sdk/enums.py
|
|
2
|
-
from enum import Enum
|
|
3
|
-
|
|
4
|
-
class Engine(str, Enum):
|
|
5
|
-
"""SERP 核心支持的四大引擎"""
|
|
6
|
-
GOOGLE = "google"
|
|
7
|
-
BING = "bing"
|
|
8
|
-
YANDEX = "yandex"
|
|
9
|
-
DUCKDUCKGO = "duckduckgo"
|
|
10
|
-
BAIDU = "baidu"
|
|
11
|
-
|
|
12
|
-
class GoogleSearchType(str, Enum):
|
|
13
|
-
"""Google 搜索的常见子类型 (参考你的截图)"""
|
|
14
|
-
SEARCH = "search" # 默认网页搜索
|
|
15
|
-
MAPS = "maps" # 地图
|
|
16
|
-
SHOPPING = "shopping" # 购物
|
|
17
|
-
NEWS = "news" # 新闻
|
|
18
|
-
IMAGES = "images" # 图片
|
|
19
|
-
VIDEOS = "videos" # 视频
|
|
20
|
-
# 其他冷门的先不写,用户可以通过字符串传参
|
thordata_sdk/parameters.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# thordata_sdk/parameters.py
|
|
2
|
-
from typing import Dict, Any
|
|
3
|
-
|
|
4
|
-
def normalize_serp_params(engine: str, query: str, **kwargs) -> Dict[str, Any]:
|
|
5
|
-
"""
|
|
6
|
-
统一不同搜索引擎的参数差异。
|
|
7
|
-
"""
|
|
8
|
-
# 1. 基础参数
|
|
9
|
-
payload = {
|
|
10
|
-
"num": str(kwargs.get("num", 10)),
|
|
11
|
-
"json": "1",
|
|
12
|
-
"engine": engine,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
# 2. 处理查询关键词 (Yandex 用 text,其他用 q)
|
|
16
|
-
if engine == "yandex":
|
|
17
|
-
payload["text"] = query
|
|
18
|
-
# 如果用户没传 url,给个默认的
|
|
19
|
-
if "url" not in kwargs:
|
|
20
|
-
payload["url"] = "yandex.com"
|
|
21
|
-
else:
|
|
22
|
-
payload["q"] = query
|
|
23
|
-
|
|
24
|
-
# 3. 处理默认 URL (如果用户没传)
|
|
25
|
-
if "url" not in kwargs:
|
|
26
|
-
defaults = {
|
|
27
|
-
"google": "google.com",
|
|
28
|
-
"bing": "bing.com",
|
|
29
|
-
"duckduckgo": "duckduckgo.com",
|
|
30
|
-
"baidu": "baidu.com"
|
|
31
|
-
}
|
|
32
|
-
if engine in defaults:
|
|
33
|
-
payload["url"] = defaults[engine]
|
|
34
|
-
|
|
35
|
-
# 4. 把用户传入的其他所有参数(比如 type="shopping", google_domain="google.co.uk")都透传进去
|
|
36
|
-
# 这样你就不用去定义那几十种类型了,用户传啥就是啥
|
|
37
|
-
for k, v in kwargs.items():
|
|
38
|
-
if k not in ["num", "engine", "q", "text"]: # 避免覆盖
|
|
39
|
-
payload[k] = v
|
|
40
|
-
|
|
41
|
-
return payload
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: thordata-sdk
|
|
3
|
-
Version: 0.2.4
|
|
4
|
-
Summary: The official Python SDK for Thordata Proxy & Scraper Infrastructure.
|
|
5
|
-
Home-page: https://github.com/Thordata/thordata-python-sdk
|
|
6
|
-
Author: Thordata Developer Team
|
|
7
|
-
Author-email: support@thordata.com
|
|
8
|
-
License: Apache License 2.0
|
|
9
|
-
Project-URL: Bug Tracker, https://github.com/Thordata/thordata-python-sdk/issues
|
|
10
|
-
Project-URL: Documentation, https://github.com/Thordata/thordata-python-sdk#readme
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
-
Classifier: Operating System :: OS Independent
|
|
20
|
-
Classifier: Topic :: Internet :: WWW/HTTP
|
|
21
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
-
Requires-Python: >=3.8
|
|
23
|
-
Description-Content-Type: text/markdown
|
|
24
|
-
License-File: LICENSE
|
|
25
|
-
Requires-Dist: requests>=2.25.0
|
|
26
|
-
Requires-Dist: aiohttp>=3.8.0
|
|
27
|
-
|
|
28
|
-
# Thordata Python SDK
|
|
29
|
-
|
|
30
|
-
<h4 align="center">
|
|
31
|
-
The Official Python Client for the Thordata Proxy Network & Web Scraper API.
|
|
32
|
-
<br>
|
|
33
|
-
<i>High-performance, async-ready, designed for AI Agents and large-scale data collection.</i>
|
|
34
|
-
</h4>
|
|
35
|
-
|
|
36
|
-
<p align="center">
|
|
37
|
-
<a href="https://pypi.org/project/thordata-sdk/"><img src="https://img.shields.io/pypi/v/thordata-sdk?color=blue" alt="PyPI version"></a>
|
|
38
|
-
<a href="https://github.com/Thordata/thordata-python-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-green" alt="License"></a>
|
|
39
|
-
<a href="https://python.org"><img src="https://img.shields.io/badge/python-3.8+-blue" alt="Python Versions"></a>
|
|
40
|
-
</p>
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## 🛠 Installation
|
|
45
|
-
|
|
46
|
-
Install via pip:
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
pip install thordata-sdk
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## ⚡ Quick Start
|
|
53
|
-
|
|
54
|
-
### 1. Proxy Usage (Simple GET Request)
|
|
55
|
-
|
|
56
|
-
**Python**
|
|
57
|
-
|
|
58
|
-
```python
|
|
59
|
-
from thordata_sdk import ThordataClient
|
|
60
|
-
|
|
61
|
-
# Initialize with your credentials from the Thordata Dashboard
|
|
62
|
-
client = ThordataClient(
|
|
63
|
-
scraper_token="YOUR_SCRAPER_TOKEN", # From "Scraping Tool Token"
|
|
64
|
-
public_token="YOUR_PUBLIC_TOKEN", # From "Public API"
|
|
65
|
-
public_key="YOUR_PUBLIC_KEY" # From "Public API"
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
# Send a request through the proxy
|
|
69
|
-
response = client.get("http://httpbin.org/ip")
|
|
70
|
-
print(response.json())
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### 2. Real-time SERP Search
|
|
74
|
-
|
|
75
|
-
**Python**
|
|
76
|
-
|
|
77
|
-
```python
|
|
78
|
-
results = client.serp_search("Thordata technology", engine="google")
|
|
79
|
-
print(f"Results found: {len(results.get('organic', []))}")
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### 3. Asynchronous Usage (High Concurrency)
|
|
83
|
-
|
|
84
|
-
**Python**
|
|
85
|
-
|
|
86
|
-
```python
|
|
87
|
-
import asyncio
|
|
88
|
-
from thordata_sdk import AsyncThordataClient
|
|
89
|
-
|
|
90
|
-
async def main():
|
|
91
|
-
async with AsyncThordataClient(scraper_token="...", public_token="...", public_key="...") as client:
|
|
92
|
-
response = await client.get("http://httpbin.org/ip")
|
|
93
|
-
print(await response.json())
|
|
94
|
-
|
|
95
|
-
asyncio.run(main())
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## ⚙️ Features Status
|
|
99
|
-
|
|
100
|
-
| Feature | Status | Description |
|
|
101
|
-
|---------|--------|-------------|
|
|
102
|
-
| Proxy Network | ✅ Stable | Synchronous & Asynchronous support via aiohttp. |
|
|
103
|
-
| SERP API | ✅ Stable | Real-time Google/Bing/Yandex search results. |
|
|
104
|
-
| Web Scraper | ✅ Stable | Async task management for scraping complex sites (e.g., YouTube). |
|
|
105
|
-
| Authentication | ✅ Secure | Dual-token system for enhanced security. |
|
|
106
|
-
|
|
107
|
-
## 📄 License
|
|
108
|
-
|
|
109
|
-
This project is licensed under the Apache License 2.0.
|
|
110
|
-
|
|
111
|
-
## 📞 Support
|
|
112
|
-
|
|
113
|
-
For technical assistance, please contact support@thordata.com or verify your tokens in the Thordata Dashboard.
|