msfabricpysdkcore 0.0.9__py3-none-any.whl → 0.0.11__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.
Files changed (33) hide show
  1. msfabricpysdkcore/admin_item.py +7 -0
  2. msfabricpysdkcore/admin_workspace.py +20 -1
  3. msfabricpysdkcore/adminapi.py +133 -7
  4. msfabricpysdkcore/auth.py +9 -6
  5. msfabricpysdkcore/client.py +5 -4
  6. msfabricpysdkcore/coreapi.py +341 -17
  7. msfabricpysdkcore/deployment_pipeline.py +240 -0
  8. msfabricpysdkcore/environment.py +209 -0
  9. msfabricpysdkcore/item.py +12 -11
  10. msfabricpysdkcore/lakehouse.py +42 -1
  11. msfabricpysdkcore/long_running_operation.py +2 -6
  12. msfabricpysdkcore/otheritems.py +122 -3
  13. msfabricpysdkcore/spark_custom_pool.py +118 -0
  14. msfabricpysdkcore/tests/test_admin_apis.py +20 -9
  15. msfabricpysdkcore/tests/test_datapipelines.py +48 -0
  16. msfabricpysdkcore/tests/test_deployment_pipeline.py +64 -0
  17. msfabricpysdkcore/tests/test_domains.py +3 -2
  18. msfabricpysdkcore/tests/test_environments.py +65 -0
  19. msfabricpysdkcore/tests/test_evenstreams.py +44 -0
  20. msfabricpysdkcore/tests/test_git.py +3 -1
  21. msfabricpysdkcore/tests/test_items_incl_lakehouse.py +81 -109
  22. msfabricpysdkcore/tests/test_jobs.py +4 -0
  23. msfabricpysdkcore/tests/test_kqldatabases.py +48 -0
  24. msfabricpysdkcore/tests/test_shortcuts.py +3 -1
  25. msfabricpysdkcore/tests/test_spark.py +91 -0
  26. msfabricpysdkcore/tests/test_workspaces_capacities.py +6 -5
  27. msfabricpysdkcore/workspace.py +358 -32
  28. {msfabricpysdkcore-0.0.9.dist-info → msfabricpysdkcore-0.0.11.dist-info}/METADATA +82 -32
  29. msfabricpysdkcore-0.0.11.dist-info/RECORD +38 -0
  30. msfabricpysdkcore-0.0.9.dist-info/RECORD +0 -29
  31. {msfabricpysdkcore-0.0.9.dist-info → msfabricpysdkcore-0.0.11.dist-info}/LICENSE +0 -0
  32. {msfabricpysdkcore-0.0.9.dist-info → msfabricpysdkcore-0.0.11.dist-info}/WHEEL +0 -0
  33. {msfabricpysdkcore-0.0.9.dist-info → msfabricpysdkcore-0.0.11.dist-info}/top_level.txt +0 -0
@@ -83,6 +83,13 @@ class AdminItem:
83
83
  def get_item_access_details(self, type=None):
84
84
  """Get the access details of the item
85
85
 
86
+ Returns:
87
+ dict: The access details of the item"""
88
+ return self.list_item_access_details(type)
89
+
90
+ def list_item_access_details(self, type=None):
91
+ """Get the access details of the item
92
+
86
93
  Returns:
87
94
  dict: The access details of the item"""
88
95
 
@@ -70,6 +70,14 @@ class AdminWorkspace:
70
70
  def get_workspace_access_details(self):
71
71
  """Get the access details of the workspace
72
72
 
73
+ Returns:
74
+ dict: The access details of the workspace
75
+ """
76
+ return self.list_workspace_access_details()
77
+
78
+ def list_workspace_access_details(self):
79
+ """Get the access details of the workspace
80
+
73
81
  Returns:
74
82
  dict: The access details of the workspace
75
83
  """
@@ -115,6 +123,17 @@ class AdminWorkspace:
115
123
  item_dict = json.loads(response.text)
116
124
  return AdminItem.from_dict(item_dict, self.auth)
117
125
 
126
+ def list_item_access_details(self, item_id, type=None):
127
+ """Get the access details of the item
128
+
129
+ Args:
130
+ item_id (str): The ID of the item
131
+ type (str): The type of the item
132
+ Returns:
133
+ dict: The access details of the item
134
+ """
135
+ return self.get_item(item_id, type).list_item_access_details()
136
+
118
137
  def get_item_access_details(self, item_id, type=None):
119
138
  """Get the access details of the item
120
139
 
@@ -124,4 +143,4 @@ class AdminWorkspace:
124
143
  Returns:
125
144
  dict: The access details of the item
126
145
  """
127
- return self.get_item(item_id, type).get_item_access_details()
146
+ return self.list_item_access_details(item_id, type)
@@ -284,13 +284,24 @@ class FabricClientAdmin(FabricClient):
284
284
  def get_workspace_access_details(self, workspace_id):
285
285
  """Get the access details of the workspace
286
286
 
287
+ Args:
288
+ workspace_id (str): The ID of the workspace
289
+ Returns:
290
+ dict: The access details of the workspace
291
+ """
292
+ print("DEPRECATED: Use list_workspace_access_details instead")
293
+ return self.list_workspace_access_details(workspace_id)
294
+
295
+ def list_workspace_access_details(self, workspace_id):
296
+ """Get the access details of the workspace
297
+
287
298
  Args:
288
299
  workspace_id (str): The ID of the workspace
289
300
  Returns:
290
301
  dict: The access details of the workspace
291
302
  """
292
303
  ws = self.get_workspace(workspace_id)
293
- return ws.get_workspace_access_details()
304
+ return ws.list_workspace_access_details()
294
305
 
295
306
  def list_workspaces(self, capacity_id = None, name=None, state=None, type=None, continuationToken = None):
296
307
  """List all workspaces
@@ -426,6 +437,15 @@ class FabricClientAdmin(FabricClient):
426
437
  def get_tenant_settings(self):
427
438
  """Get the tenant settings
428
439
 
440
+ Returns:
441
+ dict: The tenant settings
442
+ """
443
+ print("DEPRECATED: Use list_tenant_settings instead")
444
+ return self.list_tenant_settings()
445
+
446
+ def list_tenant_settings(self):
447
+ """Get the tenant settings
448
+
429
449
  Returns:
430
450
  dict: The tenant settings
431
451
  """
@@ -445,7 +465,7 @@ class FabricClientAdmin(FabricClient):
445
465
  return json.loads(response.text)
446
466
 
447
467
 
448
- def get_capacities_tenant_settings_overrides(self, continuationToken = None):
468
+ def list_capacities_tenant_settings_overrides(self, continuationToken = None):
449
469
  """Returns list of tenant setting overrides that override at the capacities
450
470
 
451
471
  Returns:
@@ -471,12 +491,35 @@ class FabricClientAdmin(FabricClient):
471
491
  overrides = resp_dict["Overrides"]
472
492
 
473
493
  if "continuationToken" in resp_dict and resp_dict["continuationToken"] is not None:
474
- overrides_next = self.get_capacities_tenant_settings_overrides(continuationToken=resp_dict["continuationToken"])
494
+ overrides_next = self.list_capacities_tenant_settings_overrides(continuationToken=resp_dict["continuationToken"])
475
495
  overrides.extend(overrides_next)
476
496
 
477
497
  return overrides
498
+
499
+ def get_capacities_tenant_settings_overrides(self):
500
+ """Returns list of tenant setting overrides that override at the capacities
501
+
502
+ Returns:
503
+ list: The capacities tenant settings overrides
504
+ """
505
+ print("DEPRECATED: Use list_capacities_tenant_settings_overrides instead")
506
+ return self.list_capacities_tenant_settings_overrides()
478
507
 
479
- def get_access_entities(self, user_id, type = None, continuationToken = None):
508
+
509
+ def get_access_entities(self, user_id, type = None):
510
+ """Get the access entities for a user
511
+
512
+ Args:
513
+ user_id (str): The ID of the user
514
+ type (str): The type of the access entity
515
+ continuationToken (str): The continuation token
516
+ Returns:
517
+ list: The list of access entities
518
+ """
519
+ print("DEPRECATED: Use list_access_entities instead")
520
+ return self.list_access_entities(user_id, type)
521
+
522
+ def list_access_entities(self, user_id, type = None, continuationToken = None):
480
523
  """Get the access entities for a user
481
524
 
482
525
  Args:
@@ -515,12 +558,12 @@ class FabricClientAdmin(FabricClient):
515
558
  access_entities = resp_dict["accessEntities"]
516
559
 
517
560
  if "continuationToken" in resp_dict and resp_dict["continuationToken"] is not None:
518
- access_entities_next = self.get_access_entities(user_id, type, continuationToken=resp_dict["continuationToken"])
561
+ access_entities_next = self.list_access_entities(user_id, type, continuationToken=resp_dict["continuationToken"])
519
562
  resp_dict["accessEntities"].extend(access_entities_next)
520
563
 
521
564
  return access_entities
522
565
 
523
- def get_item_access_details(self, workspace_id, item_id, type=None):
566
+ def list_item_access_details(self, workspace_id, item_id, type=None):
524
567
  """Get the access details of the item
525
568
 
526
569
  Args:
@@ -532,4 +575,87 @@ class FabricClientAdmin(FabricClient):
532
575
  """
533
576
  ws = self.get_workspace(workspace_id)
534
577
  item = ws.get_item(item_id, type)
535
- return item.get_item_access_details(type)
578
+ return item.list_item_access_details(type)
579
+
580
+ def get_item_access_details(self, workspace_id, item_id, type=None):
581
+ """Get the access details of the item
582
+
583
+ Args:
584
+ workspace_id (str): The ID of the workspace
585
+ item_id (str): The ID of the item
586
+ type (str): The type of the item
587
+ Returns:
588
+ dict: The access details of the item
589
+ """
590
+ print("DEPRECATED: Use list_item_access_details instead")
591
+ return self.list_item_access_details(workspace_id, item_id, type)
592
+
593
+ def bulk_set_labels(self, items, label_id, assignment_method = None, delegated_principal = None):
594
+ """Set labels in bulk"""
595
+ # POST https://api.fabric.microsoft.com/v1/admin/items/bulkSetLabels
596
+
597
+ url = "https://api.fabric.microsoft.com/v1/admin/items/bulkSetLabels"
598
+
599
+ if len(items) > 2000:
600
+ self.bulk_set_labels(items[2000:], label_id, assignment_method, delegated_principal)
601
+ items = items[:2000]
602
+
603
+ body = {
604
+ "items": items,
605
+ "labelId": label_id
606
+ }
607
+ if assignment_method:
608
+ body["assignmentMethod"] = assignment_method
609
+
610
+ if delegated_principal:
611
+ body["delegatedPrincipal"] = delegated_principal
612
+
613
+ for _ in range(10):
614
+ response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
615
+ if response.status_code == 429:
616
+ print("Too many requests, waiting 10 seconds")
617
+ sleep(10)
618
+ continue
619
+ if response.status_code not in (200, 429):
620
+ print(response.status_code)
621
+ print(response.text)
622
+ raise Exception(f"Error setting labels: {response.text}")
623
+ break
624
+
625
+ response = json.loads(response.text)
626
+ return response
627
+
628
+
629
+ def bulk_remove_labels(self, items):
630
+ """Remove labels in bulk
631
+ Args:
632
+ items (list): The list of item IDs
633
+
634
+ Returns:
635
+ dict: The response from the API"""
636
+ # POST https://api.fabric.microsoft.com/v1/admin/items/bulkRemoveLabels
637
+
638
+ url = "https://api.fabric.microsoft.com/v1/admin/items/bulkRemoveLabels"
639
+
640
+ if len(items) > 2000:
641
+ self.bulk_remove_labels(items[2000:])
642
+ items = items[:2000]
643
+
644
+ body = {
645
+ "items": items
646
+ }
647
+
648
+ for _ in range(10):
649
+ response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
650
+ if response.status_code == 429:
651
+ print("Too many requests, waiting 10 seconds")
652
+ sleep(10)
653
+ continue
654
+ if response.status_code not in (200, 429):
655
+ print(response.status_code)
656
+ print(response.text)
657
+ raise Exception(f"Error removing labels: {response.text}")
658
+ break
659
+
660
+ response = json.loads(response.text)
661
+ return response
msfabricpysdkcore/auth.py CHANGED
@@ -26,8 +26,9 @@ class FabricAuth():
26
26
  class FabricAuthClient(FabricAuth):
27
27
  """FabricAuthClient class to interact with Entra ID"""
28
28
 
29
- def __init__(self):
30
- print("Using Azure CLI for authentication")
29
+ def __init__(self, silent = False):
30
+ if not silent:
31
+ print("Using Azure CLI for authentication")
31
32
  self.auth = AzureCliCredential()
32
33
 
33
34
  def get_token(self):
@@ -38,8 +39,9 @@ class FabricAuthClient(FabricAuth):
38
39
  class FabricServicePrincipal(FabricAuth):
39
40
  """FabricServicePrincipal class to interact with Entra ID"""
40
41
 
41
- def __init__(self, tenant_id, client_id, client_secret):
42
- print("Using Service Principal for authentication")
42
+ def __init__(self, tenant_id, client_id, client_secret, silent = False):
43
+ if not silent:
44
+ print("Using Service Principal for authentication")
43
45
 
44
46
  self.tenant_id = tenant_id
45
47
  self.client_id = client_id
@@ -65,9 +67,10 @@ class FabricServicePrincipal(FabricAuth):
65
67
  class FabricSparkUtilsAuthentication(FabricAuth):
66
68
  """FabricSparkUtilsAuthentication class to interact with Entra ID"""
67
69
 
68
- def __init__(self):
70
+ def __init__(self, silent = False):
69
71
  mssparkutils.credentials.getToken("pbi")
70
- print("Using Synapse Spark Utils for authentication")
72
+ if not silent:
73
+ print("Using Synapse Spark Utils for authentication")
71
74
 
72
75
  def get_token(self):
73
76
  """Get token from Azure AD"""
@@ -6,7 +6,7 @@ from msfabricpysdkcore.auth import FabricAuthClient, FabricServicePrincipal, Fab
6
6
  class FabricClient():
7
7
  """FabricClient class to interact with Fabric API"""
8
8
 
9
- def __init__(self, tenant_id = None, client_id = None, client_secret = None) -> None:
9
+ def __init__(self, tenant_id = None, client_id = None, client_secret = None, silent=False) -> None:
10
10
  """Initialize FabricClient object"""
11
11
  self.tenant_id = tenant_id if tenant_id else os.getenv("FABRIC_TENANT_ID")
12
12
  self.client_id = client_id if client_id else os.getenv("FABRIC_CLIENT_ID")
@@ -16,10 +16,11 @@ class FabricClient():
16
16
 
17
17
  if self.client_id is None or self.client_secret is None or self.tenant_id is None:
18
18
  try:
19
- self.auth = FabricSparkUtilsAuthentication()
19
+ self.auth = FabricSparkUtilsAuthentication(silent=silent)
20
20
  except:
21
- self.auth = FabricAuthClient()
21
+ self.auth = FabricAuthClient(silent=silent)
22
22
  else:
23
23
  self.auth = FabricServicePrincipal(tenant_id = self.tenant_id,
24
24
  client_id = self.client_id,
25
- client_secret = self.client_secret)
25
+ client_secret = self.client_secret,
26
+ silent=silent)