thordata-sdk 0.7.0__py3-none-any.whl → 0.8.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 +13 -1
- thordata/_utils.py +66 -3
- thordata/async_client.py +787 -8
- thordata/client.py +851 -33
- thordata/enums.py +3 -3
- thordata/exceptions.py +16 -5
- thordata/models.py +294 -0
- thordata/retry.py +4 -1
- thordata_sdk-0.8.0.dist-info/METADATA +212 -0
- thordata_sdk-0.8.0.dist-info/RECORD +14 -0
- thordata/parameters.py +0 -53
- thordata_sdk-0.7.0.dist-info/METADATA +0 -1053
- thordata_sdk-0.7.0.dist-info/RECORD +0 -15
- {thordata_sdk-0.7.0.dist-info → thordata_sdk-0.8.0.dist-info}/WHEEL +0 -0
- {thordata_sdk-0.7.0.dist-info → thordata_sdk-0.8.0.dist-info}/licenses/LICENSE +0 -0
- {thordata_sdk-0.7.0.dist-info → thordata_sdk-0.8.0.dist-info}/top_level.txt +0 -0
thordata/__init__.py
CHANGED
|
@@ -35,7 +35,7 @@ Async Usage:
|
|
|
35
35
|
>>> asyncio.run(main())
|
|
36
36
|
"""
|
|
37
37
|
|
|
38
|
-
__version__ = "0.
|
|
38
|
+
__version__ = "0.8.0"
|
|
39
39
|
__author__ = "Thordata Developer Team"
|
|
40
40
|
__email__ = "support@thordata.com"
|
|
41
41
|
|
|
@@ -78,14 +78,20 @@ from .exceptions import (
|
|
|
78
78
|
|
|
79
79
|
# Models
|
|
80
80
|
from .models import (
|
|
81
|
+
CommonSettings,
|
|
81
82
|
ProxyConfig,
|
|
82
83
|
ProxyProduct,
|
|
84
|
+
ProxyServer,
|
|
85
|
+
ProxyUser,
|
|
86
|
+
ProxyUserList,
|
|
83
87
|
ScraperTaskConfig,
|
|
84
88
|
SerpRequest,
|
|
85
89
|
StaticISPProxy,
|
|
86
90
|
StickySession,
|
|
87
91
|
TaskStatusResponse,
|
|
88
92
|
UniversalScrapeRequest,
|
|
93
|
+
UsageStatistics,
|
|
94
|
+
VideoTaskConfig,
|
|
89
95
|
)
|
|
90
96
|
|
|
91
97
|
# Retry utilities
|
|
@@ -117,11 +123,17 @@ __all__ = [
|
|
|
117
123
|
# Models
|
|
118
124
|
"ProxyConfig",
|
|
119
125
|
"ProxyProduct",
|
|
126
|
+
"ProxyServer",
|
|
127
|
+
"ProxyUser",
|
|
128
|
+
"ProxyUserList",
|
|
129
|
+
"UsageStatistics",
|
|
120
130
|
"StaticISPProxy",
|
|
121
131
|
"StickySession",
|
|
122
132
|
"SerpRequest",
|
|
123
133
|
"UniversalScrapeRequest",
|
|
124
134
|
"ScraperTaskConfig",
|
|
135
|
+
"CommonSettings",
|
|
136
|
+
"VideoTaskConfig",
|
|
125
137
|
"TaskStatusResponse",
|
|
126
138
|
# Exceptions
|
|
127
139
|
"ThordataError",
|
thordata/_utils.py
CHANGED
|
@@ -70,18 +70,61 @@ def decode_base64_image(png_str: str) -> bytes:
|
|
|
70
70
|
raise ValueError(f"Failed to decode base64 image: {e}") from e
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
def build_auth_headers(token: str) -> Dict[str, str]:
|
|
73
|
+
def build_auth_headers(token: str, mode: str = "bearer") -> Dict[str, str]:
|
|
74
74
|
"""
|
|
75
75
|
Build authorization headers for API requests.
|
|
76
76
|
|
|
77
|
+
Supports two modes:
|
|
78
|
+
- bearer: Authorization: Bearer <token> (Thordata Docs examples)
|
|
79
|
+
- header_token: token: <token> (Interface documentation)
|
|
80
|
+
|
|
77
81
|
Args:
|
|
78
82
|
token: The scraper token.
|
|
83
|
+
mode: Authentication mode ("bearer" or "header_token").
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
Headers dict with Authorization/token and Content-Type.
|
|
87
|
+
"""
|
|
88
|
+
headers = {
|
|
89
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if mode == "bearer":
|
|
93
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
94
|
+
elif mode == "header_token":
|
|
95
|
+
headers["token"] = token
|
|
96
|
+
else:
|
|
97
|
+
# Fallback to bearer for compatibility
|
|
98
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
99
|
+
|
|
100
|
+
return headers
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def build_builder_headers(
|
|
104
|
+
scraper_token: str,
|
|
105
|
+
public_token: str,
|
|
106
|
+
public_key: str,
|
|
107
|
+
) -> Dict[str, str]:
|
|
108
|
+
"""
|
|
109
|
+
Build headers for Web Scraper builder API.
|
|
110
|
+
|
|
111
|
+
Builder requires THREE auth headers per official docs:
|
|
112
|
+
- token: public token
|
|
113
|
+
- key: public key
|
|
114
|
+
- Authorization: Bearer scraper_token
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
scraper_token: The scraper API token.
|
|
118
|
+
public_token: The public API token.
|
|
119
|
+
public_key: The public API key.
|
|
79
120
|
|
|
80
121
|
Returns:
|
|
81
|
-
Headers dict with
|
|
122
|
+
Headers dict with all required auth headers.
|
|
82
123
|
"""
|
|
83
124
|
return {
|
|
84
|
-
"
|
|
125
|
+
"token": public_token,
|
|
126
|
+
"key": public_key,
|
|
127
|
+
"Authorization": f"Bearer {scraper_token}",
|
|
85
128
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
86
129
|
}
|
|
87
130
|
|
|
@@ -142,3 +185,23 @@ def build_user_agent(sdk_version: str, http_client: str) -> str:
|
|
|
142
185
|
py = platform.python_version()
|
|
143
186
|
system = platform.system()
|
|
144
187
|
return f"thordata-python-sdk/{sdk_version} (python {py}; {system}; {http_client})"
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def build_sign_headers(sign: str, api_key: str) -> Dict[str, str]:
|
|
191
|
+
"""
|
|
192
|
+
Build headers for Public API NEW (sign + apiKey authentication).
|
|
193
|
+
|
|
194
|
+
This is a different authentication system from token+key.
|
|
195
|
+
|
|
196
|
+
Args:
|
|
197
|
+
sign: The sign value from Dashboard (immutable).
|
|
198
|
+
api_key: The apiKey value from Dashboard (can be changed).
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
Headers dict with sign, apiKey, and Content-Type.
|
|
202
|
+
"""
|
|
203
|
+
return {
|
|
204
|
+
"sign": sign,
|
|
205
|
+
"apiKey": api_key,
|
|
206
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
207
|
+
}
|