msfabricpysdkcore 0.0.4__py3-none-any.whl → 0.0.5__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.
- msfabricpysdkcore/coreapi.py +2 -2
- msfabricpysdkcore/item.py +6 -4
- msfabricpysdkcore/job_instance.py +0 -1
- msfabricpysdkcore/lakehouse.py +0 -1
- msfabricpysdkcore/long_running_operation.py +6 -9
- msfabricpysdkcore/otheritems.py +17 -0
- msfabricpysdkcore/tests/test_items_incl_lakehouse.py +34 -0
- msfabricpysdkcore/workspace.py +116 -17
- {msfabricpysdkcore-0.0.4.dist-info → msfabricpysdkcore-0.0.5.dist-info}/METADATA +1 -1
- {msfabricpysdkcore-0.0.4.dist-info → msfabricpysdkcore-0.0.5.dist-info}/RECORD +13 -12
- {msfabricpysdkcore-0.0.4.dist-info → msfabricpysdkcore-0.0.5.dist-info}/LICENSE +0 -0
- {msfabricpysdkcore-0.0.4.dist-info → msfabricpysdkcore-0.0.5.dist-info}/WHEEL +0 -0
- {msfabricpysdkcore-0.0.4.dist-info → msfabricpysdkcore-0.0.5.dist-info}/top_level.txt +0 -0
msfabricpysdkcore/coreapi.py
CHANGED
@@ -203,10 +203,10 @@ class FabricClientCore(FabricClient):
|
|
203
203
|
ws = self.get_workspace_by_id(workspace_id)
|
204
204
|
return ws.delete_item(item_id)
|
205
205
|
|
206
|
-
def list_items(self, workspace_id):
|
206
|
+
def list_items(self, workspace_id, with_properties = False):
|
207
207
|
"""List items in a workspace"""
|
208
208
|
ws = self.get_workspace_by_id(workspace_id)
|
209
|
-
return ws.list_items()
|
209
|
+
return ws.list_items(with_properties=with_properties)
|
210
210
|
|
211
211
|
def get_item_definition(self, workspace_id, item_id):
|
212
212
|
"""Get the definition of an item"""
|
msfabricpysdkcore/item.py
CHANGED
@@ -80,7 +80,9 @@ class Item:
|
|
80
80
|
sleep(10)
|
81
81
|
continue
|
82
82
|
if response.status_code == 202:
|
83
|
-
check_long_running_operation( response.headers, self.auth)
|
83
|
+
operation_result = check_long_running_operation( response.headers, self.auth)
|
84
|
+
self.definition = operation_result['definition']
|
85
|
+
return operation_result
|
84
86
|
|
85
87
|
if response.status_code not in (200, 202, 429):
|
86
88
|
print(response.status_code)
|
@@ -88,9 +90,9 @@ class Item:
|
|
88
90
|
raise Exception(f"Error getting item definition: {response.text}")
|
89
91
|
break
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
return
|
93
|
+
resp_dict = json.loads(response.text)
|
94
|
+
self.definition = resp_dict['definition']
|
95
|
+
return resp_dict
|
94
96
|
|
95
97
|
def update(self, display_name = None, description = None):
|
96
98
|
"""Update the item"""
|
msfabricpysdkcore/lakehouse.py
CHANGED
@@ -22,13 +22,14 @@ class LongRunningOperation:
|
|
22
22
|
print("Too many requests, waiting 10 seconds")
|
23
23
|
sleep(10)
|
24
24
|
continue
|
25
|
+
if response.status_code == 400:
|
26
|
+
return None
|
25
27
|
if response.status_code not in (200, 429):
|
26
28
|
print(response.status_code)
|
27
29
|
print(response.text)
|
28
30
|
raise Exception(f"Error getting operation results: {response.text}")
|
29
31
|
break
|
30
32
|
|
31
|
-
print(json.loads(response.text))
|
32
33
|
return json.loads(response.text)
|
33
34
|
|
34
35
|
def get_operation_state(self):
|
@@ -47,7 +48,6 @@ class LongRunningOperation:
|
|
47
48
|
raise Exception(f"Error getting operation state: {response.text}")
|
48
49
|
break
|
49
50
|
|
50
|
-
print(json.loads(response.text))
|
51
51
|
return json.loads(response.text)
|
52
52
|
|
53
53
|
def wait_for_completion(self):
|
@@ -72,10 +72,7 @@ def check_long_running_operation(headers, auth):
|
|
72
72
|
if not operation_id:
|
73
73
|
print("Operation initiated, no operation id found")
|
74
74
|
return None
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
print("Operation completed")
|
80
|
-
lro = LongRunningOperation(operation_id, auth)
|
81
|
-
return lro.wait_for_completion()
|
75
|
+
lro = LongRunningOperation(operation_id=operation_id, auth=auth)
|
76
|
+
lro.wait_for_completion()
|
77
|
+
|
78
|
+
return lro.get_operation_results()
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from time import sleep
|
2
|
+
|
3
|
+
from msfabricpysdkcore.item import Item
|
4
|
+
|
5
|
+
class SparkJobDefinition(Item):
|
6
|
+
"""Class to represent a spark job definition in Microsoft Fabric"""
|
7
|
+
|
8
|
+
def __init__(self, id, display_name, type, workspace_id, auth, properties = None, definition=None, description=""):
|
9
|
+
super().__init__(id, display_name, type, workspace_id, auth, properties, definition, description)
|
10
|
+
|
11
|
+
class Warehouse(Item):
|
12
|
+
"""Class to represent a warehouse in Microsoft Fabric"""
|
13
|
+
|
14
|
+
def __init__(self, id, display_name, type, workspace_id, auth, properties = None, definition=None, description=""):
|
15
|
+
super().__init__(id, display_name, type, workspace_id, auth, properties, definition, description)
|
16
|
+
|
17
|
+
|
@@ -47,9 +47,43 @@ class TestFabricClientCore(unittest.TestCase):
|
|
47
47
|
|
48
48
|
self.assertAlmostEqual(status_code, 200)
|
49
49
|
|
50
|
+
def test_item_definition(self):
|
51
|
+
|
52
|
+
sjd = self.fc.get_item(workspace_id=self.workspace_id, item_name="blubb", item_type="SparkJobDefinition")
|
53
|
+
self.assertIsNotNone(sjd.definition)
|
54
|
+
datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
|
55
|
+
blubb2 = "blubb2" + datetime_str
|
56
|
+
blubb3 = "blubb3" + datetime_str
|
57
|
+
blubb2 = self.fc.create_item(display_name=blubb2, type="SparkJobDefinition", workspace_id=self.workspace_id,
|
58
|
+
definition=sjd.definition)
|
59
|
+
|
60
|
+
blubb3 = self.fc.create_item(display_name=blubb3, type="SparkJobDefinition", workspace_id=self.workspace_id)
|
61
|
+
|
62
|
+
blubb3 = self.fc.update_item_definition(workspace_id=self.workspace_id,
|
63
|
+
item_id=blubb3.id, definition=sjd.definition)
|
64
|
+
|
65
|
+
self.assertEqual(blubb3.definition, sjd.definition)
|
66
|
+
|
67
|
+
self.assertNotEqual(blubb2.id, sjd.id)
|
68
|
+
self.assertEqual(blubb2.definition, sjd.definition)
|
69
|
+
self.assertNotEqual(blubb2.id, blubb3.id)
|
70
|
+
|
71
|
+
blubb2.delete()
|
72
|
+
blubb3.delete()
|
73
|
+
|
74
|
+
def test_warehouse(self):
|
75
|
+
warehouse = self.fc.get_item(workspace_id=self.workspace_id, item_name="testitem20240404134030", item_type="Warehouse")
|
76
|
+
self.assertIsNotNone(warehouse.properties)
|
77
|
+
|
78
|
+
def test_spark_job_definition(self):
|
79
|
+
spark_job_definition = self.fc.get_item(workspace_id=self.workspace_id,
|
80
|
+
item_name="blubb", item_type="SparkJobDefinition")
|
81
|
+
self.assertIsNotNone(spark_job_definition.properties)
|
82
|
+
|
50
83
|
def test_lakehouse(self):
|
51
84
|
|
52
85
|
lakehouse = self.fc.get_item(workspace_id=self.workspace_id, item_name="lakehouse1", item_type="Lakehouse")
|
86
|
+
self.assertIsNotNone(lakehouse.properties)
|
53
87
|
item_id = lakehouse.id
|
54
88
|
date_str = datetime.now().strftime("%Y%m%d%H%M%S")
|
55
89
|
table_name = f"table{date_str}"
|
msfabricpysdkcore/workspace.py
CHANGED
@@ -2,7 +2,10 @@ import json
|
|
2
2
|
import requests
|
3
3
|
from time import sleep
|
4
4
|
from msfabricpysdkcore.item import Item
|
5
|
+
from msfabricpysdkcore.lakehouse import Lakehouse
|
5
6
|
from msfabricpysdkcore.long_running_operation import check_long_running_operation
|
7
|
+
from msfabricpysdkcore.otheritems import SparkJobDefinition
|
8
|
+
from msfabricpysdkcore.otheritems import Warehouse
|
6
9
|
|
7
10
|
class Workspace:
|
8
11
|
"""Class to represent a workspace in Microsoft Fabric"""
|
@@ -247,26 +250,29 @@ class Workspace:
|
|
247
250
|
item_dict = json.loads(response.text)
|
248
251
|
if item_dict is None:
|
249
252
|
print("Item not returned by API, trying to get it by name")
|
250
|
-
return self.get_item_by_name(display_name, type)
|
251
|
-
|
253
|
+
return self.get_item_by_name(display_name, type)
|
254
|
+
|
255
|
+
if item_dict["type"] == "Lakehouse":
|
256
|
+
return self.get_lakehouse(item_dict["id"])
|
257
|
+
if item_dict["type"] == "Warehouse":
|
258
|
+
return self.get_warehouse(item_dict["id"])
|
259
|
+
if item_dict["type"] == "SparkJobDefinition":
|
260
|
+
return self.get_spark_job_definition(item_dict["id"])
|
252
261
|
|
262
|
+
item_obj = Item.from_dict(item_dict, auth=self.auth)
|
263
|
+
if item_obj.type in ["Notebook", "Report", "SemanticModel"]:
|
264
|
+
item_obj.get_definition()
|
265
|
+
return item_obj
|
253
266
|
|
254
267
|
def get_item_by_name(self, item_name, item_type):
|
255
268
|
"""Get an item from a workspace by name"""
|
256
|
-
ws_items = self.list_items()
|
269
|
+
ws_items = self.list_items(with_properties=False)
|
257
270
|
for item in ws_items:
|
258
271
|
if item.display_name == item_name and item.type == item_type:
|
259
|
-
return item
|
272
|
+
return self.get_item(item.id, item_type)
|
260
273
|
|
261
|
-
|
262
|
-
|
263
|
-
"""Get an item from a workspace"""
|
264
|
-
if item_id is None and item_name is not None and item_type is not None:
|
265
|
-
return self.get_item_by_name(item_name, item_type)
|
266
|
-
elif item_id is None:
|
267
|
-
raise Exception("item_id or the combination item_name + item_type is required")
|
268
|
-
|
269
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/items/{item_id}"
|
274
|
+
|
275
|
+
def get_item_internal(self, url):
|
270
276
|
|
271
277
|
for _ in range(10):
|
272
278
|
response = requests.get(url=url, headers=self.auth.get_headers())
|
@@ -281,14 +287,103 @@ class Workspace:
|
|
281
287
|
break
|
282
288
|
|
283
289
|
item_dict = json.loads(response.text)
|
284
|
-
return
|
290
|
+
return item_dict
|
291
|
+
|
292
|
+
def get_lakehouse(self, lakehouse_id = None, lakehouse_name = None):
|
293
|
+
"""Get a lakehouse from a workspace"""
|
294
|
+
|
295
|
+
if lakehouse_id is None and lakehouse_name is not None:
|
296
|
+
return self.get_item_by_name(lakehouse_name, "Lakehouse")
|
297
|
+
elif lakehouse_id is None:
|
298
|
+
raise Exception("lakehouse_id or the lakehouse_name is required")
|
299
|
+
|
300
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/lakehouses/{lakehouse_id}"
|
301
|
+
|
302
|
+
item_dict = self.get_item_internal(url)
|
303
|
+
return Lakehouse.from_dict(item_dict, auth=self.auth)
|
304
|
+
|
305
|
+
def get_warehouse(self, warehouse_id = None, warehouse_name = None):
|
306
|
+
"""Get a warehouse from a workspace"""
|
307
|
+
if warehouse_id is None and warehouse_name is not None:
|
308
|
+
return self.get_item_by_name(warehouse_name, "Warehouse")
|
309
|
+
elif warehouse_id is None:
|
310
|
+
raise Exception("warehouse_id or the warehouse_name is required")
|
311
|
+
|
312
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/warehouses/{warehouse_id}"
|
313
|
+
|
314
|
+
item_dict = self.get_item_internal(url)
|
315
|
+
return Warehouse.from_dict(item_dict, auth=self.auth)
|
316
|
+
|
317
|
+
def get_spark_job_definition(self, spark_job_definition_id = None, spark_job_definition_name = None):
|
318
|
+
"""Get a spark job definition from a workspace"""
|
319
|
+
if spark_job_definition_id is None and spark_job_definition_name is not None:
|
320
|
+
return self.get_item_by_name(spark_job_definition_name, "SparkJobDefinition")
|
321
|
+
elif spark_job_definition_id is None:
|
322
|
+
raise Exception("spark_job_definition_id or the spark_job_definition_name is required")
|
323
|
+
|
324
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/sparkjobdefinitions/{spark_job_definition_id}"
|
325
|
+
|
326
|
+
item_dict = self.get_item_internal(url)
|
327
|
+
sjd_obj = SparkJobDefinition.from_dict(item_dict, auth=self.auth)
|
328
|
+
sjd_obj.get_definition()
|
329
|
+
return sjd_obj
|
330
|
+
|
331
|
+
def get_item(self, item_id = None, item_name = None, item_type = None):
|
332
|
+
# GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/items/{itemId}
|
333
|
+
"""Get an item from a workspace"""
|
334
|
+
if item_type:
|
335
|
+
if item_type.lower() == "lakehouse":
|
336
|
+
return self.get_lakehouse(item_id, item_name)
|
337
|
+
if item_type.lower() == "warehouse":
|
338
|
+
return self.get_warehouse(item_id, item_name)
|
339
|
+
if item_type.lower() == "sparkjobdefinition":
|
340
|
+
return self.get_spark_job_definition(item_id, item_name)
|
341
|
+
|
342
|
+
if item_id is None and item_name is not None and item_type is not None:
|
343
|
+
return self.get_item_by_name(item_name, item_type)
|
344
|
+
elif item_id is None:
|
345
|
+
raise Exception("item_id or the combination item_name + item_type is required")
|
346
|
+
|
347
|
+
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/items/{item_id}"
|
348
|
+
|
349
|
+
item_dict = self.get_item_internal(url)
|
350
|
+
if item_dict["type"] == "Lakehouse":
|
351
|
+
return self.get_lakehouse(item_dict["id"])
|
352
|
+
if item_dict["type"] == "Warehouse":
|
353
|
+
return self.get_warehouse(item_dict["id"])
|
354
|
+
if item_dict["type"] == "SparkJobDefinition":
|
355
|
+
return self.get_spark_job_definition(item_dict["id"])
|
356
|
+
|
357
|
+
|
358
|
+
item_obj = Item.from_dict(item_dict, auth=self.auth)
|
359
|
+
if item_obj.type in ["Notebook", "Report", "SemanticModel"]:
|
360
|
+
item_obj.get_definition()
|
361
|
+
return item_obj
|
362
|
+
|
285
363
|
|
286
364
|
def delete_item(self, item_id):
|
287
365
|
"""Delete an item from a workspace"""
|
288
366
|
return self.get_item(item_id).delete()
|
289
367
|
|
290
368
|
|
291
|
-
def
|
369
|
+
def get_item_object_w_properties(self, item_list):
|
370
|
+
|
371
|
+
new_item_list = []
|
372
|
+
for item in item_list:
|
373
|
+
if item["type"] == "Lakehouse":
|
374
|
+
item = self.get_lakehouse(item["id"])
|
375
|
+
elif item["type"] == "Warehouse":
|
376
|
+
item = self.get_warehouse(item["id"])
|
377
|
+
elif item["type"] == "SparkJobDefinition":
|
378
|
+
item = self.get_spark_job_definition(item["id"])
|
379
|
+
else:
|
380
|
+
item = Item.from_dict(item, auth=self.auth)
|
381
|
+
if item.type in ["Notebook", "Report", "SemanticModel"]:
|
382
|
+
item.get_definition()
|
383
|
+
new_item_list.append(item)
|
384
|
+
return new_item_list
|
385
|
+
|
386
|
+
def list_items(self, with_properties = False, continuationToken = None):
|
292
387
|
"""List items in a workspace"""
|
293
388
|
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/items"
|
294
389
|
|
@@ -309,10 +404,14 @@ class Workspace:
|
|
309
404
|
|
310
405
|
resp_dict = json.loads(response.text)
|
311
406
|
items = resp_dict["value"]
|
312
|
-
|
407
|
+
if with_properties:
|
408
|
+
items = self.get_item_object_w_properties(items)
|
409
|
+
else:
|
410
|
+
items = [Item.from_dict(item, auth=self.auth) for item in items]
|
313
411
|
|
314
412
|
if "continuationToken" in resp_dict:
|
315
|
-
item_list_next = self.list_items(
|
413
|
+
item_list_next = self.list_items(with_properties=with_properties,
|
414
|
+
continuationToken=resp_dict["continuationToken"])
|
316
415
|
items.extend(item_list_next)
|
317
416
|
|
318
417
|
return items
|
@@ -5,24 +5,25 @@ msfabricpysdkcore/adminapi.py,sha256=YzK3s-CoFkzwOXrWPxoUeXFpv16ZwNujieaZI63bhqI
|
|
5
5
|
msfabricpysdkcore/auth.py,sha256=1t5prgSg2hK7vMutif2lxHOQk_qTo3152h3FMof3y_4,1929
|
6
6
|
msfabricpysdkcore/capacity.py,sha256=Q_2-XrZtdf9F67fY0qU3D0ocEOGQq4KtIXAv9dXjQhI,1761
|
7
7
|
msfabricpysdkcore/client.py,sha256=XVa9xndx-b2f7rA8zR-9fXyon1Ig1MmSwIMNXDfUdhw,1060
|
8
|
-
msfabricpysdkcore/coreapi.py,sha256=
|
8
|
+
msfabricpysdkcore/coreapi.py,sha256=ICZzDgfI-iiT8yVwiuK3zi8hJfK6-0w7zDqqmAKHWR4,14423
|
9
9
|
msfabricpysdkcore/domain.py,sha256=i8jMJEutDRL5XuQ69woCVQEzLS_lm9uUxl4Kp3xtxHc,14722
|
10
|
-
msfabricpysdkcore/item.py,sha256=
|
11
|
-
msfabricpysdkcore/job_instance.py,sha256=
|
12
|
-
msfabricpysdkcore/lakehouse.py,sha256=
|
13
|
-
msfabricpysdkcore/long_running_operation.py,sha256=
|
10
|
+
msfabricpysdkcore/item.py,sha256=qXmcqSSKSF443sSfAAU3Yhemr6FVlDJXsEy95ThMvVg,11296
|
11
|
+
msfabricpysdkcore/job_instance.py,sha256=C9kKsV-BIJSeU6DfoTnLlg4DLp-8RYpovs0A-mKwi4o,2745
|
12
|
+
msfabricpysdkcore/lakehouse.py,sha256=7LXYNoN5kfiaUkoXOMVsa5fgDgFf-6qTHsld3OKHLDs,3928
|
13
|
+
msfabricpysdkcore/long_running_operation.py,sha256=Vy2ESejnTIt66AtSUhMDlNRb5i_E92V8lHKKjl6Xosk,2848
|
14
14
|
msfabricpysdkcore/onelakeshortcut.py,sha256=EYZfP-rl60HdCqJD1O1NXrQTgrYTIw-EWisF4hs4bTU,2102
|
15
|
-
msfabricpysdkcore/
|
15
|
+
msfabricpysdkcore/otheritems.py,sha256=K7cGb5xDppRfbfAo7CF1LoiKAB1XmD6v2769wnCAwgY,737
|
16
|
+
msfabricpysdkcore/workspace.py,sha256=_xHyi0_AddFc0SjvZ5tPdi1NE6i9MHaWNr7rrclXq8E,26160
|
16
17
|
msfabricpysdkcore/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
18
|
msfabricpysdkcore/tests/test_admin_apis.py,sha256=M-WWQBgOG03hobCEH3dTu9VkJzyFLLN-yE9A9sdsi_8,2062
|
18
19
|
msfabricpysdkcore/tests/test_domains.py,sha256=GJX5WA_pEMYzeOGB-GAml0vnnj5AZqa7akSZB-yeBeA,4649
|
19
20
|
msfabricpysdkcore/tests/test_git.py,sha256=6OERflBSYfJbdPYuHeTEtUl2ZVqiJERVY0Z1APt94_g,2398
|
20
|
-
msfabricpysdkcore/tests/test_items_incl_lakehouse.py,sha256=
|
21
|
+
msfabricpysdkcore/tests/test_items_incl_lakehouse.py,sha256=ctb4t6RmcamuoWhrplgQwMa_577USupO_As7yuoy5QA,4627
|
21
22
|
msfabricpysdkcore/tests/test_jobs.py,sha256=G3edmNO9FpRgaVnG3RR_MTtxfSTLhp05-HBKWsRNJF8,1581
|
22
23
|
msfabricpysdkcore/tests/test_shortcuts.py,sha256=2Y4R-PfzpqaD3fEsZ7gMYGCnMPZSlgsw7V4jxZHewdU,2390
|
23
24
|
msfabricpysdkcore/tests/test_workspaces_capacities.py,sha256=2VHPvZ8GnpFStgUoZ-Al3kVVVimjkAs9YG47NsFl-zo,6563
|
24
|
-
msfabricpysdkcore-0.0.
|
25
|
-
msfabricpysdkcore-0.0.
|
26
|
-
msfabricpysdkcore-0.0.
|
27
|
-
msfabricpysdkcore-0.0.
|
28
|
-
msfabricpysdkcore-0.0.
|
25
|
+
msfabricpysdkcore-0.0.5.dist-info/LICENSE,sha256=1NrGuF-zOmzbwzk3iI6lsP9koyDeKO1B0-8OD_tTvOQ,1156
|
26
|
+
msfabricpysdkcore-0.0.5.dist-info/METADATA,sha256=3FxCakoOXWzGQ9sH1Fg1-35oNj6IRynnIbifosBEDoA,16186
|
27
|
+
msfabricpysdkcore-0.0.5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
28
|
+
msfabricpysdkcore-0.0.5.dist-info/top_level.txt,sha256=3iRonu6ptDGQN4Yl6G76XGM7xbFNsskiEHW-P2gMQGY,18
|
29
|
+
msfabricpysdkcore-0.0.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|