thordata-sdk 0.6.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 CHANGED
@@ -35,7 +35,7 @@ Async Usage:
35
35
  >>> asyncio.run(main())
36
36
  """
37
37
 
38
- __version__ = "0.6.0"
38
+ __version__ = "0.8.0"
39
39
  __author__ = "Thordata Developer Team"
40
40
  __email__ = "support@thordata.com"
41
41
 
@@ -52,6 +52,7 @@ from .enums import (
52
52
  Device,
53
53
  Engine,
54
54
  GoogleSearchType,
55
+ GoogleTbm,
55
56
  OutputFormat,
56
57
  ProxyHost,
57
58
  ProxyPort,
@@ -77,14 +78,20 @@ from .exceptions import (
77
78
 
78
79
  # Models
79
80
  from .models import (
81
+ CommonSettings,
80
82
  ProxyConfig,
81
83
  ProxyProduct,
84
+ ProxyServer,
85
+ ProxyUser,
86
+ ProxyUserList,
82
87
  ScraperTaskConfig,
83
88
  SerpRequest,
84
89
  StaticISPProxy,
85
90
  StickySession,
86
91
  TaskStatusResponse,
87
92
  UniversalScrapeRequest,
93
+ UsageStatistics,
94
+ VideoTaskConfig,
88
95
  )
89
96
 
90
97
  # Retry utilities
@@ -112,14 +119,21 @@ __all__ = [
112
119
  "TimeRange",
113
120
  "ProxyHost",
114
121
  "ProxyPort",
122
+ "GoogleTbm",
115
123
  # Models
116
124
  "ProxyConfig",
117
125
  "ProxyProduct",
126
+ "ProxyServer",
127
+ "ProxyUser",
128
+ "ProxyUserList",
129
+ "UsageStatistics",
118
130
  "StaticISPProxy",
119
131
  "StickySession",
120
132
  "SerpRequest",
121
133
  "UniversalScrapeRequest",
122
134
  "ScraperTaskConfig",
135
+ "CommonSettings",
136
+ "VideoTaskConfig",
123
137
  "TaskStatusResponse",
124
138
  # Exceptions
125
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 Authorization and Content-Type.
122
+ Headers dict with all required auth headers.
82
123
  """
83
124
  return {
84
- "Authorization": f"Bearer {token}",
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
+ }