pltr-cli 0.5.0__py3-none-any.whl → 0.5.1__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.
@@ -0,0 +1,305 @@
1
+ """
2
+ Connectivity service wrapper for Foundry SDK.
3
+ """
4
+
5
+ from typing import Any, Optional, Dict, List
6
+
7
+ from .base import BaseService
8
+
9
+
10
+ class ConnectivityService(BaseService):
11
+ """Service wrapper for Foundry connectivity operations."""
12
+
13
+ def _get_service(self) -> Any:
14
+ """Get the Foundry client for connectivity operations."""
15
+ return self.client
16
+
17
+ @property
18
+ def connections_service(self) -> Any:
19
+ """Get the connections service from the client."""
20
+ return self.client.connections
21
+
22
+ @property
23
+ def file_imports_service(self) -> Any:
24
+ """Get the file imports service from the client."""
25
+ return self.client.file_imports
26
+
27
+ @property
28
+ def table_imports_service(self) -> Any:
29
+ """Get the table imports service from the client."""
30
+ return self.client.table_imports
31
+
32
+ def list_connections(self) -> List[Dict[str, Any]]:
33
+ """
34
+ List available connections.
35
+
36
+ Returns:
37
+ List of connection information dictionaries
38
+ """
39
+ try:
40
+ connections = self.connections_service.Connection.list()
41
+ return [self._format_connection_info(conn) for conn in connections]
42
+ except Exception as e:
43
+ raise RuntimeError(f"Failed to list connections: {e}")
44
+
45
+ def get_connection(self, connection_rid: str) -> Dict[str, Any]:
46
+ """
47
+ Get information about a specific connection.
48
+
49
+ Args:
50
+ connection_rid: Connection Resource Identifier
51
+
52
+ Returns:
53
+ Connection information dictionary
54
+ """
55
+ try:
56
+ connection = self.connections_service.Connection.get(connection_rid)
57
+ return self._format_connection_info(connection)
58
+ except Exception as e:
59
+ raise RuntimeError(f"Failed to get connection {connection_rid}: {e}")
60
+
61
+ def create_file_import(
62
+ self,
63
+ connection_rid: str,
64
+ source_path: str,
65
+ target_dataset_rid: str,
66
+ import_config: Optional[Dict[str, Any]] = None,
67
+ ) -> Dict[str, Any]:
68
+ """
69
+ Create a file import via connection.
70
+
71
+ Args:
72
+ connection_rid: Connection Resource Identifier
73
+ source_path: Path to source file in the connection
74
+ target_dataset_rid: Target dataset RID
75
+ import_config: Optional import configuration
76
+
77
+ Returns:
78
+ File import information dictionary
79
+ """
80
+ try:
81
+ config = import_config or {}
82
+ file_import = self.file_imports_service.FileImport.create(
83
+ connection_rid=connection_rid,
84
+ source_path=source_path,
85
+ target_dataset_rid=target_dataset_rid,
86
+ **config,
87
+ )
88
+ return self._format_import_info(file_import)
89
+ except Exception as e:
90
+ raise RuntimeError(
91
+ f"Failed to create file import from {connection_rid}:{source_path}: {e}"
92
+ )
93
+
94
+ def get_file_import(self, import_rid: str) -> Dict[str, Any]:
95
+ """
96
+ Get information about a specific file import.
97
+
98
+ Args:
99
+ import_rid: File import Resource Identifier
100
+
101
+ Returns:
102
+ File import information dictionary
103
+ """
104
+ try:
105
+ file_import = self.file_imports_service.FileImport.get(import_rid)
106
+ return self._format_import_info(file_import)
107
+ except Exception as e:
108
+ raise RuntimeError(f"Failed to get file import {import_rid}: {e}")
109
+
110
+ def execute_file_import(self, import_rid: str) -> Dict[str, Any]:
111
+ """
112
+ Execute a file import.
113
+
114
+ Args:
115
+ import_rid: File import Resource Identifier
116
+
117
+ Returns:
118
+ Execution result information
119
+ """
120
+ try:
121
+ result = self.file_imports_service.FileImport.execute(import_rid)
122
+ return self._format_execution_result(result)
123
+ except Exception as e:
124
+ raise RuntimeError(f"Failed to execute file import {import_rid}: {e}")
125
+
126
+ def create_table_import(
127
+ self,
128
+ connection_rid: str,
129
+ source_table: str,
130
+ target_dataset_rid: str,
131
+ import_config: Optional[Dict[str, Any]] = None,
132
+ ) -> Dict[str, Any]:
133
+ """
134
+ Create a table import via connection.
135
+
136
+ Args:
137
+ connection_rid: Connection Resource Identifier
138
+ source_table: Source table name in the connection
139
+ target_dataset_rid: Target dataset RID
140
+ import_config: Optional import configuration
141
+
142
+ Returns:
143
+ Table import information dictionary
144
+ """
145
+ try:
146
+ config = import_config or {}
147
+ table_import = self.table_imports_service.TableImport.create(
148
+ connection_rid=connection_rid,
149
+ source_table=source_table,
150
+ target_dataset_rid=target_dataset_rid,
151
+ **config,
152
+ )
153
+ return self._format_import_info(table_import)
154
+ except Exception as e:
155
+ raise RuntimeError(
156
+ f"Failed to create table import from {connection_rid}:{source_table}: {e}"
157
+ )
158
+
159
+ def get_table_import(self, import_rid: str) -> Dict[str, Any]:
160
+ """
161
+ Get information about a specific table import.
162
+
163
+ Args:
164
+ import_rid: Table import Resource Identifier
165
+
166
+ Returns:
167
+ Table import information dictionary
168
+ """
169
+ try:
170
+ table_import = self.table_imports_service.TableImport.get(import_rid)
171
+ return self._format_import_info(table_import)
172
+ except Exception as e:
173
+ raise RuntimeError(f"Failed to get table import {import_rid}: {e}")
174
+
175
+ def execute_table_import(self, import_rid: str) -> Dict[str, Any]:
176
+ """
177
+ Execute a table import.
178
+
179
+ Args:
180
+ import_rid: Table import Resource Identifier
181
+
182
+ Returns:
183
+ Execution result information
184
+ """
185
+ try:
186
+ result = self.table_imports_service.TableImport.execute(import_rid)
187
+ return self._format_execution_result(result)
188
+ except Exception as e:
189
+ raise RuntimeError(f"Failed to execute table import {import_rid}: {e}")
190
+
191
+ def list_file_imports(
192
+ self, connection_rid: Optional[str] = None
193
+ ) -> List[Dict[str, Any]]:
194
+ """
195
+ List file imports, optionally filtered by connection.
196
+
197
+ Args:
198
+ connection_rid: Optional connection RID to filter by
199
+
200
+ Returns:
201
+ List of file import information dictionaries
202
+ """
203
+ try:
204
+ if connection_rid:
205
+ imports = self.file_imports_service.FileImport.list(
206
+ connection_rid=connection_rid
207
+ )
208
+ else:
209
+ imports = self.file_imports_service.FileImport.list()
210
+ return [self._format_import_info(imp) for imp in imports]
211
+ except Exception as e:
212
+ raise RuntimeError(f"Failed to list file imports: {e}")
213
+
214
+ def list_table_imports(
215
+ self, connection_rid: Optional[str] = None
216
+ ) -> List[Dict[str, Any]]:
217
+ """
218
+ List table imports, optionally filtered by connection.
219
+
220
+ Args:
221
+ connection_rid: Optional connection RID to filter by
222
+
223
+ Returns:
224
+ List of table import information dictionaries
225
+ """
226
+ try:
227
+ if connection_rid:
228
+ imports = self.table_imports_service.TableImport.list(
229
+ connection_rid=connection_rid
230
+ )
231
+ else:
232
+ imports = self.table_imports_service.TableImport.list()
233
+ return [self._format_import_info(imp) for imp in imports]
234
+ except Exception as e:
235
+ raise RuntimeError(f"Failed to list table imports: {e}")
236
+
237
+ def _format_connection_info(self, connection: Any) -> Dict[str, Any]:
238
+ """
239
+ Format connection information for display.
240
+
241
+ Args:
242
+ connection: Connection object from SDK
243
+
244
+ Returns:
245
+ Formatted connection dictionary
246
+ """
247
+ try:
248
+ return {
249
+ "rid": getattr(connection, "rid", "N/A"),
250
+ "display_name": getattr(connection, "display_name", "N/A"),
251
+ "description": getattr(connection, "description", ""),
252
+ "connection_type": getattr(connection, "connection_type", "N/A"),
253
+ "status": getattr(connection, "status", "N/A"),
254
+ "created_time": getattr(connection, "created_time", "N/A"),
255
+ "modified_time": getattr(connection, "modified_time", "N/A"),
256
+ }
257
+ except Exception:
258
+ return {"raw": str(connection)}
259
+
260
+ def _format_import_info(self, import_obj: Any) -> Dict[str, Any]:
261
+ """
262
+ Format import information for display.
263
+
264
+ Args:
265
+ import_obj: Import object from SDK
266
+
267
+ Returns:
268
+ Formatted import dictionary
269
+ """
270
+ try:
271
+ return {
272
+ "rid": getattr(import_obj, "rid", "N/A"),
273
+ "display_name": getattr(import_obj, "display_name", "N/A"),
274
+ "connection_rid": getattr(import_obj, "connection_rid", "N/A"),
275
+ "target_dataset_rid": getattr(import_obj, "target_dataset_rid", "N/A"),
276
+ "status": getattr(import_obj, "status", "N/A"),
277
+ "import_type": getattr(import_obj, "import_type", "N/A"),
278
+ "source": getattr(import_obj, "source", "N/A"),
279
+ "created_time": getattr(import_obj, "created_time", "N/A"),
280
+ "modified_time": getattr(import_obj, "modified_time", "N/A"),
281
+ }
282
+ except Exception:
283
+ return {"raw": str(import_obj)}
284
+
285
+ def _format_execution_result(self, result: Any) -> Dict[str, Any]:
286
+ """
287
+ Format execution result for display.
288
+
289
+ Args:
290
+ result: Execution result object from SDK
291
+
292
+ Returns:
293
+ Formatted result dictionary
294
+ """
295
+ try:
296
+ return {
297
+ "execution_rid": getattr(result, "execution_rid", "N/A"),
298
+ "status": getattr(result, "status", "N/A"),
299
+ "started_time": getattr(result, "started_time", "N/A"),
300
+ "completed_time": getattr(result, "completed_time", ""),
301
+ "records_processed": getattr(result, "records_processed", 0),
302
+ "errors": getattr(result, "errors", []),
303
+ }
304
+ except Exception:
305
+ return {"raw": str(result)}
pltr/services/dataset.py CHANGED
@@ -307,6 +307,211 @@ class DatasetService(BaseService):
307
307
  f"Failed to create branch '{branch_name}' for dataset {dataset_rid}: {e}"
308
308
  )
309
309
 
310
+ def create_transaction(
311
+ self, dataset_rid: str, branch: str = "master", transaction_type: str = "APPEND"
312
+ ) -> Dict[str, Any]:
313
+ """
314
+ Create a new transaction for a dataset.
315
+
316
+ Args:
317
+ dataset_rid: Dataset Resource Identifier
318
+ branch: Dataset branch name
319
+ transaction_type: Transaction type (APPEND, UPDATE, SNAPSHOT, DELETE)
320
+
321
+ Returns:
322
+ Transaction information dictionary
323
+ """
324
+ try:
325
+ # Try to use the v2 API's Dataset.create_transaction method
326
+ transaction = self.service.Dataset.create_transaction(
327
+ dataset_rid=dataset_rid,
328
+ branch=branch,
329
+ transaction_type=transaction_type,
330
+ )
331
+
332
+ return {
333
+ "transaction_rid": getattr(transaction, "rid", None),
334
+ "dataset_rid": dataset_rid,
335
+ "branch": branch,
336
+ "transaction_type": transaction_type,
337
+ "status": getattr(transaction, "status", "OPEN"),
338
+ "created_time": getattr(transaction, "created_time", None),
339
+ "created_by": getattr(transaction, "created_by", None),
340
+ }
341
+ except AttributeError:
342
+ # Fallback to service.create_transaction if available
343
+ try:
344
+ transaction = self.service.create_transaction(
345
+ dataset_rid=dataset_rid,
346
+ branch=branch,
347
+ transaction_type=transaction_type,
348
+ )
349
+ return {
350
+ "transaction_rid": getattr(transaction, "rid", None),
351
+ "dataset_rid": dataset_rid,
352
+ "branch": branch,
353
+ "transaction_type": transaction_type,
354
+ "status": getattr(transaction, "status", "OPEN"),
355
+ "created_time": getattr(transaction, "created_time", None),
356
+ "created_by": getattr(transaction, "created_by", None),
357
+ }
358
+ except Exception as e:
359
+ raise RuntimeError(
360
+ f"Failed to create transaction for dataset {dataset_rid}: {e}"
361
+ )
362
+ except Exception as e:
363
+ raise RuntimeError(
364
+ f"Failed to create transaction for dataset {dataset_rid}: {e}"
365
+ )
366
+
367
+ def commit_transaction(
368
+ self, dataset_rid: str, transaction_rid: str
369
+ ) -> Dict[str, Any]:
370
+ """
371
+ Commit an open transaction.
372
+
373
+ Args:
374
+ dataset_rid: Dataset Resource Identifier
375
+ transaction_rid: Transaction Resource Identifier
376
+
377
+ Returns:
378
+ Transaction commit result
379
+ """
380
+ try:
381
+ # Try the v2 API first (Dataset.commit_transaction)
382
+ self.service.Dataset.commit_transaction(
383
+ dataset_rid=dataset_rid, transaction_rid=transaction_rid
384
+ )
385
+
386
+ return {
387
+ "transaction_rid": transaction_rid,
388
+ "dataset_rid": dataset_rid,
389
+ "status": "COMMITTED",
390
+ "committed_time": None, # Would need to get this from a status call
391
+ "success": True,
392
+ }
393
+ except AttributeError:
394
+ # Fallback to service.commit_transaction
395
+ try:
396
+ self.service.commit_transaction(
397
+ dataset_rid=dataset_rid, transaction_rid=transaction_rid
398
+ )
399
+ return {
400
+ "transaction_rid": transaction_rid,
401
+ "dataset_rid": dataset_rid,
402
+ "status": "COMMITTED",
403
+ "committed_time": None,
404
+ "success": True,
405
+ }
406
+ except Exception as e:
407
+ raise RuntimeError(
408
+ f"Failed to commit transaction {transaction_rid}: {e}"
409
+ )
410
+ except Exception as e:
411
+ raise RuntimeError(f"Failed to commit transaction {transaction_rid}: {e}")
412
+
413
+ def abort_transaction(
414
+ self, dataset_rid: str, transaction_rid: str
415
+ ) -> Dict[str, Any]:
416
+ """
417
+ Abort an open transaction.
418
+
419
+ Args:
420
+ dataset_rid: Dataset Resource Identifier
421
+ transaction_rid: Transaction Resource Identifier
422
+
423
+ Returns:
424
+ Transaction abort result
425
+ """
426
+ try:
427
+ # Try the v2 API first (Dataset.abort_transaction)
428
+ self.service.Dataset.abort_transaction(
429
+ dataset_rid=dataset_rid, transaction_rid=transaction_rid
430
+ )
431
+
432
+ return {
433
+ "transaction_rid": transaction_rid,
434
+ "dataset_rid": dataset_rid,
435
+ "status": "ABORTED",
436
+ "aborted_time": None, # Would need to get this from a status call
437
+ "success": True,
438
+ }
439
+ except AttributeError:
440
+ # Fallback to service.abort_transaction
441
+ try:
442
+ self.service.abort_transaction(
443
+ dataset_rid=dataset_rid, transaction_rid=transaction_rid
444
+ )
445
+ return {
446
+ "transaction_rid": transaction_rid,
447
+ "dataset_rid": dataset_rid,
448
+ "status": "ABORTED",
449
+ "aborted_time": None,
450
+ "success": True,
451
+ }
452
+ except Exception as e:
453
+ raise RuntimeError(
454
+ f"Failed to abort transaction {transaction_rid}: {e}"
455
+ )
456
+ except Exception as e:
457
+ raise RuntimeError(f"Failed to abort transaction {transaction_rid}: {e}")
458
+
459
+ def get_transaction_status(
460
+ self, dataset_rid: str, transaction_rid: str
461
+ ) -> Dict[str, Any]:
462
+ """
463
+ Get the status of a specific transaction.
464
+
465
+ Args:
466
+ dataset_rid: Dataset Resource Identifier
467
+ transaction_rid: Transaction Resource Identifier
468
+
469
+ Returns:
470
+ Transaction status information
471
+ """
472
+ try:
473
+ # Try the v2 API first (Dataset.get_transaction)
474
+ transaction = self.service.Dataset.get_transaction(
475
+ dataset_rid=dataset_rid, transaction_rid=transaction_rid
476
+ )
477
+
478
+ return {
479
+ "transaction_rid": transaction_rid,
480
+ "dataset_rid": dataset_rid,
481
+ "status": getattr(transaction, "status", None),
482
+ "transaction_type": getattr(transaction, "transaction_type", None),
483
+ "branch": getattr(transaction, "branch", None),
484
+ "created_time": getattr(transaction, "created_time", None),
485
+ "created_by": getattr(transaction, "created_by", None),
486
+ "committed_time": getattr(transaction, "committed_time", None),
487
+ "aborted_time": getattr(transaction, "aborted_time", None),
488
+ }
489
+ except AttributeError:
490
+ # Fallback to service.get_transaction
491
+ try:
492
+ transaction = self.service.get_transaction(
493
+ dataset_rid=dataset_rid, transaction_rid=transaction_rid
494
+ )
495
+ return {
496
+ "transaction_rid": transaction_rid,
497
+ "dataset_rid": dataset_rid,
498
+ "status": getattr(transaction, "status", None),
499
+ "transaction_type": getattr(transaction, "transaction_type", None),
500
+ "branch": getattr(transaction, "branch", None),
501
+ "created_time": getattr(transaction, "created_time", None),
502
+ "created_by": getattr(transaction, "created_by", None),
503
+ "committed_time": getattr(transaction, "committed_time", None),
504
+ "aborted_time": getattr(transaction, "aborted_time", None),
505
+ }
506
+ except Exception as e:
507
+ raise RuntimeError(
508
+ f"Failed to get transaction status {transaction_rid}: {e}"
509
+ )
510
+ except Exception as e:
511
+ raise RuntimeError(
512
+ f"Failed to get transaction status {transaction_rid}: {e}"
513
+ )
514
+
310
515
  def get_transactions(
311
516
  self, dataset_rid: str, branch: str = "master"
312
517
  ) -> List[Dict[str, Any]]:
@@ -321,26 +526,56 @@ class DatasetService(BaseService):
321
526
  List of transaction information dictionaries
322
527
  """
323
528
  try:
324
- # Note: This method may not be available in all SDK versions
325
- transactions = self.service.list_transactions(
529
+ # Try the v2 API first (Dataset.list_transactions)
530
+ transactions = self.service.Dataset.list_transactions(
326
531
  dataset_rid=dataset_rid, branch=branch
327
532
  )
328
533
 
329
534
  return [
330
535
  {
331
536
  "transaction_rid": getattr(transaction, "rid", None),
537
+ "status": getattr(transaction, "status", None),
538
+ "transaction_type": getattr(transaction, "transaction_type", None),
539
+ "branch": getattr(transaction, "branch", branch),
332
540
  "created_time": getattr(transaction, "created_time", None),
333
541
  "created_by": getattr(transaction, "created_by", None),
334
- "status": getattr(transaction, "status", None),
542
+ "committed_time": getattr(transaction, "committed_time", None),
543
+ "aborted_time": getattr(transaction, "aborted_time", None),
335
544
  }
336
545
  for transaction in transactions
337
546
  ]
338
547
  except AttributeError:
339
- # Method not available in this SDK version
340
- raise NotImplementedError(
341
- "Transaction listing is not supported by this SDK version. "
342
- "This feature may require a newer version of foundry-platform-python."
343
- )
548
+ # Fallback to service.list_transactions
549
+ try:
550
+ transactions = self.service.list_transactions(
551
+ dataset_rid=dataset_rid, branch=branch
552
+ )
553
+
554
+ return [
555
+ {
556
+ "transaction_rid": getattr(transaction, "rid", None),
557
+ "created_time": getattr(transaction, "created_time", None),
558
+ "created_by": getattr(transaction, "created_by", None),
559
+ "status": getattr(transaction, "status", None),
560
+ "transaction_type": getattr(
561
+ transaction, "transaction_type", None
562
+ ),
563
+ "branch": getattr(transaction, "branch", branch),
564
+ "committed_time": getattr(transaction, "committed_time", None),
565
+ "aborted_time": getattr(transaction, "aborted_time", None),
566
+ }
567
+ for transaction in transactions
568
+ ]
569
+ except AttributeError:
570
+ # Method not available in this SDK version
571
+ raise NotImplementedError(
572
+ "Transaction listing is not supported by this SDK version. "
573
+ "This feature may require a newer version of foundry-platform-python."
574
+ )
575
+ except Exception as e:
576
+ raise RuntimeError(
577
+ f"Failed to get transactions for dataset {dataset_rid}: {e}"
578
+ )
344
579
  except Exception as e:
345
580
  raise RuntimeError(
346
581
  f"Failed to get transactions for dataset {dataset_rid}: {e}"