msfabricpysdkcore 0.0.12__py3-none-any.whl → 0.1.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.
Files changed (45) hide show
  1. msfabricpysdkcore/admin_item.py +18 -44
  2. msfabricpysdkcore/admin_workspace.py +13 -60
  3. msfabricpysdkcore/adminapi.py +400 -429
  4. msfabricpysdkcore/client.py +115 -1
  5. msfabricpysdkcore/coreapi.py +2553 -763
  6. msfabricpysdkcore/deployment_pipeline.py +34 -146
  7. msfabricpysdkcore/domain.py +20 -219
  8. msfabricpysdkcore/environment.py +13 -171
  9. msfabricpysdkcore/item.py +63 -198
  10. msfabricpysdkcore/job_instance.py +8 -22
  11. msfabricpysdkcore/lakehouse.py +9 -118
  12. msfabricpysdkcore/long_running_operation.py +7 -37
  13. msfabricpysdkcore/onelakeshortcut.py +7 -21
  14. msfabricpysdkcore/otheritems.py +66 -91
  15. msfabricpysdkcore/spark_custom_pool.py +7 -47
  16. msfabricpysdkcore/tests/test_admin_apis.py +21 -1
  17. msfabricpysdkcore/tests/test_datapipelines.py +14 -17
  18. msfabricpysdkcore/tests/test_deployment_pipeline.py +3 -3
  19. msfabricpysdkcore/tests/test_domains.py +4 -3
  20. msfabricpysdkcore/tests/test_environments.py +51 -2
  21. msfabricpysdkcore/tests/test_evenhouses.py +48 -0
  22. msfabricpysdkcore/tests/test_evenstreams.py +1 -1
  23. msfabricpysdkcore/tests/test_external_data_shares.py +51 -0
  24. msfabricpysdkcore/tests/test_items.py +80 -0
  25. msfabricpysdkcore/tests/test_kql_queryset.py +50 -0
  26. msfabricpysdkcore/tests/test_kqldatabases.py +1 -1
  27. msfabricpysdkcore/tests/test_lakehouse.py +86 -0
  28. msfabricpysdkcore/tests/test_ml_experiments.py +48 -0
  29. msfabricpysdkcore/tests/test_ml_models.py +48 -0
  30. msfabricpysdkcore/tests/test_notebooks.py +58 -0
  31. msfabricpysdkcore/tests/test_one_lake_data_access_security.py +65 -0
  32. msfabricpysdkcore/tests/test_other_items.py +46 -0
  33. msfabricpysdkcore/tests/test_reports.py +53 -0
  34. msfabricpysdkcore/tests/test_semantic_model.py +51 -0
  35. msfabricpysdkcore/tests/test_spark.py +7 -5
  36. msfabricpysdkcore/tests/test_sparkjobdefinition.py +1 -1
  37. msfabricpysdkcore/tests/test_warehouses.py +51 -0
  38. msfabricpysdkcore/tests/test_workspaces_capacities.py +7 -4
  39. msfabricpysdkcore/workspace.py +397 -1121
  40. {msfabricpysdkcore-0.0.12.dist-info → msfabricpysdkcore-0.1.1.dist-info}/METADATA +110 -8
  41. msfabricpysdkcore-0.1.1.dist-info/RECORD +52 -0
  42. {msfabricpysdkcore-0.0.12.dist-info → msfabricpysdkcore-0.1.1.dist-info}/WHEEL +1 -1
  43. msfabricpysdkcore-0.0.12.dist-info/RECORD +0 -39
  44. {msfabricpysdkcore-0.0.12.dist-info → msfabricpysdkcore-0.1.1.dist-info}/LICENSE +0 -0
  45. {msfabricpysdkcore-0.0.12.dist-info → msfabricpysdkcore-0.1.1.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,8 @@
1
+ from abc import abstractmethod
1
2
  import os
2
3
  from time import sleep
4
+ import requests
5
+ import json
3
6
 
4
7
  from msfabricpysdkcore.auth import FabricAuthClient, FabricServicePrincipal, FabricSparkUtilsAuthentication
5
8
 
@@ -23,4 +26,115 @@ class FabricClient():
23
26
  self.auth = FabricServicePrincipal(tenant_id = self.tenant_id,
24
27
  client_id = self.client_id,
25
28
  client_secret = self.client_secret,
26
- silent=silent)
29
+ silent=silent)
30
+
31
+
32
+
33
+ def calling_routine(self, url, operation, body = None, headers=None, file_path = None, response_codes = [200], error_message = "Error",
34
+ continue_on_error_code = False, return_format = "value_json", paging = False,
35
+ wait_for_completion = True, continuation_token = None):
36
+ """Routine to make API calls
37
+ Args:
38
+ url (str): The URL of the API
39
+ operation (str): The operation to perform
40
+ body (dict): The body of the request
41
+ response_codes (list): The response codes to expect
42
+ error_message (str): The error message
43
+ continue_on_error_code (bool): Whether to continue on error code
44
+ return_format (str): The format of the return
45
+ paging (bool): Whether to paginate
46
+ wait_for_completion (bool): Whether to wait for the operation to complete
47
+ Returns:
48
+ dict: The response
49
+ """
50
+ original_url = url
51
+
52
+ if continuation_token:
53
+ last_part_url = url.split("/")[-1]
54
+ if "?" not in last_part_url:
55
+ continuation_token = f"?continuationToken={continuation_token}"
56
+ else:
57
+ continuation_token = f"&continuationToken={continuation_token}"
58
+ url = f"{url}{continuation_token}"
59
+
60
+ response_codes.append(429)
61
+ if headers is None:
62
+ headers = self.auth.get_headers()
63
+ for _ in range(10):
64
+ if operation == "GET":
65
+ response = requests.get(url=url, headers=headers)
66
+ elif operation == "PATCH":
67
+ if body is None:
68
+ response = requests.patch(url=url, headers=headers)
69
+ else:
70
+ response = requests.patch(url=url, headers=headers, json=body)
71
+ elif operation == "POST":
72
+ if body is not None:
73
+ response = requests.post(url=url, headers=headers, json=body)
74
+ elif file_path is not None:
75
+ headers.pop('Content-Type')
76
+ with open(file_path, 'rb') as f:
77
+ files = {"file": f}
78
+ response = requests.post(url=url, files=files, headers=headers)
79
+ else:
80
+ response = requests.post(url=url, headers=headers)
81
+ elif operation == "PUT":
82
+ if body is None:
83
+ response = requests.put(url=url, headers=headers)
84
+ else:
85
+ response = requests.put(url=url, headers=headers, json=body)
86
+ elif operation == "DELETE":
87
+ response = requests.delete(url=url, headers=headers)
88
+ else:
89
+ raise ValueError("Invalid operation")
90
+ if response.status_code == 429:
91
+ print("Too many requests, waiting 10 seconds")
92
+ sleep(10)
93
+ continue
94
+ elif response.status_code == 202:
95
+ if wait_for_completion:
96
+ operation_result = self.long_running_operation(response.headers)
97
+ if "operation_result" in return_format:
98
+ return operation_result
99
+ return response
100
+ elif response.status_code not in response_codes:
101
+ if continue_on_error_code:
102
+ return response
103
+ raise Exception(f"{error_message}: {response.status_code} {response.text}")
104
+ break
105
+
106
+ if paging:
107
+ resp_dict = json.loads(response.text)
108
+
109
+ if return_format in ["data", "itemEntities", "Overrides", "accessEntities", "workspaces"]:
110
+ items = resp_dict[return_format]
111
+ else:
112
+ items = resp_dict["value"]
113
+
114
+
115
+ if "continuationToken" in resp_dict and resp_dict["continuationToken"]:
116
+ continuation_token = resp_dict["continuationToken"]
117
+ items_next = self.calling_routine(url=original_url, operation=operation, body=body, headers=headers,
118
+ response_codes=response_codes,
119
+ error_message=error_message, continuation_token=continuation_token,
120
+ return_format=return_format, paging=True, wait_for_completion=wait_for_completion)
121
+ items.extend(items_next)
122
+ if "etag" in return_format:
123
+ return items, response.headers.get('ETag')
124
+ return items
125
+
126
+ if "value_json" in return_format:
127
+ resp_dict = json.loads(response.text)
128
+ if "etag" in return_format:
129
+ return resp_dict["value"], response.headers.get('ETag')
130
+ return resp_dict["value"]
131
+
132
+ if "json" in return_format:
133
+ return json.loads(response.text)
134
+
135
+ return response
136
+
137
+ @abstractmethod
138
+ def long_running_operation(self, headers):
139
+ """Long running operation"""
140
+ pass