polydata-client 0.1.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.
- polydata/__init__.py +4 -0
- polydata/client.py +666 -0
- polydata/common.py +320 -0
- polydata_client-0.1.0.dist-info/METADATA +129 -0
- polydata_client-0.1.0.dist-info/RECORD +9 -0
- polydata_client-0.1.0.dist-info/WHEEL +5 -0
- polydata_client-0.1.0.dist-info/licenses/LICENSE +201 -0
- polydata_client-0.1.0.dist-info/licenses/NOTICE +4 -0
- polydata_client-0.1.0.dist-info/top_level.txt +1 -0
polydata/__init__.py
ADDED
polydata/client.py
ADDED
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Dict
|
|
3
|
+
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PolydataClient:
|
|
9
|
+
"""Client for interacting with the Polydata API."""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
api_key: str,
|
|
14
|
+
base_url: str = "https://api.polydata.co/v1",
|
|
15
|
+
timeout: int = 3600,
|
|
16
|
+
):
|
|
17
|
+
self.api_key = api_key
|
|
18
|
+
self.base_url = base_url
|
|
19
|
+
self.timeout = timeout # Default 60 minutes (3600 seconds)
|
|
20
|
+
self.session = requests.Session()
|
|
21
|
+
self.session.headers.update(
|
|
22
|
+
{"Authorization": "Bearer {}".format(api_key)}
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def _handle_response(
|
|
26
|
+
self,
|
|
27
|
+
response: requests.Response,
|
|
28
|
+
success_message: str = None,
|
|
29
|
+
error_context: str = "Request",
|
|
30
|
+
) -> Dict:
|
|
31
|
+
"""
|
|
32
|
+
Handle API response with standardized error handling.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
response: The response object from requests
|
|
36
|
+
success_message: Optional message to print on success
|
|
37
|
+
error_context: Context for error message (e.g., "Create ticker")
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
Dict: Response JSON if successful
|
|
41
|
+
|
|
42
|
+
Raises:
|
|
43
|
+
Exception: If request fails (status != 200)
|
|
44
|
+
"""
|
|
45
|
+
if response.status_code == 200:
|
|
46
|
+
if success_message:
|
|
47
|
+
print(success_message)
|
|
48
|
+
return response.json() if response.text else {}
|
|
49
|
+
else:
|
|
50
|
+
raise Exception(
|
|
51
|
+
f"{error_context} failed with status "
|
|
52
|
+
f"{response.status_code}: {response.text}"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def test_connection(self) -> Dict:
|
|
56
|
+
"""
|
|
57
|
+
Test the API connection and authentication.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
Dict: Response from the API with user info.
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
Exception: If connection fails or API key is invalid
|
|
64
|
+
"""
|
|
65
|
+
response = self.session.get(f"{self.base_url}/auth/test-auth")
|
|
66
|
+
self._handle_response(
|
|
67
|
+
response,
|
|
68
|
+
success_message="✅ API key connection works.",
|
|
69
|
+
error_context="Connection test",
|
|
70
|
+
)
|
|
71
|
+
return True
|
|
72
|
+
|
|
73
|
+
def upload_data_source(
|
|
74
|
+
self,
|
|
75
|
+
file_path: str,
|
|
76
|
+
hub_schema: str,
|
|
77
|
+
table_name: str,
|
|
78
|
+
schema_path: str,
|
|
79
|
+
type: str,
|
|
80
|
+
ignore_superset_validation: bool = False,
|
|
81
|
+
explicitly_delete_view: bool = False,
|
|
82
|
+
force_cascade: bool = False,
|
|
83
|
+
) -> Dict:
|
|
84
|
+
"""
|
|
85
|
+
Upload, replace, or append data to a data source.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
file_path: Path to the CSV file
|
|
89
|
+
hub_schema: The hub schema name (e.g. fight_matrix)
|
|
90
|
+
table_name: Name for the table
|
|
91
|
+
schema_path: Path to the JSON schema file
|
|
92
|
+
type: Operation type - "create", "replace", or "append"
|
|
93
|
+
ignore_superset_validation: If True, skip superset validation
|
|
94
|
+
(only applies to replace operations)
|
|
95
|
+
explicitly_delete_view: If True, delete view before replacing
|
|
96
|
+
(only applies to replace operations)
|
|
97
|
+
force_cascade: If True, use CASCADE when dropping columns
|
|
98
|
+
(only applies to replace operations)
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
Dict: Response from the API
|
|
102
|
+
|
|
103
|
+
Raises:
|
|
104
|
+
Exception: If upload fails or invalid type specified
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
# Validate type parameter
|
|
108
|
+
valid_types = ["create", "replace", "append"]
|
|
109
|
+
if type not in valid_types:
|
|
110
|
+
raise ValueError(
|
|
111
|
+
f"Invalid type '{type}'. Must be one of: {valid_types}"
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
with open(schema_path, "r") as f:
|
|
115
|
+
table_schema = f.read()
|
|
116
|
+
|
|
117
|
+
form_data = {
|
|
118
|
+
"hub_schema": hub_schema,
|
|
119
|
+
"table_name": table_name,
|
|
120
|
+
"table_schema": table_schema,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# Only add these params for replace operations
|
|
124
|
+
if type == "replace":
|
|
125
|
+
form_data.update(
|
|
126
|
+
{
|
|
127
|
+
"ignore_superset_validation": str(
|
|
128
|
+
ignore_superset_validation
|
|
129
|
+
).lower(),
|
|
130
|
+
"explicitly_delete_view": str(
|
|
131
|
+
explicitly_delete_view
|
|
132
|
+
).lower(),
|
|
133
|
+
"force_cascade": str(force_cascade).lower(),
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# Map type to endpoint
|
|
138
|
+
endpoint_map = {
|
|
139
|
+
"create": "/data/workflows/create-data-source-from-file",
|
|
140
|
+
"replace": "/data/workflows/replace-data-source-from-file",
|
|
141
|
+
"append": "/data/workflows/append-data-source-from-file",
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
endpoint = endpoint_map[type]
|
|
145
|
+
action = type.capitalize()
|
|
146
|
+
|
|
147
|
+
file_path = Path(file_path)
|
|
148
|
+
with open(file_path, "rb") as f:
|
|
149
|
+
files = {"file": (file_path.name, f, "text/csv")}
|
|
150
|
+
response = self.session.post(
|
|
151
|
+
f"{self.base_url}{endpoint}",
|
|
152
|
+
data=form_data,
|
|
153
|
+
files=files,
|
|
154
|
+
timeout=self.timeout,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
return self._handle_response(response, error_context=action)
|
|
158
|
+
|
|
159
|
+
def create_data_app(
|
|
160
|
+
self,
|
|
161
|
+
hub_schema: str,
|
|
162
|
+
data_app_name: str,
|
|
163
|
+
data_app_title: str,
|
|
164
|
+
data_app_description: str,
|
|
165
|
+
) -> bool:
|
|
166
|
+
"""
|
|
167
|
+
Create a data app using the API endpoint.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
hub_schema: The hub schema name
|
|
171
|
+
data_app_name: Name for the data app
|
|
172
|
+
data_app_title: Title for the data app
|
|
173
|
+
data_app_description: Description of the data app
|
|
174
|
+
Returns:
|
|
175
|
+
bool: True if successful, False otherwise
|
|
176
|
+
"""
|
|
177
|
+
payload = {
|
|
178
|
+
"hub_schema": hub_schema,
|
|
179
|
+
"data_app_name": data_app_name,
|
|
180
|
+
"data_app_title": data_app_title,
|
|
181
|
+
"data_app_description": data_app_description,
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
response = self.session.post(
|
|
185
|
+
f"{self.base_url}/apps/workflows/initialize-data-app",
|
|
186
|
+
json=payload,
|
|
187
|
+
)
|
|
188
|
+
self._handle_response(
|
|
189
|
+
response,
|
|
190
|
+
success_message=f"✓ Created data app: {data_app_name}",
|
|
191
|
+
error_context=f"Create data app {data_app_name}",
|
|
192
|
+
)
|
|
193
|
+
return True
|
|
194
|
+
|
|
195
|
+
def update_data_app_page(self, app_config: dict) -> bool:
|
|
196
|
+
"""
|
|
197
|
+
Update data app page configuration using the API endpoint.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
app_config: Dictionary containing the app configuration
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
bool: True if successful, False otherwise
|
|
204
|
+
"""
|
|
205
|
+
response = self.session.patch(
|
|
206
|
+
f"{self.base_url}/apps/pages/update-data-app-page",
|
|
207
|
+
json=app_config,
|
|
208
|
+
)
|
|
209
|
+
app_name = app_config.get("data_app_name", "unknown")
|
|
210
|
+
self._handle_response(
|
|
211
|
+
response,
|
|
212
|
+
success_message=f"✓ Updated page config for: {app_name}",
|
|
213
|
+
error_context="Update page config",
|
|
214
|
+
)
|
|
215
|
+
return True
|
|
216
|
+
|
|
217
|
+
def create_data_view(
|
|
218
|
+
self, hub_schema: str, view_name: str, view_query: str
|
|
219
|
+
) -> bool:
|
|
220
|
+
"""
|
|
221
|
+
Create a data view using the API endpoint.
|
|
222
|
+
|
|
223
|
+
Args:
|
|
224
|
+
hub_schema: The hub schema name
|
|
225
|
+
view_name: Name for the view
|
|
226
|
+
view_query: SQL query for the view
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
bool: True if successful, False otherwise
|
|
230
|
+
"""
|
|
231
|
+
payload = {"view_query": view_query}
|
|
232
|
+
response = self.session.post(
|
|
233
|
+
f"{self.base_url}/data/views/{hub_schema}/{view_name}",
|
|
234
|
+
json=payload,
|
|
235
|
+
)
|
|
236
|
+
self._handle_response(
|
|
237
|
+
response,
|
|
238
|
+
success_message=f"✓ Created data view: {view_name}",
|
|
239
|
+
error_context=f"Create view {view_name}",
|
|
240
|
+
)
|
|
241
|
+
return True
|
|
242
|
+
|
|
243
|
+
def update_data_view(
|
|
244
|
+
self, hub_schema: str, view_name: str, view_query: str
|
|
245
|
+
) -> bool:
|
|
246
|
+
"""
|
|
247
|
+
Update an existing data view using the API endpoint.
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
hub_schema: The hub schema name
|
|
251
|
+
view_name: Name of the view to update
|
|
252
|
+
view_query: New SQL query for the view
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
bool: True if successful, False otherwise
|
|
256
|
+
"""
|
|
257
|
+
payload = {"view_query": view_query}
|
|
258
|
+
response = self.session.patch(
|
|
259
|
+
f"{self.base_url}/data/views/{hub_schema}/{view_name}",
|
|
260
|
+
json=payload,
|
|
261
|
+
)
|
|
262
|
+
self._handle_response(
|
|
263
|
+
response,
|
|
264
|
+
success_message=f"✓ Updated data view: {view_name}",
|
|
265
|
+
error_context=f"Update view {view_name}",
|
|
266
|
+
)
|
|
267
|
+
return True
|
|
268
|
+
|
|
269
|
+
def get_data_view(
|
|
270
|
+
self, hub_schema: str, view_name: str, include_data: bool = True
|
|
271
|
+
) -> pd.DataFrame:
|
|
272
|
+
"""
|
|
273
|
+
Get data from an existing data view and return as a pandas DataFrame.
|
|
274
|
+
|
|
275
|
+
Args:
|
|
276
|
+
hub_schema: The hub schema name
|
|
277
|
+
view_name: Name of the view to retrieve
|
|
278
|
+
include_data: Whether to include the actual data (default: True)
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
pd.DataFrame: DataFrame containing the view data
|
|
282
|
+
|
|
283
|
+
Raises:
|
|
284
|
+
Exception: If retrieval fails
|
|
285
|
+
"""
|
|
286
|
+
response = self.session.get(
|
|
287
|
+
f"{self.base_url}/data/views/{hub_schema}/{view_name}",
|
|
288
|
+
params={"include_data": include_data},
|
|
289
|
+
)
|
|
290
|
+
response_data = self._handle_response(
|
|
291
|
+
response, error_context=f"Get view {view_name}"
|
|
292
|
+
)
|
|
293
|
+
view_data = response_data.get("data", {}).get("data", [])
|
|
294
|
+
df = pd.DataFrame(view_data)
|
|
295
|
+
print(f"✓ Retrieved data view: {view_name} ({len(df)} rows)")
|
|
296
|
+
return df
|
|
297
|
+
|
|
298
|
+
def list_data_views(self, hub_schema: str) -> pd.DataFrame:
|
|
299
|
+
"""
|
|
300
|
+
List all data views for a specific hub and return as a pandas DataFrame.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
hub_schema: The hub schema name
|
|
304
|
+
|
|
305
|
+
Returns:
|
|
306
|
+
pd.DataFrame: DataFrame containing view metadata (hub_view_id, hub_id, created_by, view_name, view_query)
|
|
307
|
+
|
|
308
|
+
Raises:
|
|
309
|
+
Exception: If retrieval fails
|
|
310
|
+
""" # noqa: E501
|
|
311
|
+
response = self.session.get(f"{self.base_url}/data/views/{hub_schema}")
|
|
312
|
+
response_data = self._handle_response(
|
|
313
|
+
response, error_context=f"List views for hub {hub_schema}"
|
|
314
|
+
)
|
|
315
|
+
views_list = response_data.get("data", [])
|
|
316
|
+
df = pd.DataFrame(views_list)
|
|
317
|
+
print(f"✓ Retrieved {len(df)} data views for hub: {hub_schema}")
|
|
318
|
+
return df
|
|
319
|
+
|
|
320
|
+
def list_data_apps(self, hub_schema: str) -> pd.DataFrame:
|
|
321
|
+
"""
|
|
322
|
+
List all data apps for a specific hub and return as a pandas DataFrame.
|
|
323
|
+
|
|
324
|
+
Args:
|
|
325
|
+
hub_schema: The hub schema name
|
|
326
|
+
|
|
327
|
+
Returns:
|
|
328
|
+
pd.DataFrame: DataFrame containing data app metadata
|
|
329
|
+
|
|
330
|
+
Raises:
|
|
331
|
+
Exception: If retrieval fails
|
|
332
|
+
"""
|
|
333
|
+
response = self.session.get(
|
|
334
|
+
f"{self.base_url}/apps/dataapps/{hub_schema}"
|
|
335
|
+
)
|
|
336
|
+
response_data = self._handle_response(
|
|
337
|
+
response, error_context=f"List apps for hub {hub_schema}"
|
|
338
|
+
)
|
|
339
|
+
apps_list = response_data.get("data", [])
|
|
340
|
+
df = pd.DataFrame(apps_list)
|
|
341
|
+
print(f"✓ Retrieved {len(df)} data apps for hub: {hub_schema}")
|
|
342
|
+
return df
|
|
343
|
+
|
|
344
|
+
def update_component(
|
|
345
|
+
self, hub_schema: str, component_name: str, component_config: dict
|
|
346
|
+
) -> bool:
|
|
347
|
+
"""
|
|
348
|
+
Update an existing component using the API endpoint.
|
|
349
|
+
|
|
350
|
+
Args:
|
|
351
|
+
hub_schema: The hub schema name
|
|
352
|
+
component_name: Name of the component to update
|
|
353
|
+
component_config: Component configuration dict
|
|
354
|
+
|
|
355
|
+
Returns:
|
|
356
|
+
bool: True if successful, False otherwise
|
|
357
|
+
"""
|
|
358
|
+
import json
|
|
359
|
+
|
|
360
|
+
payload = {"component_config": json.dumps(component_config)}
|
|
361
|
+
|
|
362
|
+
response = self.session.patch(
|
|
363
|
+
f"{self.base_url}/apps/components/{hub_schema}/{component_name}",
|
|
364
|
+
json=payload,
|
|
365
|
+
)
|
|
366
|
+
self._handle_response(
|
|
367
|
+
response,
|
|
368
|
+
success_message=f"✓ Updated component: {component_name}",
|
|
369
|
+
error_context=f"Update component {component_name}",
|
|
370
|
+
)
|
|
371
|
+
return True
|
|
372
|
+
|
|
373
|
+
def create_widget(
|
|
374
|
+
self, hub_schema: str, widget_name: str, widget_config: dict
|
|
375
|
+
) -> bool:
|
|
376
|
+
"""
|
|
377
|
+
Create a new widget using the API endpoint.
|
|
378
|
+
|
|
379
|
+
Args:
|
|
380
|
+
hub_schema: The hub schema name
|
|
381
|
+
widget_name: Name for the widget
|
|
382
|
+
widget_config: Widget configuration dict
|
|
383
|
+
|
|
384
|
+
Returns:
|
|
385
|
+
bool: True if successful, False otherwise
|
|
386
|
+
"""
|
|
387
|
+
import json
|
|
388
|
+
|
|
389
|
+
payload = {"widget_config": json.dumps(widget_config)}
|
|
390
|
+
|
|
391
|
+
response = self.session.post(
|
|
392
|
+
f"{self.base_url}/apps/widgets/{hub_schema}/{widget_name}",
|
|
393
|
+
json=payload,
|
|
394
|
+
)
|
|
395
|
+
self._handle_response(
|
|
396
|
+
response,
|
|
397
|
+
success_message=f"✓ Created widget: {widget_name}",
|
|
398
|
+
error_context=f"Create widget {widget_name}",
|
|
399
|
+
)
|
|
400
|
+
return True
|
|
401
|
+
|
|
402
|
+
def update_widget(
|
|
403
|
+
self, hub_schema: str, widget_name: str, widget_config: dict
|
|
404
|
+
) -> bool:
|
|
405
|
+
"""
|
|
406
|
+
Update an existing widget using the API endpoint.
|
|
407
|
+
|
|
408
|
+
Args:
|
|
409
|
+
hub_schema: The hub schema name
|
|
410
|
+
widget_name: Name of the widget to update
|
|
411
|
+
widget_config: Widget configuration dict
|
|
412
|
+
|
|
413
|
+
Returns:
|
|
414
|
+
bool: True if successful, False otherwise
|
|
415
|
+
"""
|
|
416
|
+
import json
|
|
417
|
+
|
|
418
|
+
payload = {"widget_config": json.dumps(widget_config)}
|
|
419
|
+
|
|
420
|
+
response = self.session.patch(
|
|
421
|
+
f"{self.base_url}/apps/widgets/{hub_schema}/{widget_name}",
|
|
422
|
+
json=payload,
|
|
423
|
+
)
|
|
424
|
+
self._handle_response(
|
|
425
|
+
response,
|
|
426
|
+
success_message=f"✓ Updated widget: {widget_name}",
|
|
427
|
+
error_context=f"Update widget {widget_name}",
|
|
428
|
+
)
|
|
429
|
+
return True
|
|
430
|
+
|
|
431
|
+
def create_ticker(
|
|
432
|
+
self,
|
|
433
|
+
hub_schema: str,
|
|
434
|
+
ticker_name: str,
|
|
435
|
+
ticker_config: dict,
|
|
436
|
+
is_ticker_on_homepage: bool = False,
|
|
437
|
+
is_ticker_on_hub_homepage: bool = False,
|
|
438
|
+
data_app_name: str = None,
|
|
439
|
+
last_updated_table_name: str = None,
|
|
440
|
+
) -> bool:
|
|
441
|
+
"""
|
|
442
|
+
Create a new ticker using the API endpoint.
|
|
443
|
+
|
|
444
|
+
Args:
|
|
445
|
+
hub_schema: The hub schema name
|
|
446
|
+
ticker_name: Name for the ticker
|
|
447
|
+
ticker_config: Ticker configuration dict (required)
|
|
448
|
+
is_ticker_on_homepage: Whether to show ticker on homepage
|
|
449
|
+
(default: False)
|
|
450
|
+
is_ticker_on_hub_homepage: Whether to show ticker on hub homepage
|
|
451
|
+
(default: False)
|
|
452
|
+
data_app_name: Name of the associated data app (optional)
|
|
453
|
+
last_updated_table_name: Name of the table to check for last
|
|
454
|
+
update (optional)
|
|
455
|
+
|
|
456
|
+
Returns:
|
|
457
|
+
bool: True if successful, False otherwise
|
|
458
|
+
"""
|
|
459
|
+
payload = {
|
|
460
|
+
"ticker_config": ticker_config,
|
|
461
|
+
"is_ticker_on_homepage": is_ticker_on_homepage,
|
|
462
|
+
"is_ticker_on_hub_homepage": is_ticker_on_hub_homepage,
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if data_app_name is not None:
|
|
466
|
+
payload["data_app_name"] = data_app_name
|
|
467
|
+
if last_updated_table_name is not None:
|
|
468
|
+
payload["last_updated_table_name"] = last_updated_table_name
|
|
469
|
+
|
|
470
|
+
response = self.session.post(
|
|
471
|
+
f"{self.base_url}/apps/tickers/{hub_schema}/{ticker_name}",
|
|
472
|
+
json=payload,
|
|
473
|
+
)
|
|
474
|
+
self._handle_response(
|
|
475
|
+
response,
|
|
476
|
+
success_message=f"✓ Created ticker: {ticker_name}",
|
|
477
|
+
error_context=f"Create ticker {ticker_name}",
|
|
478
|
+
)
|
|
479
|
+
return True
|
|
480
|
+
|
|
481
|
+
def update_ticker(
|
|
482
|
+
self,
|
|
483
|
+
hub_schema: str,
|
|
484
|
+
ticker_name: str,
|
|
485
|
+
ticker_config: dict = None,
|
|
486
|
+
is_ticker_on_homepage: bool = None,
|
|
487
|
+
is_ticker_on_hub_homepage: bool = None,
|
|
488
|
+
data_app_name: str = None,
|
|
489
|
+
last_updated_table_name: str = None,
|
|
490
|
+
) -> bool:
|
|
491
|
+
"""
|
|
492
|
+
Update an existing ticker using the API endpoint.
|
|
493
|
+
|
|
494
|
+
Args:
|
|
495
|
+
hub_schema: The hub schema name
|
|
496
|
+
ticker_name: Name of the ticker to update
|
|
497
|
+
ticker_config: Ticker configuration dict (optional)
|
|
498
|
+
is_ticker_on_homepage: Whether to show ticker on homepage
|
|
499
|
+
(optional)
|
|
500
|
+
is_ticker_on_hub_homepage: Whether to show ticker on hub homepage
|
|
501
|
+
(optional)
|
|
502
|
+
data_app_name: Name of the associated data app (optional)
|
|
503
|
+
last_updated_table_name: Name of the table to check for last
|
|
504
|
+
update (optional)
|
|
505
|
+
|
|
506
|
+
Returns:
|
|
507
|
+
bool: True if successful, False otherwise
|
|
508
|
+
"""
|
|
509
|
+
payload = {}
|
|
510
|
+
|
|
511
|
+
if ticker_config is not None:
|
|
512
|
+
payload["ticker_config"] = ticker_config
|
|
513
|
+
if is_ticker_on_homepage is not None:
|
|
514
|
+
payload["is_ticker_on_homepage"] = is_ticker_on_homepage
|
|
515
|
+
if is_ticker_on_hub_homepage is not None:
|
|
516
|
+
payload["is_ticker_on_hub_homepage"] = is_ticker_on_hub_homepage
|
|
517
|
+
if data_app_name is not None:
|
|
518
|
+
payload["data_app_name"] = data_app_name
|
|
519
|
+
if last_updated_table_name is not None:
|
|
520
|
+
payload["last_updated_table_name"] = last_updated_table_name
|
|
521
|
+
|
|
522
|
+
response = self.session.patch(
|
|
523
|
+
f"{self.base_url}/apps/tickers/{hub_schema}/{ticker_name}",
|
|
524
|
+
json=payload,
|
|
525
|
+
)
|
|
526
|
+
self._handle_response(
|
|
527
|
+
response,
|
|
528
|
+
success_message=f"✓ Updated ticker: {ticker_name}",
|
|
529
|
+
error_context=f"Update ticker {ticker_name}",
|
|
530
|
+
)
|
|
531
|
+
return True
|
|
532
|
+
|
|
533
|
+
def list_tickers(self, hub_schema: str) -> pd.DataFrame:
|
|
534
|
+
"""
|
|
535
|
+
List all tickers for a specific hub and return as a pandas DataFrame.
|
|
536
|
+
|
|
537
|
+
Args:
|
|
538
|
+
hub_schema: The hub schema name
|
|
539
|
+
|
|
540
|
+
Returns:
|
|
541
|
+
pd.DataFrame: DataFrame containing ticker metadata
|
|
542
|
+
|
|
543
|
+
Raises:
|
|
544
|
+
Exception: If retrieval fails
|
|
545
|
+
"""
|
|
546
|
+
response = self.session.get(
|
|
547
|
+
f"{self.base_url}/apps/tickers/{hub_schema}"
|
|
548
|
+
)
|
|
549
|
+
response_data = self._handle_response(
|
|
550
|
+
response, error_context=f"List tickers for hub {hub_schema}"
|
|
551
|
+
)
|
|
552
|
+
tickers_list = response_data.get("data", [])
|
|
553
|
+
df = pd.DataFrame(tickers_list)
|
|
554
|
+
print(f"✓ Retrieved {len(df)} tickers for hub: {hub_schema}")
|
|
555
|
+
return df
|
|
556
|
+
|
|
557
|
+
def create_endpoint(
|
|
558
|
+
self,
|
|
559
|
+
hub_schema: str,
|
|
560
|
+
hub_view_id: int,
|
|
561
|
+
hub_endpoint_name: str,
|
|
562
|
+
subscription_plan_type_name: str = "enterprise",
|
|
563
|
+
params_config: dict = None,
|
|
564
|
+
) -> bool:
|
|
565
|
+
"""
|
|
566
|
+
Create a new hub endpoint using the API.
|
|
567
|
+
|
|
568
|
+
Args:
|
|
569
|
+
hub_schema: The hub schema name
|
|
570
|
+
hub_view_id: ID of the hub view to expose as an endpoint
|
|
571
|
+
hub_endpoint_name: Name for the endpoint
|
|
572
|
+
subscription_plan_type_name: Subscription plan type required
|
|
573
|
+
(default: "enterprise")
|
|
574
|
+
params_config: Optional configuration for query parameters and
|
|
575
|
+
allowed columns
|
|
576
|
+
|
|
577
|
+
Returns:
|
|
578
|
+
bool: True if successful, False otherwise
|
|
579
|
+
"""
|
|
580
|
+
payload = {
|
|
581
|
+
"hub_view_id": hub_view_id,
|
|
582
|
+
"hub_endpoint_name": hub_endpoint_name,
|
|
583
|
+
"subscription_plan_type_name": subscription_plan_type_name,
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if params_config is not None:
|
|
587
|
+
payload["params_config"] = params_config
|
|
588
|
+
|
|
589
|
+
response = self.session.post(
|
|
590
|
+
f"{self.base_url}/endpoints/{hub_schema}",
|
|
591
|
+
json=payload,
|
|
592
|
+
)
|
|
593
|
+
self._handle_response(
|
|
594
|
+
response,
|
|
595
|
+
success_message=f"✓ Created endpoint: {hub_endpoint_name}",
|
|
596
|
+
error_context=f"Create endpoint {hub_endpoint_name}",
|
|
597
|
+
)
|
|
598
|
+
return True
|
|
599
|
+
|
|
600
|
+
def update_endpoint(
|
|
601
|
+
self,
|
|
602
|
+
hub_schema: str,
|
|
603
|
+
hub_endpoint_name: str,
|
|
604
|
+
hub_view_id: int = None,
|
|
605
|
+
subscription_plan_type_name: str = None,
|
|
606
|
+
params_config: dict = None,
|
|
607
|
+
is_active: bool = None,
|
|
608
|
+
) -> bool:
|
|
609
|
+
"""
|
|
610
|
+
Update an existing hub endpoint using the API.
|
|
611
|
+
|
|
612
|
+
Args:
|
|
613
|
+
hub_schema: The hub schema name
|
|
614
|
+
hub_endpoint_name: Name of the endpoint to update
|
|
615
|
+
hub_view_id: New hub view ID (optional)
|
|
616
|
+
subscription_plan_type_name: New subscription plan type (optional)
|
|
617
|
+
params_config: New configuration for query parameters (optional)
|
|
618
|
+
is_active: Whether the endpoint is active (optional)
|
|
619
|
+
|
|
620
|
+
Returns:
|
|
621
|
+
bool: True if successful, False otherwise
|
|
622
|
+
"""
|
|
623
|
+
payload = {}
|
|
624
|
+
|
|
625
|
+
if hub_view_id is not None:
|
|
626
|
+
payload["hub_view_id"] = hub_view_id
|
|
627
|
+
if subscription_plan_type_name is not None:
|
|
628
|
+
payload["subscription_plan_type_name"] = subscription_plan_type_name
|
|
629
|
+
if params_config is not None:
|
|
630
|
+
payload["params_config"] = params_config
|
|
631
|
+
if is_active is not None:
|
|
632
|
+
payload["is_active"] = is_active
|
|
633
|
+
|
|
634
|
+
response = self.session.patch(
|
|
635
|
+
f"{self.base_url}/endpoints/{hub_schema}/{hub_endpoint_name}",
|
|
636
|
+
json=payload,
|
|
637
|
+
)
|
|
638
|
+
self._handle_response(
|
|
639
|
+
response,
|
|
640
|
+
success_message=f"✓ Updated endpoint: {hub_endpoint_name}",
|
|
641
|
+
error_context=f"Update endpoint {hub_endpoint_name}",
|
|
642
|
+
)
|
|
643
|
+
return True
|
|
644
|
+
|
|
645
|
+
def list_endpoints(self, hub_schema: str) -> pd.DataFrame:
|
|
646
|
+
"""
|
|
647
|
+
List all endpoints for a specific hub and return as a pandas DataFrame.
|
|
648
|
+
|
|
649
|
+
Args:
|
|
650
|
+
hub_schema: The hub schema name
|
|
651
|
+
|
|
652
|
+
Returns:
|
|
653
|
+
pd.DataFrame: DataFrame containing endpoint metadata including
|
|
654
|
+
params_config
|
|
655
|
+
|
|
656
|
+
Raises:
|
|
657
|
+
Exception: If retrieval fails
|
|
658
|
+
"""
|
|
659
|
+
response = self.session.get(f"{self.base_url}/endpoints/{hub_schema}")
|
|
660
|
+
response_data = self._handle_response(
|
|
661
|
+
response, error_context=f"List endpoints for hub {hub_schema}"
|
|
662
|
+
)
|
|
663
|
+
endpoints_list = response_data.get("data", [])
|
|
664
|
+
df = pd.DataFrame(endpoints_list)
|
|
665
|
+
print(f"✓ Retrieved {len(df)} endpoints for hub: {hub_schema}")
|
|
666
|
+
return df
|
polydata/common.py
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Common utility functions for Polydata client usage.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import tempfile
|
|
7
|
+
import time
|
|
8
|
+
from typing import Dict
|
|
9
|
+
|
|
10
|
+
import pandas as pd
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def hub_view_exists(view_name: str, hub_views_df: pd.DataFrame) -> bool:
|
|
14
|
+
"""
|
|
15
|
+
Check if a view exists in the hub.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
view_name: Full view name (schema.view_name format)
|
|
19
|
+
hub_views_df: DataFrame from client.list_data_views()
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
True if the view exists, False otherwise
|
|
23
|
+
"""
|
|
24
|
+
return view_name in hub_views_df["view_name"].values
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def create_or_update_view(
|
|
28
|
+
client,
|
|
29
|
+
hub_schema: str,
|
|
30
|
+
view_name: str,
|
|
31
|
+
view_query: str,
|
|
32
|
+
hub_views_df: pd.DataFrame,
|
|
33
|
+
):
|
|
34
|
+
"""
|
|
35
|
+
Create or update a data view based on whether it exists.
|
|
36
|
+
|
|
37
|
+
This function checks if a view already exists and calls either
|
|
38
|
+
client.create_data_view() or client.update_data_view() accordingly.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
client: PolydataClient instance
|
|
42
|
+
hub_schema: Schema name
|
|
43
|
+
view_name: View name (without schema prefix)
|
|
44
|
+
view_query: SQL query for the view
|
|
45
|
+
hub_views_df: DataFrame from client.list_data_views(hub_schema=hub_schema)
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
```python
|
|
49
|
+
from polydata import PolydataClient
|
|
50
|
+
from polydata.common import create_or_update_view
|
|
51
|
+
|
|
52
|
+
client = PolydataClient(api_key="...", base_url="...")
|
|
53
|
+
hub_views_df = client.list_data_views(hub_schema="my_schema")
|
|
54
|
+
|
|
55
|
+
create_or_update_view(
|
|
56
|
+
client=client,
|
|
57
|
+
hub_schema="my_schema",
|
|
58
|
+
view_name="my_view",
|
|
59
|
+
view_query="SELECT * FROM my_table",
|
|
60
|
+
hub_views_df=hub_views_df,
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
"""
|
|
64
|
+
full_view_name = f"{hub_schema}.{view_name}"
|
|
65
|
+
|
|
66
|
+
if hub_view_exists(full_view_name, hub_views_df):
|
|
67
|
+
client.update_data_view(
|
|
68
|
+
hub_schema=hub_schema,
|
|
69
|
+
view_name=view_name,
|
|
70
|
+
view_query=view_query,
|
|
71
|
+
)
|
|
72
|
+
else:
|
|
73
|
+
client.create_data_view(
|
|
74
|
+
hub_schema=hub_schema,
|
|
75
|
+
view_name=view_name,
|
|
76
|
+
view_query=view_query,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def ticker_exists(ticker_name: str, hub_tickers_df: pd.DataFrame) -> bool:
|
|
81
|
+
"""
|
|
82
|
+
Check if a ticker exists in the hub.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
ticker_name: Ticker name to check
|
|
86
|
+
hub_tickers_df: DataFrame from client.list_tickers()
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
True if the ticker exists, False otherwise
|
|
90
|
+
"""
|
|
91
|
+
if hub_tickers_df.empty:
|
|
92
|
+
return False
|
|
93
|
+
return ticker_name in hub_tickers_df["ticker_name"].values
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def create_or_update_ticker(
|
|
97
|
+
client,
|
|
98
|
+
hub_schema: str,
|
|
99
|
+
ticker_name: str,
|
|
100
|
+
ticker_config: dict,
|
|
101
|
+
hub_tickers_df: pd.DataFrame,
|
|
102
|
+
is_ticker_on_homepage: bool = False,
|
|
103
|
+
is_ticker_on_hub_homepage: bool = False,
|
|
104
|
+
data_app_name: str = None,
|
|
105
|
+
last_updated_table_name: str = None,
|
|
106
|
+
):
|
|
107
|
+
"""
|
|
108
|
+
Create or update a ticker based on whether it exists.
|
|
109
|
+
|
|
110
|
+
This function checks if a ticker already exists and calls either
|
|
111
|
+
client.create_ticker() or client.update_ticker() accordingly.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
client: PolydataClient instance
|
|
115
|
+
hub_schema: Schema name
|
|
116
|
+
ticker_name: Ticker name
|
|
117
|
+
ticker_config: Ticker configuration dict
|
|
118
|
+
hub_tickers_df: DataFrame from client.list_tickers()
|
|
119
|
+
is_ticker_on_homepage: Whether to show ticker on homepage
|
|
120
|
+
is_ticker_on_hub_homepage: Whether to show ticker on hub homepage
|
|
121
|
+
data_app_name: Name of the associated data app (optional)
|
|
122
|
+
last_updated_table_name: Name of the table to check for last update
|
|
123
|
+
|
|
124
|
+
Example:
|
|
125
|
+
```python
|
|
126
|
+
from polydata import PolydataClient, create_or_update_ticker
|
|
127
|
+
|
|
128
|
+
client = PolydataClient(api_key="...", base_url="...")
|
|
129
|
+
hub_tickers_df = client.list_tickers(hub_schema="my_schema")
|
|
130
|
+
|
|
131
|
+
create_or_update_ticker(
|
|
132
|
+
client=client,
|
|
133
|
+
hub_schema="my_schema",
|
|
134
|
+
ticker_name="my_ticker",
|
|
135
|
+
ticker_config={...},
|
|
136
|
+
hub_tickers_df=hub_tickers_df,
|
|
137
|
+
is_ticker_on_homepage=True,
|
|
138
|
+
data_app_name="My App",
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
"""
|
|
142
|
+
if ticker_exists(ticker_name, hub_tickers_df):
|
|
143
|
+
client.update_ticker(
|
|
144
|
+
hub_schema=hub_schema,
|
|
145
|
+
ticker_name=ticker_name,
|
|
146
|
+
ticker_config=ticker_config,
|
|
147
|
+
is_ticker_on_homepage=is_ticker_on_homepage,
|
|
148
|
+
is_ticker_on_hub_homepage=is_ticker_on_hub_homepage,
|
|
149
|
+
data_app_name=data_app_name,
|
|
150
|
+
last_updated_table_name=last_updated_table_name,
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
client.create_ticker(
|
|
154
|
+
hub_schema=hub_schema,
|
|
155
|
+
ticker_name=ticker_name,
|
|
156
|
+
ticker_config=ticker_config,
|
|
157
|
+
is_ticker_on_homepage=is_ticker_on_homepage,
|
|
158
|
+
is_ticker_on_hub_homepage=is_ticker_on_hub_homepage,
|
|
159
|
+
data_app_name=data_app_name,
|
|
160
|
+
last_updated_table_name=last_updated_table_name,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def upload_large_csv_in_batches(
|
|
165
|
+
client,
|
|
166
|
+
file_path: str,
|
|
167
|
+
hub_schema: str,
|
|
168
|
+
table_name: str,
|
|
169
|
+
schema_path: str,
|
|
170
|
+
chunk_size: int = 10000,
|
|
171
|
+
delay_between_chunks: int = 5,
|
|
172
|
+
ignore_superset_validation: bool = False,
|
|
173
|
+
explicitly_delete_view: bool = False,
|
|
174
|
+
force_cascade: bool = False,
|
|
175
|
+
) -> Dict:
|
|
176
|
+
"""
|
|
177
|
+
Upload a large CSV file in batches to avoid memory issues.
|
|
178
|
+
|
|
179
|
+
This function splits a large CSV into smaller chunks and uploads them
|
|
180
|
+
sequentially. The first chunk uses type="replace" to clear/create the
|
|
181
|
+
table, and subsequent chunks use type="append" to add more rows.
|
|
182
|
+
|
|
183
|
+
This is useful when uploading files that would exceed API memory limits
|
|
184
|
+
(typically > 50-100MB depending on server configuration).
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
client: PolydataClient instance
|
|
188
|
+
file_path: Path to the large CSV file
|
|
189
|
+
hub_schema: The hub schema name (e.g. fight_matrix)
|
|
190
|
+
table_name: Name for the table
|
|
191
|
+
schema_path: Path to the JSON schema file
|
|
192
|
+
chunk_size: Number of rows per chunk (default: 10,000)
|
|
193
|
+
delay_between_chunks: Seconds to wait between chunk uploads to allow
|
|
194
|
+
server garbage collection (default: 5). Increase for memory-constrained
|
|
195
|
+
servers. Set to 0 to disable delays.
|
|
196
|
+
ignore_superset_validation: If True, skip superset validation
|
|
197
|
+
(only applies to first/replace operation)
|
|
198
|
+
explicitly_delete_view: If True, delete view before replacing
|
|
199
|
+
(only applies to first/replace operation)
|
|
200
|
+
force_cascade: If True, use CASCADE when dropping columns
|
|
201
|
+
(only applies to first/replace operation)
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
Dict: Summary of upload results
|
|
205
|
+
|
|
206
|
+
Example:
|
|
207
|
+
```python
|
|
208
|
+
from polydata import PolydataClient
|
|
209
|
+
from polydata.common import upload_large_csv_in_batches
|
|
210
|
+
|
|
211
|
+
client = PolydataClient(api_key="...", base_url="...")
|
|
212
|
+
|
|
213
|
+
upload_large_csv_in_batches(
|
|
214
|
+
client=client,
|
|
215
|
+
file_path="/path/to/large_file.csv",
|
|
216
|
+
hub_schema="my_schema",
|
|
217
|
+
table_name="my_table",
|
|
218
|
+
schema_path="/path/to/schema.json",
|
|
219
|
+
chunk_size=10000
|
|
220
|
+
)
|
|
221
|
+
```
|
|
222
|
+
"""
|
|
223
|
+
print(f"\n📦 Starting batched upload of: {file_path}")
|
|
224
|
+
print(f" Chunk size: {chunk_size:,} rows")
|
|
225
|
+
|
|
226
|
+
# Read CSV as raw lines to preserve exact formatting
|
|
227
|
+
with open(file_path, "r") as f:
|
|
228
|
+
lines = f.readlines()
|
|
229
|
+
|
|
230
|
+
header = lines[0]
|
|
231
|
+
data_lines = lines[1:]
|
|
232
|
+
total_rows = len(data_lines)
|
|
233
|
+
num_chunks = (total_rows + chunk_size - 1) // chunk_size
|
|
234
|
+
|
|
235
|
+
print(f" Total rows: {total_rows:,}")
|
|
236
|
+
print(f" Number of chunks: {num_chunks}")
|
|
237
|
+
|
|
238
|
+
# Create temporary directory for chunk files
|
|
239
|
+
temp_dir = tempfile.mkdtemp(prefix="polydata_chunks_")
|
|
240
|
+
print(f" Temporary directory: {temp_dir}")
|
|
241
|
+
|
|
242
|
+
try:
|
|
243
|
+
for chunk_num in range(num_chunks):
|
|
244
|
+
start_row = chunk_num * chunk_size
|
|
245
|
+
end_row = min(start_row + chunk_size, total_rows)
|
|
246
|
+
chunk_lines = data_lines[start_row:end_row]
|
|
247
|
+
|
|
248
|
+
# Create temporary chunk file
|
|
249
|
+
chunk_filename = f"chunk_{chunk_num:04d}.csv"
|
|
250
|
+
chunk_path = os.path.join(temp_dir, chunk_filename)
|
|
251
|
+
|
|
252
|
+
# Write chunk preserving exact CSV format
|
|
253
|
+
with open(chunk_path, "w") as f:
|
|
254
|
+
f.write(header)
|
|
255
|
+
f.writelines(chunk_lines)
|
|
256
|
+
|
|
257
|
+
chunk_size_mb = os.path.getsize(chunk_path) / (1024 * 1024)
|
|
258
|
+
chunk_row_count = len(chunk_lines)
|
|
259
|
+
|
|
260
|
+
print(
|
|
261
|
+
f"\n 📤 Uploading chunk {chunk_num + 1}/{num_chunks} "
|
|
262
|
+
f"(rows {start_row:,}-{end_row:,}, "
|
|
263
|
+
f"{chunk_row_count:,} rows, {chunk_size_mb:.2f} MB)"
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
# First chunk: replace, rest: append
|
|
267
|
+
if chunk_num == 0:
|
|
268
|
+
client.upload_data_source(
|
|
269
|
+
file_path=chunk_path,
|
|
270
|
+
hub_schema=hub_schema,
|
|
271
|
+
table_name=table_name,
|
|
272
|
+
schema_path=schema_path,
|
|
273
|
+
type="replace",
|
|
274
|
+
ignore_superset_validation=ignore_superset_validation,
|
|
275
|
+
explicitly_delete_view=explicitly_delete_view,
|
|
276
|
+
force_cascade=force_cascade,
|
|
277
|
+
)
|
|
278
|
+
else:
|
|
279
|
+
client.upload_data_source(
|
|
280
|
+
file_path=chunk_path,
|
|
281
|
+
hub_schema=hub_schema,
|
|
282
|
+
table_name=table_name,
|
|
283
|
+
schema_path=schema_path,
|
|
284
|
+
type="append",
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
print(f" ✓ Chunk {chunk_num + 1} uploaded successfully")
|
|
288
|
+
|
|
289
|
+
# Clean up chunk file after upload
|
|
290
|
+
os.remove(chunk_path)
|
|
291
|
+
|
|
292
|
+
# Add delay between chunks to allow server garbage collection
|
|
293
|
+
# (skip delay after last chunk)
|
|
294
|
+
if delay_between_chunks > 0 and chunk_num < num_chunks - 1:
|
|
295
|
+
print(
|
|
296
|
+
f" ⏳ Waiting {delay_between_chunks}s for server "
|
|
297
|
+
f"garbage collection..."
|
|
298
|
+
)
|
|
299
|
+
time.sleep(delay_between_chunks)
|
|
300
|
+
|
|
301
|
+
finally:
|
|
302
|
+
# Clean up temporary directory
|
|
303
|
+
try:
|
|
304
|
+
os.rmdir(temp_dir)
|
|
305
|
+
print("\n 🧹 Cleaned up temporary directory")
|
|
306
|
+
except OSError:
|
|
307
|
+
print(
|
|
308
|
+
f"\n ⚠️ Could not remove temp directory: {temp_dir} "
|
|
309
|
+
f"(may contain files)"
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
print(
|
|
313
|
+
f"\n ✅ Batched upload complete: {total_rows:,} total rows uploaded"
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
"total_rows": total_rows,
|
|
318
|
+
"num_chunks": num_chunks,
|
|
319
|
+
"chunk_size": chunk_size,
|
|
320
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: polydata-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python client for Polydata API
|
|
5
|
+
Author-email: Polydata <support@polydata.co>
|
|
6
|
+
Maintainer-email: Polydata <support@polydata.co>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://polydata.co
|
|
9
|
+
Project-URL: Documentation, https://docs.polydata.co/
|
|
10
|
+
Keywords: polydata,api,client,data,data-apps,data-viz
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
License-File: NOTICE
|
|
26
|
+
Requires-Dist: requests>=2.31.0
|
|
27
|
+
Requires-Dist: pandas>=1.5.0
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# Polydata Python Client
|
|
31
|
+
|
|
32
|
+
Official Python client for the [Polydata](https://polydata.co) API.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install polydata-client
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from polydata import PolydataClient
|
|
44
|
+
|
|
45
|
+
# Initialize client with your API key
|
|
46
|
+
client = PolydataClient(api_key="pd_sk_your_api_key_here")
|
|
47
|
+
|
|
48
|
+
# Test connection
|
|
49
|
+
client.test_connection()
|
|
50
|
+
|
|
51
|
+
# Get data from a view
|
|
52
|
+
df = client.get_data_view(
|
|
53
|
+
hub_schema="my_hub",
|
|
54
|
+
view_name="my_view"
|
|
55
|
+
)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Authentication
|
|
59
|
+
|
|
60
|
+
Get your API key from your Polydata dashboard. You can pass it directly or set it as an environment variable:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
export POLYDATA_API_KEY="pd_sk_your_api_key_here"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import os
|
|
68
|
+
from polydata import PolydataClient
|
|
69
|
+
|
|
70
|
+
client = PolydataClient(api_key=os.getenv("POLYDATA_API_KEY"))
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Core Features
|
|
74
|
+
|
|
75
|
+
### Get Data
|
|
76
|
+
|
|
77
|
+
Retrieve data from a view as a pandas DataFrame:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
df = client.get_data_view(
|
|
81
|
+
hub_schema="my_hub",
|
|
82
|
+
view_name="my_view"
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Upload Data
|
|
87
|
+
|
|
88
|
+
Upload CSV data to create or update tables:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
client.upload_data_source(
|
|
92
|
+
file_path="data.csv",
|
|
93
|
+
hub_schema="my_hub",
|
|
94
|
+
table_name="my_table",
|
|
95
|
+
schema_path="schema.json",
|
|
96
|
+
type="create" # or "replace" or "append"
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Manage Views
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
# List all views
|
|
104
|
+
views = client.list_data_views(hub_schema="my_hub")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Additional Features
|
|
108
|
+
|
|
109
|
+
The client also supports:
|
|
110
|
+
|
|
111
|
+
- Data apps, pages, components, and widgets
|
|
112
|
+
- Tickers for real-time displays
|
|
113
|
+
- Custom API endpoints
|
|
114
|
+
- Batch uploads for large files
|
|
115
|
+
|
|
116
|
+
## Requirements
|
|
117
|
+
|
|
118
|
+
- Python >= 3.8
|
|
119
|
+
- requests >= 2.31.0
|
|
120
|
+
- pandas >= 1.5.0
|
|
121
|
+
|
|
122
|
+
## Links
|
|
123
|
+
|
|
124
|
+
- [Homepage](https://polydata.co)
|
|
125
|
+
- [Documentation](https://docs.polydata.co)
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
Apache License 2.0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
polydata/__init__.py,sha256=BEtkb0BKMCWA9G7M6wsq6zyzK376BOJ_JJRM1eds8Ck,125
|
|
2
|
+
polydata/client.py,sha256=c-sh3X812jXcXYjHrEm8vfyTuAfoKPr7Bb_xR3Ihb1Q,21802
|
|
3
|
+
polydata/common.py,sha256=KG5UgLjc61E4SXRexgTwrTO-zI6B-Zwb1IofcGG9l_A,10526
|
|
4
|
+
polydata_client-0.1.0.dist-info/licenses/LICENSE,sha256=RPfqTzAnWfAG4rjiQ4dnSvLSumVXV35vnchUMmiySpw,10497
|
|
5
|
+
polydata_client-0.1.0.dist-info/licenses/NOTICE,sha256=CQcX8EeU0TGCgxJykn5uQIiHq8tNfUqx1FONK3zj8LM,131
|
|
6
|
+
polydata_client-0.1.0.dist-info/METADATA,sha256=PgGV1P68W0Y1KyMR6MZYPb-ZMc0XxqjwavodJYZyI1Q,2821
|
|
7
|
+
polydata_client-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
polydata_client-0.1.0.dist-info/top_level.txt,sha256=Ocz6UylAMpuNxakKZdMihF8mlzzKaYXPMtI128RhTyw,9
|
|
9
|
+
polydata_client-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
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 files, 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 Support. 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 2026 Polydata, Inc.
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
polydata
|