msfabricpysdkcore 0.0.13__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 (43) hide show
  1. msfabricpysdkcore/admin_item.py +18 -44
  2. msfabricpysdkcore/admin_workspace.py +13 -60
  3. msfabricpysdkcore/adminapi.py +398 -475
  4. msfabricpysdkcore/client.py +115 -1
  5. msfabricpysdkcore/coreapi.py +2566 -821
  6. msfabricpysdkcore/deployment_pipeline.py +34 -146
  7. msfabricpysdkcore/domain.py +20 -219
  8. msfabricpysdkcore/environment.py +13 -172
  9. msfabricpysdkcore/item.py +55 -331
  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 +1 -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_items.py +80 -0
  24. msfabricpysdkcore/tests/test_kql_queryset.py +50 -0
  25. msfabricpysdkcore/tests/test_kqldatabases.py +1 -1
  26. msfabricpysdkcore/tests/test_lakehouse.py +86 -0
  27. msfabricpysdkcore/tests/test_ml_experiments.py +48 -0
  28. msfabricpysdkcore/tests/test_ml_models.py +48 -0
  29. msfabricpysdkcore/tests/test_notebooks.py +58 -0
  30. msfabricpysdkcore/tests/test_other_items.py +46 -0
  31. msfabricpysdkcore/tests/test_reports.py +53 -0
  32. msfabricpysdkcore/tests/test_semantic_model.py +51 -0
  33. msfabricpysdkcore/tests/test_spark.py +7 -5
  34. msfabricpysdkcore/tests/test_sparkjobdefinition.py +1 -1
  35. msfabricpysdkcore/tests/test_warehouses.py +51 -0
  36. msfabricpysdkcore/tests/test_workspaces_capacities.py +7 -4
  37. msfabricpysdkcore/workspace.py +397 -1163
  38. {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.1.dist-info}/METADATA +9 -8
  39. msfabricpysdkcore-0.1.1.dist-info/RECORD +52 -0
  40. {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.1.dist-info}/WHEEL +1 -1
  41. msfabricpysdkcore-0.0.13.dist-info/RECORD +0 -41
  42. {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.1.dist-info}/LICENSE +0 -0
  43. {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.1.dist-info}/top_level.txt +0 -0
@@ -1,32 +1,25 @@
1
1
  import json
2
- import requests
3
- from time import sleep
4
- from msfabricpysdkcore.item import Item
5
- from msfabricpysdkcore.lakehouse import Lakehouse
6
- from msfabricpysdkcore.environment import Environment
7
- from msfabricpysdkcore.long_running_operation import check_long_running_operation
8
- from msfabricpysdkcore.otheritems import DataPipeline, Eventstream, KQLDatabase, KQLQueryset, SparkJobDefinition
9
- from msfabricpysdkcore.otheritems import Eventhouse, MLExperiment, MLModel, Notebook, Report, SemanticModel, Warehouse
10
- from msfabricpysdkcore.spark_custom_pool import SparkCustomPool
2
+
3
+ from msfabricpysdkcore.coreapi import FabricClientCore
11
4
 
12
5
 
13
6
  class Workspace:
14
7
  """Class to represent a workspace in Microsoft Fabric"""
15
8
 
16
- def __init__(self, id, display_name, description, type, auth, capacity_id = None) -> None:
9
+ def __init__(self, id, display_name, description, type, core_client: FabricClientCore, capacity_id = None) -> None:
17
10
  self.id = id
18
11
  self.display_name = display_name
19
12
  self.description = description
20
13
  self.type = type
21
14
  self.capacity_id = capacity_id
22
15
 
23
- self.auth = auth
16
+ self.core_client = core_client
24
17
 
25
18
 
26
- def from_dict(dict, auth):
19
+ def from_dict(dict, core_client):
27
20
  """Create a Workspace object from a dictionary"""
28
21
  return Workspace(id=dict['id'], display_name=dict['displayName'], description=dict['description'], type=dict['type'], capacity_id=dict.get('capacityId', None),
29
- auth=auth)
22
+ core_client=core_client)
30
23
 
31
24
  def __str__(self) -> str:
32
25
  """Return a string representation of the workspace object"""
@@ -41,119 +34,105 @@ class Workspace:
41
34
 
42
35
  def __repr__(self) -> str:
43
36
  return self.__str__()
44
-
45
- def list_role_assignments(self, continuationToken = None):
46
- """List role assignments for the workspace"""
47
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments"
48
37
 
49
- if continuationToken:
50
- url = f"{url}?continuationToken={continuationToken}"
38
+ # General workspace operations
39
+
40
+ def add_role_assignment(self, role, principal):
41
+ """Add a role assignment to the workspace
51
42
 
52
- for _ in range(10):
53
- response = requests.get(url=url, headers=self.auth.get_headers())
54
- if response.status_code == 429:
55
- print("Too many requests, waiting 10 seconds")
56
- sleep(10)
57
- continue
58
- if response.status_code not in (200, 429):
59
- print(response.status_code)
60
- print(response.text)
61
- raise Exception(f"Error getting role assignments: {response.text}")
62
- break
63
-
64
- resp_dict = json.loads(response.text)
65
- role_assignments = resp_dict["value"]
66
-
67
- if "continuationToken" in resp_dict:
68
- role_assignments_next = self.list_role_assignments(continuationToken=resp_dict["continuationToken"])
69
- role_assignments.extend(role_assignments_next)
70
-
71
- return role_assignments
43
+ Args:
44
+ role (str): The role to assign
45
+ principal (dict): The principal to assign the role to
46
+ Returns:
47
+ int: The status code of the response
48
+ """
49
+
50
+ return self.core_client.add_workspace_role_assignment(workspace_id=self.id, role=role, principal=principal)
51
+
52
+ def assign_to_capacity(self, capacity_id, wait_for_completion=True):
53
+ """Assign the workspace to a capacity
54
+ Args:
55
+ capacity_id (str): The id of the capacity to assign the workspace to
56
+ wait_for_completion (bool): Whether to wait for the operation to complete
57
+ Returns:
58
+ int: The status code of the response
59
+ """
60
+ response = self.core_client.assign_to_capacity(workspace_id=self.id, capacity_id=capacity_id, wait_for_completion=wait_for_completion)
61
+ self.capacity_id = capacity_id
62
+ return response
72
63
 
73
64
  def delete(self):
74
- """Delete the workspace"""
75
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}"
76
-
77
- for _ in range(10):
78
- response = requests.delete(url=url, headers=self.auth.get_headers())
79
- if response.status_code == 429:
80
- print("Too many requests, waiting 10 seconds")
81
- sleep(10)
82
- continue
83
- if response.status_code not in (200, 429):
84
- print(response.status_code)
85
- print(response.text)
86
- raise Exception(f"Error deleting workspace: {response.text}")
87
- break
88
-
89
- return response.status_code
90
-
91
- # function to add workpace role assignment
92
- def add_role_assignment(self, role, principal):
93
- """Add a role assignment to the workspace"""
94
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments"
95
-
96
- payload = {
97
- 'principal': principal,
98
- 'role': role
99
- }
100
-
101
- for _ in range(10):
102
- response = requests.post(url=url, headers=self.auth.get_headers(), data=json.dumps(payload))
103
- if response.status_code == 429:
104
- print("Too many requests, waiting 10 seconds")
105
- sleep(10)
106
- continue
107
- if response.status_code not in (201, 429):
108
- print(response.status_code)
109
- print(response.text)
110
- raise Exception(f"Error adding role assignments: {response.text}")
111
- break
112
-
113
- return response.status_code
65
+ """Delete the workspace
66
+
67
+ Returns:
68
+ int: The status code of the response
69
+ """
70
+ return self.core_client.delete_workspace(workspace_id=self.id)
114
71
 
115
72
 
116
73
  def delete_role_assignment(self, workspace_role_assignment_id):
117
- """Delete a role assignment from the workspace"""
118
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments/{workspace_role_assignment_id}"
119
-
120
- for _ in range(10):
121
- response = requests.delete(url=url, headers=self.auth.get_headers())
122
- if response.status_code == 429:
123
- print("Too many requests, waiting 10 seconds")
124
- sleep(10)
125
- continue
126
- if response.status_code not in (200, 429):
127
- print(response.status_code)
128
- print(response.text)
129
- raise Exception(f"Error deleting role assignments: {response.text}")
130
- break
131
-
132
-
133
- return response.status_code
74
+ """Delete a role assignment from the workspace
75
+ Args:
76
+ workspace_role_assignment_id (str): The id of the role assignment to delete
77
+ Returns:
78
+ int: The status code of the response
79
+ """
80
+ return self.core_client.delete_workspace_role_assignment(workspace_id=self.id, workspace_role_assignment_id=workspace_role_assignment_id)
134
81
 
135
- def update(self, display_name = None, description = None):
136
- """Update the workspace"""
137
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}"
138
-
139
- body = dict()
140
- if display_name:
141
- body["displayName"] = display_name
142
- if description:
143
- body["description"] = description
82
+ def deprovision_identity(self):
83
+ """Deprovision identity for the workspace
144
84
 
85
+ Returns:
86
+ int: The status code of the response"""
87
+ return self.core_client.deprovision_identity(workspace_id=self.id)
145
88
 
146
- for _ in range(10):
147
- response = requests.patch(url=url, headers=self.auth.get_headers(), json=body)
148
- if response.status_code == 429:
149
- print("Too many requests, waiting 10 seconds")
150
- sleep(10)
151
- continue
152
- if response.status_code not in (200, 429):
153
- raise Exception(f"Error updating workspace: {response.status_code}, {response.text}")
154
- break
89
+
90
+ def get_role_assignment(self, workspace_role_assignment_id):
91
+ """Get a role assignment from the workspace
92
+ Args:
93
+ workspace_role_assignment_id (str): The id of the role assignment to get
94
+ Returns:
95
+ dict: The role assignment
96
+ """
97
+
98
+ return self.core_client.get_workspace_role_assignment(workspace_id=self.id, workspace_role_assignment_id=workspace_role_assignment_id)
99
+
100
+ def list_role_assignments(self):
101
+ """List role assignments for the workspace
102
+ Returns:
103
+ list: A list of role assignments
104
+ """
105
+ return self.core_client.list_workspace_role_assignments(workspace_id = self.id)
106
+
107
+ def provision_identity(self):
108
+ """Provision identity for the workspace
109
+ Returns:
110
+ dict: The identity
111
+ """
112
+ return self.core_client.provision_identity(workspace_id=self.id)
113
+
114
+ def unassign_from_capacity(self, wait_for_completion=False):
115
+ """Unassign the workspace from a capacity
116
+ Args:
117
+ wait_for_completion (bool): Whether to wait for the operation to complete
118
+ Returns:
119
+ int: The status code of the response
120
+ """
121
+ response_status_code = self.core_client.unassign_from_capacity(workspace_id=self.id,
122
+ wait_for_completion = wait_for_completion)
123
+ self.capacity_id = None
124
+ return response_status_code
125
+
126
+ def update(self, display_name = None, description = None):
127
+ """Update the workspace
128
+ Args:
129
+ display_name (str): The new display name for the workspace
130
+ description (str): The new description for the workspace
131
+ Returns:
132
+ Workspace: The updated workspace object
133
+ """
134
+ self.core_client.update_workspace(workspace_id=self.id, display_name=display_name, description=description)
155
135
 
156
- assert response.status_code == 200
157
136
  if display_name:
158
137
  self.display_name = display_name
159
138
  if description:
@@ -161,1071 +140,503 @@ class Workspace:
161
140
 
162
141
  return self
163
142
 
164
- def get_role_assignment(self, workspace_role_assignment_id):
165
- # GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/roleAssignments/{workspaceRoleAssignmentId}
143
+ def update_role_assignment(self, role, workspace_role_assignment_id):
144
+ """Update a role assignment in the workspace
145
+ Args:
146
+ role (str): The new role to assign
147
+ workspace_role_assignment_id (str): The id of the role assignment to update
148
+ Returns:
149
+ int: The status code of the response
150
+ """
166
151
 
167
- """Get a role assignment from the workspace"""
168
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments/{workspace_role_assignment_id}"
152
+ return self.core_client.update_workspace_role_assignment(workspace_id=self.id, role=role, workspace_role_assignment_id=workspace_role_assignment_id)
169
153
 
170
- for _ in range(10):
171
- response = requests.get(url=url, headers=self.auth.get_headers())
172
154
 
173
- if response.status_code == 429:
174
- print("Too many requests, waiting 10 seconds")
175
- sleep(10)
176
- continue
177
- if response.status_code not in (200, 429):
178
- raise Exception(f"Error getting role assignments: {response.status_code}, {response.text}")
179
- break
155
+ # External Data Shares
180
156
 
181
- return json.loads(response.text)
157
+ # create
182
158
 
183
- def update_role_assignment(self, role, workspace_role_assignment_id):
184
- """Update a role assignment in the workspace"""
185
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments/{workspace_role_assignment_id}"
186
- body = {
187
- 'role': role
188
- }
159
+ def create_external_data_share(self, item_id, paths, recipient):
160
+ return self.core_client.create_external_data_share(workspace_id=self.id, item_id=item_id, paths=paths, recipient=recipient)
189
161
 
190
- for _ in range(10):
191
- response = requests.patch(url=url, headers=self.auth.get_headers(), json=body)
192
- if response.status_code == 429:
193
- print("Too many requests, waiting 10 seconds")
194
- sleep(10)
195
- continue
196
- if response.status_code not in (200, 429):
197
- print(response.status_code)
198
- print(response.text)
199
- raise Exception(f"Error updating role assignments: {response.text}")
200
- break
201
-
202
- return response.status_code
203
-
204
- def assign_to_capacity(self, capacity_id):
205
- """Assign the workspace to a capacity"""
206
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/assignToCapacity"
207
-
208
- body = {
209
- 'capacityId': capacity_id
210
- }
162
+ # get
211
163
 
164
+ def get_external_data_share(self, item_id, external_data_share_id):
165
+ return self.core_client.get_external_data_share(workspace_id=self.id, item_id=item_id, external_data_share_id=external_data_share_id)
212
166
 
213
- for _ in range(10):
214
- response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
215
- if response.status_code == 429:
216
- print("Too many requests, waiting 10 seconds")
217
- sleep(10)
218
- continue
219
- if response.status_code == 202:
220
- check_long_running_operation( response.headers, self.auth)
221
- if response.status_code not in (202, 429):
222
- print(response.status_code)
223
- print(response.text)
224
- raise Exception(f"Error assigning capacity: {response.text}")
225
- break
226
-
227
- assert response.status_code == 202
228
- self.capacity_id = capacity_id
229
- return response.status_code
230
-
231
- def unassign_from_capacity(self):
232
- """Unassign the workspace from a capacity"""
233
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/unassignFromCapacity"
234
-
235
- for _ in range(10):
236
- response = requests.post(url=url, headers=self.auth.get_headers())
237
- if response.status_code == 429:
238
- print("Too many requests, waiting 10 seconds")
239
- sleep(10)
240
- continue
241
-
242
- if response.status_code == 202:
243
- check_long_running_operation( response.headers, self.auth)
244
- if response.status_code not in (202, 429):
245
- print(response.status_code)
246
- print(response.text)
247
- raise Exception(f"Error unassigning capacity: {response.text}")
248
- break
249
-
250
- assert response.status_code == 202
251
- self.capacity_id = None
252
- return response.status_code
253
-
254
- def provision_identity(self):
255
- # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/provisionIdentity
256
- """Provision identity for the workspace"""
257
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/provisionIdentity"
258
-
259
- for _ in range(10):
260
- response = requests.post(url=url, headers=self.auth.get_headers())
261
- if response.status_code == 429:
262
- print("Too many requests, waiting 10 seconds")
263
- sleep(10)
264
- continue
265
- if response.status_code == 202:
266
- return check_long_running_operation( response.headers, self.auth)
267
- if response.status_code not in (200, 201, 202, 429):
268
- raise Exception(f"Error provisioning identity: {response.status_code}, {response.text}")
269
- break
167
+ # list
270
168
 
271
- return response
272
-
273
- def deprovision_identity(self):
274
- # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/deprovisionIdentity
275
- """Deprovision identity for the workspace"""
276
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/deprovisionIdentity"
277
-
278
- for _ in range(10):
279
- response = requests.post(url=url, headers=self.auth.get_headers())
280
- if response.status_code == 429:
281
- print("Too many requests, waiting 10 seconds")
282
- sleep(10)
283
- continue
284
- if response.status_code == 202:
285
- return check_long_running_operation( response.headers, self.auth)
286
- if response.status_code not in (200, 201, 202, 429):
287
- raise Exception(f"Error deprovisioning identity: {response.status_code}, {response.text}")
288
- break
169
+ def list_external_data_shares_in_item(self, item_id):
170
+ return self.core_client.list_external_data_shares_in_item(workspace_id=self.id, item_id=item_id)
289
171
 
290
- return response
172
+ # revoke
291
173
 
174
+ def revoke_external_data_share(self, item_id, external_data_share_id):
175
+ return self.core_client.revoke_external_data_share(workspace_id=self.id, item_id=item_id, external_data_share_id=external_data_share_id)
292
176
 
293
- def get_item_specific(self, item_dict):
294
- if item_dict["type"] == "DataPipeline":
295
- return self.get_data_pipeline(item_dict["id"])
296
- if item_dict["type"] == "Eventstream":
297
- return self.get_eventstream(item_dict["id"])
298
- if item_dict["type"] == "Eventhouse":
299
- return self.get_eventhouse(item_dict["id"])
300
- if item_dict["type"] == "KQLDatabase":
301
- return self.get_kql_database(item_dict["id"])
302
- if item_dict["type"] == "KQLQueryset":
303
- return self.get_kql_queryset(item_dict["id"])
304
- if item_dict["type"] == "Lakehouse":
305
- return self.get_lakehouse(item_dict["id"])
306
- if item_dict["type"] == "MLExperiment":
307
- return self.get_ml_experiment(item_dict["id"])
308
- if item_dict["type"] == "MLModel":
309
- return self.get_ml_model(item_dict["id"])
310
- if item_dict["type"] == "Notebook":
311
- return self.get_notebook(item_dict["id"])
312
- if item_dict["type"] == "Report":
313
- return self.get_report(item_dict["id"])
314
- if item_dict["type"] == "SemanticModel":
315
- return self.get_semantic_model(item_dict["id"])
316
- if item_dict["type"] == "SparkJobDefinition":
317
- return self.get_spark_job_definition(item_dict["id"])
318
- if item_dict["type"] == "Warehouse":
319
- return self.get_warehouse(item_dict["id"])
320
- if item_dict["type"] == "Environment":
321
- return self.get_environment(item_dict["id"])
322
-
323
- item_obj = Item.from_dict(item_dict, auth=self.auth)
324
- return item_obj
177
+
178
+ # Item specific operations
325
179
 
326
180
  def create_item(self, display_name, type, definition = None, description = None, **kwargs):
327
181
  """Create an item in a workspace"""
328
182
 
329
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/items"
330
- body = {
331
- 'displayName': display_name,
332
- 'type': type
333
- }
334
-
335
- if definition:
336
- body['definition'] = definition
337
- if description:
338
- body['description'] = description
339
-
340
- if type in ["dataPipelines",
341
- "environments",
342
- "eventhouses",
343
- "eventstreams",
344
- "kqlDatabases",
345
- "lakehouses",
346
- "mlExperiments",
347
- "mlModels",
348
- "notebooks",
349
- "reports",
350
- "semanticModels",
351
- "sparkJobDefinitions",
352
- "warehouses"]:
353
-
354
- if type == "kqlDatabases":
355
- if "creation_payload" not in kwargs:
356
- raise Exception("creation_payload is required for KQLDatabase")
357
- body["creationPayload"] = kwargs["creation_payload"]
358
-
359
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/{type}"
360
- body.pop('type')
361
-
362
-
363
- for _ in range(10):
364
- response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
365
- if response.status_code == 429:
366
- print("Too many requests, waiting 10 seconds")
367
- sleep(10)
368
- continue
369
- if response.status_code == 202:
370
- check_long_running_operation( response.headers, self.auth)
371
- if response.status_code not in (201, 202, 429):
372
- print(response.status_code)
373
- print(response.text)
374
- raise Exception(f"Error creating item: {response.text}")
375
- break
376
-
377
- item_dict = json.loads(response.text)
378
- if item_dict is None:
379
- print("Item not returned by API, trying to get it by name")
380
- item = None
381
- i = 0
382
-
383
- type_mapping = {"dataPipelines": "DataPipeline",
384
- "environments": "Environment",
385
- "eventhouses": "Eventhouse",
386
- "eventstreams": "Eventstream",
387
- "kqlDatabases": "KQLDatabase",
388
- "lakehouses": "Lakehouse",
389
- "mlExperiments": "MLExperiment",
390
- "mlModels": "MLModel",
391
- "notebooks": "Notebook",
392
- "reports": "Report",
393
- "semanticModels": "SemanticModel",
394
- "sparkJobDefinitions": "SparkJobDefinition",
395
- "warehouses": "Warehouse"
396
- }
397
-
398
- if type in type_mapping.keys():
399
- type = type_mapping[type]
400
- while item is None and i < 12:
401
- item = self.get_item_by_name(display_name, type)
402
- if item is not None:
403
- return item
404
- print("Item not found, waiting 5 seconds")
405
- sleep(5)
406
- i += 1
407
-
408
- print("Item not found after 1 minute, returning None")
409
- return None
410
-
411
- return self.get_item_specific(item_dict)
183
+ return self.core_client.create_item(workspace_id=self.id, display_name=display_name,
184
+ type=type, definition=definition, description=description, **kwargs)
412
185
 
413
186
 
414
- def get_item_by_name(self, item_name, item_type):
415
- """Get an item from a workspace by name"""
416
- ws_items = self.list_items(with_properties=False)
417
- for item in ws_items:
418
- if item.display_name == item_name and item.type == item_type:
419
- return self.get_item(item.id, item_type)
420
-
421
-
422
- def get_item_internal(self, url):
423
-
424
- for _ in range(10):
425
- response = requests.get(url=url, headers=self.auth.get_headers())
426
- if response.status_code == 429:
427
- print("Too many requests, waiting 10 seconds")
428
- sleep(10)
429
- continue
430
- if response.status_code not in (200, 429):
431
- print(response.status_code)
432
- print(response.text)
433
- raise Exception(f"Error getting item: {response.text}")
434
- break
435
-
436
- item_dict = json.loads(response.text)
437
- return item_dict
187
+
438
188
 
439
189
  def get_item(self, item_id = None, item_name = None, item_type = None):
440
190
  # GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/items/{itemId}
441
191
  """Get an item from a workspace"""
442
- if item_type:
443
- if item_type.lower() == "datapipeline":
444
- return self.get_data_pipeline(item_id, item_name)
445
- if item_type.lower() == "eventstream":
446
- return self.get_eventstream(item_id, item_name)
447
- if item_type.lower() == "kqldatabase":
448
- return self.get_kql_database(item_id, item_name)
449
- if item_type.lower() == "kqlqueryset":
450
- return self.get_kql_queryset(item_id, item_name)
451
- if item_type.lower() == "lakehouse":
452
- return self.get_lakehouse(item_id, item_name)
453
- if item_type.lower() == "mlmodel":
454
- return self.get_ml_model(item_id, item_name)
455
- if item_type.lower() == "mlexperiment":
456
- return self.get_ml_experiment(item_id, item_name)
457
- if item_type.lower() == "notebook":
458
- return self.get_notebook(item_id, item_name)
459
- if item_type.lower() == "report":
460
- return self.get_report(item_id, item_name)
461
- if item_type.lower() == "semanticmodel":
462
- return self.get_semantic_model(item_id, item_name)
463
- if item_type.lower() == "sparkjobdefinition":
464
- return self.get_spark_job_definition(item_id, item_name)
465
- if item_type.lower() == "warehouse":
466
- return self.get_warehouse(item_id, item_name)
467
-
468
- if item_id is None and item_name is not None and item_type is not None:
469
- return self.get_item_by_name(item_name, item_type)
470
- elif item_id is None:
471
- raise Exception("item_id or the combination item_name + item_type is required")
472
-
473
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/items/{item_id}"
474
-
475
- item_dict = self.get_item_internal(url)
476
-
477
- return self.get_item_specific(item_dict)
192
+ return self.core_client.get_item(workspace_id=self.id, item_id=item_id, item_name=item_name, item_type=item_type)
478
193
 
479
- def delete_item(self, item_id):
194
+ def delete_item(self, item_id, type = None):
480
195
  """Delete an item from a workspace"""
481
- return self.get_item(item_id).delete()
196
+ return self.core_client.delete_item(workspace_id=self.id, item_id=item_id, type=type)
482
197
 
483
-
484
- def get_item_object_w_properties(self, item_list):
485
-
486
- new_item_list = []
487
- for item in item_list:
488
- item_ = self.get_item_specific(item)
489
- new_item_list.append(item_)
490
- return new_item_list
491
-
492
- def list_items(self, with_properties = False, continuationToken = None, type = None):
198
+ def list_items(self, with_properties = False, type = None):
493
199
  """List items in a workspace"""
494
200
 
495
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/items"
496
-
497
- if type:
498
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/{type}"
499
-
500
-
501
- if continuationToken:
502
- url = f"{url}?continuationToken={continuationToken}"
503
-
504
- for _ in range(10):
505
- response = requests.get(url=url, headers=self.auth.get_headers())
506
- if response.status_code == 429:
507
- print("Too many requests, waiting 10 seconds")
508
- sleep(10)
509
- continue
510
- if response.status_code not in (200, 429):
511
- print(response.status_code)
512
- print(response.text)
513
- raise Exception(f"Error listing items: {response.text}")
514
- break
515
-
516
- resp_dict = json.loads(response.text)
517
- items = resp_dict["value"]
518
- if with_properties:
519
- items = self.get_item_object_w_properties(items)
520
- else:
521
- items = [Item.from_dict(item, auth=self.auth) for item in items]
522
-
523
- if "continuationToken" in resp_dict:
524
- item_list_next = self.list_items(with_properties=with_properties,
525
- continuationToken=resp_dict["continuationToken"])
526
- items.extend(item_list_next)
527
-
528
- return items
201
+ return self.core_client.list_items(workspace_id=self.id, with_properties=with_properties,
202
+ type=type)
529
203
 
530
204
  def get_item_definition(self, item_id, type = None, format = None):
531
205
  """Get the definition of an item from a workspace"""
532
- return self.get_item(item_id).get_definition(type=type, format=format)
533
-
534
- def update_item(self, item_id, display_name = None, description = None):
206
+ return self.core_client.get_item_definition(workspace_id=self.id, item_id=item_id, type=type, format=format)
207
+
208
+ def update_item(self, item_id, display_name = None, description = None, return_item="Default"):
535
209
  """Update an item in a workspace"""
536
- return self.get_item(item_id=item_id).update(display_name=display_name, description=description)
210
+ return self.core_client.update_item(workspace_id=self.id,
211
+ item_id=item_id, display_name=display_name, description=description,
212
+ return_item=return_item)
537
213
 
538
214
  def update_item_definition(self, item_id, definition):
539
215
  """Update the definition of an item in a workspace"""
540
- return self.get_item(item_id=item_id).update_definition(definition=definition)
216
+ return self.core_client.update_item_definition(workspace_id=self.id, item_id=item_id, definition=definition)
541
217
 
218
+
542
219
  def create_shortcut(self, item_id, path, name, target):
543
- return self.get_item(item_id=item_id).create_shortcut(path=path, name=name, target=target)
220
+ return self.core_client.create_shortcut(workspace_id=self.id, item_id=item_id,
221
+ path=path, name=name, target=target)
222
+
223
+ def delete_shortcut(self, item_id, path, name):
224
+ return self.core_client.delete_shortcut(self.id, item_id, path=path, name=name)
544
225
 
545
226
  def get_shortcut(self, item_id, path, name):
546
- return self.get_item(item_id=item_id).get_shortcut(path=path, name=name)
227
+ return self.core_client.get_shortcut(self.id, item_id, path=path, name=name)
547
228
 
548
- def delete_shortcut(self, item_id, path, name):
549
- return self.get_item(item_id=item_id).delete_shortcut(path=path, name=name)
550
-
551
- def run_on_demand_item_job(self, item_id, job_type, execution_data = None):
552
- return self.get_item(item_id=item_id).run_on_demand_job(job_type=job_type, execution_data = execution_data)
229
+
230
+ def cancel_item_job_instance(self, item_id, job_instance_id):
231
+ return self.core_client.cancel_item_job_instance(workspace_id=self.id, item_id=item_id,
232
+ job_instance_id=job_instance_id)
553
233
 
554
234
  def get_item_job_instance(self, item_id, job_instance_id):
555
- return self.get_item(item_id=item_id).get_item_job_instance(job_instance_id=job_instance_id)
556
-
557
- def cancel_item_job_instance(self, item_id, job_instance_id):
558
- return self.get_item(item_id=item_id).cancel_item_job_instance(job_instance_id=job_instance_id)
235
+ return self.core_client.get_item_job_instance(workspace_id=self.id, item_id=item_id,
236
+ job_instance_id=job_instance_id)
237
+
238
+ def run_on_demand_item_job(self, item_id, job_type, execution_data = None):
239
+ return self.core_client.run_on_demand_item_job(workspace_id=self.id, item_id=item_id,
240
+ job_type=job_type, execution_data=execution_data)
559
241
 
560
- def git_connect(self, git_provider_details):
561
- """Connect git"""
562
- # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/connect
563
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/git/connect"
564
242
 
565
- payload = {
566
- 'gitProviderDetails': git_provider_details
567
- }
568
243
 
569
- for _ in range(10):
570
- response = requests.post(url=url, headers=self.auth.get_headers(), json=payload)
571
- if response.status_code == 429:
572
- print("Too many requests, waiting 10 seconds")
573
- sleep(10)
574
- continue
575
- if response.status_code not in (200, 204, 429):
576
- print(response.status_code)
577
- print(response.text)
578
- raise Exception(f"Error connecting git: {response.text}")
579
- break
580
- return response.status_code
244
+ def commit_to_git(self, mode, comment=None, items=None, workspace_head=None):
245
+ return self.core_client.commit_to_git(workspace_id=self.id, mode=mode, comment=comment,
246
+ items=items, workspace_head=workspace_head)
247
+
248
+
249
+ def git_connect(self, git_provider_details):
250
+ return self.core_client.git_connect(workspace_id=self.id, git_provider_details=git_provider_details)
581
251
 
582
252
  def git_disconnect(self):
583
- """Disconnect git"""
584
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/git/disconnect"
585
-
586
- for _ in range(10):
587
- response = requests.post(url=url, headers=self.auth.get_headers())
588
- if response.status_code == 429:
589
- print("Too many requests, waiting 10 seconds")
590
- sleep(10)
591
- continue
592
- if response.status_code not in (200, 204, 429):
593
- print(response.status_code)
594
- print(response.text)
595
- raise Exception(f"Error disconnecting git: {response.text}")
596
- break
597
- return response.status_code
253
+ return self.core_client.git_disconnect(workspace_id=self.id)
598
254
 
599
255
  def git_initialize_connection(self, initialization_strategy):
600
- # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/initializeConnection
601
- """Initialize git connection"""
602
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/git/initializeConnection"
603
-
604
- body = {'initializeGitConnectionRequest':initialization_strategy}
605
-
606
- for _ in range(10):
607
- response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
608
- if response.status_code == 429:
609
- print("Too many requests, waiting 10 seconds")
610
- sleep(10)
611
- continue
612
- if response.status_code == 202:
613
- check_long_running_operation( response.headers, self.auth)
614
- if response.status_code not in (200, 202, 429):
615
- print(response.status_code)
616
- print(response.text)
617
- raise Exception(f"Error initializing connection: {response.text}")
618
- break
619
- return response.status_code
620
-
621
- def git_get_status(self):
622
- """Get git connection status"""
623
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/git/status"
624
-
625
- for _ in range(10):
626
- response = requests.get(url=url, headers=self.auth.get_headers())
627
- if response.status_code == 429:
628
- print("Too many requests, waiting 10 seconds")
629
- sleep(10)
630
- continue
631
- if response.status_code == 202:
632
- check_long_running_operation( response.headers, self.auth)
633
- if response.status_code not in (200, 202, 429):
634
- print(response.status_code)
635
- print(response.text)
636
- raise Exception(f"Error getting git connection status: {response.text}")
637
- break
638
- return json.loads(response.text)
639
-
256
+ return self.core_client.git_initialize_connection(workspace_id=self.id,
257
+ initialization_strategy=initialization_strategy)
640
258
  def git_get_connection(self):
641
- """Get git connection info"""
642
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/git/connection"
643
-
644
- for _ in range(10):
645
- response = requests.get(url=url, headers=self.auth.get_headers())
646
- if response.status_code == 429:
647
- print("Too many requests, waiting 10 seconds")
648
- sleep(10)
649
- continue
650
- if response.status_code not in (200, 429):
651
- print(response.status_code)
652
- print(response.text)
653
- raise Exception(f"Error getting git connection info: {response.text}")
654
- break
655
- return json.loads(response.text)
656
-
657
- def commit_to_git(self, mode, comment=None, items=None, workspace_head=None):
658
- # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/commitToGit
659
-
660
- """Commit to git"""
661
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/git/commitToGit"
259
+ return self.core_client.git_get_connection(workspace_id=self.id)
260
+
261
+ def git_get_status(self):
262
+ return self.core_client.git_get_status(workspace_id=self.id)
662
263
 
663
- body = {
664
- 'mode': mode
665
- }
264
+ def update_from_git(self, remote_commit_hash, conflict_resolution = None, options = None, workspace_head = None):
265
+ return self.core_client.update_from_git(workspace_id=self.id, remote_commit_hash=remote_commit_hash,
266
+ conflict_resolution=conflict_resolution,
267
+ options=options, workspace_head=workspace_head)
268
+
666
269
 
667
- if comment:
668
- body['comment'] = comment
669
- if items:
670
- body['items'] = items
671
- if workspace_head:
672
- body['workspaceHead'] = workspace_head
673
-
674
- for _ in range(10):
675
- response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
676
- if response.status_code == 429:
677
- print("Too many requests, waiting 10 seconds")
678
- sleep(10)
679
- continue
680
- if response.status_code == 202:
681
- check_long_running_operation( response.headers, self.auth)
682
- if response.status_code not in (200, 202, 429):
683
- print(response.status_code)
684
- print(response.text)
685
- raise Exception(f"Error committing to git: {response.text}")
686
- break
687
-
688
- return response.status_code
689
270
 
690
- def update_from_git(self, remote_commit_hash, conflict_resolution = None, options = None, workspace_head = None):
691
- # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/git/updateFromGit
692
- """Update from git"""
693
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/git/updateFromGit"
271
+ # One Lake Data Access Security
694
272
 
695
- body = {
696
- "remoteCommitHash" : remote_commit_hash
697
- }
273
+ # create and update
698
274
 
699
- if conflict_resolution:
700
- body['conflictResolution'] = conflict_resolution
701
- if options:
702
- body['options'] = options
703
- if workspace_head:
704
- body['workspaceHead'] = workspace_head
705
-
706
- for _ in range(10):
707
- response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
708
- if response.status_code == 429:
709
- print("Too many requests, waiting 10 seconds")
710
- sleep(10)
711
- continue
712
- if response.status_code == 202:
713
- check_long_running_operation( response.headers, self.auth)
714
-
715
- if response.status_code not in (200, 202, 429):
716
- print(response.status_code)
717
- print(response.text)
718
- raise Exception(f"Error updating from git: {response.text}")
719
- break
720
-
721
- return response.status_code
722
-
723
- def list_tables(self, lakehouse_id):
724
- """List tables in a workspace"""
725
- return self.get_lakehouse(lakehouse_id=lakehouse_id).list_tables()
275
+ def create_or_update_data_access_roles(self, item_id, data_access_roles, dryrun = False, etag_match = None):
276
+ return self.core_client.create_or_update_data_access_roles(workspace_id=self.id, item_id=item_id, data_access_roles=data_access_roles,
277
+ dryrun=dryrun, etag_match=etag_match)
726
278
 
727
- def load_table(self, lakehouse_id, table_name, path_type, relative_path,
728
- file_extension = None, format_options = None,
729
- mode = None, recursive = None, wait_for_completion = True):
730
-
731
- return self.get_lakehouse(lakehouse_id=lakehouse_id).load_table(table_name, path_type, relative_path,
732
- file_extension, format_options,
733
- mode, recursive, wait_for_completion)
279
+ # list
280
+
281
+ def list_data_access_roles(self, item_id):
282
+ return self.core_client.list_data_access_roles(workspace_id=self.id, item_id=item_id)
734
283
 
735
- def run_on_demand_table_maintenance(self, lakehouse_id, execution_data,
736
- job_type = "TableMaintenance", wait_for_completion = True):
737
- """Run on demand table maintenance"""
738
- return self.get_lakehouse(lakehouse_id=lakehouse_id).run_on_demand_table_maintenance(execution_data,
739
- job_type,
740
- wait_for_completion)
284
+ # List other items
741
285
 
742
286
  def list_dashboards(self):
743
- """List dashboards in a workspace"""
744
- return self.list_items(type="dashboards")
287
+ return self.core_client.list_dashboards(workspace_id=self.id)
745
288
 
746
289
  def list_datamarts(self):
747
- """List datamarts in a workspace"""
748
- return self.list_items(type="datamarts")
290
+ return self.core_client.list_datamarts(workspace_id=self.id)
749
291
 
750
292
  def list_paginated_reports(self):
751
- """List paginated reports in a workspace"""
752
- return self.list_items(type="paginatedReports")
753
-
293
+ return self.core_client.list_paginated_reports(workspace_id=self.id)
294
+
754
295
  def list_sql_endpoints(self):
755
- """List sql endpoints in a workspace"""
756
- return self.list_items(type="sqlEndpoints")
757
-
758
- def list_mirrored_warehouses(self):
759
- """List mirrored warehouses in a workspace"""
760
- return self.list_items(type="mirroredWarehouses")
296
+ return self.core_client.list_sql_endpoints(workspace_id=self.id)
761
297
 
298
+ def list_mirrored_warehouses(self):
299
+ return self.core_client.list_mirrored_warehouses(workspace_id=self.id)
300
+
762
301
  # datapipelines
763
302
 
764
303
  def create_data_pipeline(self, display_name, definition = None, description = None):
765
- """Create a data pipeline in a workspace"""
766
- return self.create_item(display_name = display_name,
767
- type = "dataPipelines",
768
- definition = definition,
769
- description = description)
304
+ return self.core_client.create_data_pipeline(workspace_id=self.id, display_name=display_name,
305
+ definition=definition, description=description)
770
306
 
771
307
  def list_data_pipelines(self, with_properties = False):
772
- """List data pipelines in a workspace"""
773
- return self.list_items(type="dataPipelines", with_properties=with_properties)
308
+ return self.core_client.list_data_pipelines(workspace_id=self.id, with_properties=with_properties)
774
309
 
775
310
  def get_data_pipeline(self, data_pipeline_id = None, data_pipeline_name = None):
776
- """Get a data pipeline from a workspace"""
777
- if data_pipeline_id is None and data_pipeline_name is not None:
778
- return self.get_item_by_name(data_pipeline_name, "DataPipeline")
779
- elif data_pipeline_id is None:
780
- raise Exception("data_pipeline_id or the data_pipeline_name is required")
781
-
782
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/dataPipelines/{data_pipeline_id}"
783
-
784
- item_dict = self.get_item_internal(url)
785
- dp = DataPipeline.from_dict(item_dict, auth=self.auth)
786
- dp.get_definition()
787
- return dp
311
+ return self.core_client.get_data_pipeline(workspace_id=self.id, data_pipeline_id=data_pipeline_id,
312
+ data_pipeline_name=data_pipeline_name)
788
313
 
789
314
  def delete_data_pipeline(self, data_pipeline_id):
790
- """Delete a data pipeline from a workspace"""
791
- return self.get_item(item_id=data_pipeline_id).delete(type="dataPipelines")
315
+ return self.core_client.delete_data_pipeline(workspace_id=self.id, data_pipeline_id=data_pipeline_id)
792
316
 
793
317
  def update_data_pipeline(self, data_pipeline_id, display_name = None, description = None):
794
- """Update a data pipeline in a workspace"""
795
- return self.get_item(item_id=data_pipeline_id).update(display_name=display_name, description=description, type="dataPipelines")
318
+ return self.core_client.update_data_pipeline(workspace_id=self.id, data_pipeline_id=data_pipeline_id,
319
+ display_name=display_name, description=description)
796
320
 
797
321
  # environments
798
322
 
799
323
  def list_environments(self, with_properties = False):
800
324
  """List environments in a workspace"""
801
- return self.list_items(type="environments", with_properties = with_properties)
325
+ return self.core_client.list_environments(workspace_id=self.id, with_properties=with_properties)
802
326
 
803
327
  def create_environment(self, display_name, description = None):
804
328
  """Create an environment in a workspace"""
805
- return self.create_item(display_name = display_name,
806
- type = "environments",
807
- definition = None,
808
- description = description)
329
+ return self.core_client.create_environment(workspace_id=self.id, display_name=display_name, description=description)
809
330
 
810
331
  def get_environment(self, environment_id = None, environment_name = None):
811
332
  """Get an environment from a workspace"""
812
- if environment_id is None and environment_name is not None:
813
- return self.get_item_by_name(environment_name, "Environment")
814
- elif environment_id is None:
815
- raise Exception("environment_id or the environment_name is required")
816
-
817
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/environments/{environment_id}"
818
-
819
- item_dict = self.get_item_internal(url)
820
- env = Environment.from_dict(item_dict, auth=self.auth)
821
- return env
333
+ return self.core_client.get_environment(workspace_id=self.id, environment_id=environment_id,
334
+ environment_name=environment_name)
822
335
 
823
336
  def delete_environment(self, environment_id):
824
337
  """Delete an environment from a workspace"""
825
- return self.get_item(item_id=environment_id).delete(type="environments")
338
+ return self.core_client.delete_environment(workspace_id=self.id, environment_id=environment_id)
826
339
 
827
340
  def update_environment(self, environment_id, display_name = None, description = None):
828
341
  """Update an environment in a workspace"""
829
- return self.get_item(item_id=environment_id).update(display_name=display_name,
830
- description=description,
831
- type="environments")
342
+ return self.core_client.update_environment(workspace_id=self.id, environment_id=environment_id,
343
+ display_name=display_name, description=description)
832
344
 
833
345
  # environment spark compute
834
346
 
835
347
  def get_published_settings(self, environment_id):
836
- return self.get_environment(environment_id).get_published_settings()
348
+ return self.core_client.get_published_settings(workspace_id=self.id, environment_id=environment_id)
837
349
 
838
350
  def get_staging_settings(self, environment_id):
839
- return self.get_environment(environment_id).get_staging_settings()
351
+ return self.core_client.get_staging_settings(workspace_id=self.id, environment_id=environment_id)
840
352
 
841
353
  def update_staging_settings(self, environment_id,
842
354
  driver_cores = None, driver_memory = None, dynamic_executor_allocation = None,
843
355
  executor_cores = None, executor_memory = None, instance_pool = None,
844
356
  runtime_version = None, spark_properties = None):
845
- return self.get_environment(environment_id).update_staging_settings(driver_cores=driver_cores,
846
- driver_memory=driver_memory,
847
- dynamic_executor_allocation=dynamic_executor_allocation,
848
- executor_cores=executor_cores,
849
- executor_memory=executor_memory,
850
- instance_pool=instance_pool,
851
- runtime_version=runtime_version,
852
- spark_properties=spark_properties)
357
+ return self.core_client.update_staging_settings(workspace_id=self.id, environment_id=environment_id,
358
+ driver_cores=driver_cores, driver_memory=driver_memory,
359
+ dynamic_executor_allocation=dynamic_executor_allocation,
360
+ executor_cores=executor_cores, executor_memory=executor_memory,
361
+ instance_pool=instance_pool, runtime_version=runtime_version,
362
+ spark_properties=spark_properties)
853
363
 
854
364
  # environment spark libraries
855
365
 
856
366
  def get_published_libraries(self, environment_id):
857
- return self.get_environment(environment_id).get_published_libraries()
367
+ return self.core_client.get_published_libraries(workspace_id=self.id, environment_id=environment_id)
858
368
 
859
369
  def get_staging_libraries(self, environment_id):
860
- return self.get_environment(environment_id).get_staging_libraries()
370
+ return self.core_client.get_staging_libraries(workspace_id=self.id, environment_id=environment_id)
861
371
 
862
372
  def upload_staging_library(self, environment_id, file_path):
863
- return self.get_environment(environment_id).upload_staging_library(file_path)
373
+ return self.core_client.upload_staging_library(workspace_id=self.id, environment_id=environment_id, file_path=file_path)
864
374
 
865
375
  def publish_environment(self, environment_id):
866
- return self.get_environment(environment_id).publish_environment()
376
+ return self.core_client.publish_environment(workspace_id=self.id, environment_id=environment_id)
867
377
 
868
378
  def delete_staging_library(self, environment_id, library_to_delete):
869
- return self.get_environment(environment_id).delete_staging_library(library_to_delete)
870
-
379
+ return self.core_client.delete_staging_library(workspace_id=self.id, environment_id=environment_id, library_to_delete=library_to_delete)
380
+
871
381
  def cancel_publish(self, environment_id):
872
- return self.get_environment(environment_id).cancel_publish()
382
+ return self.core_client.cancel_publish(workspace_id=self.id, environment_id=environment_id)
873
383
 
874
384
  # eventhouses
385
+
875
386
  def list_eventhouses(self, with_properties = False):
876
387
  """List eventhouses in a workspace"""
877
- return self.list_items(type="eventhouses", with_properties=with_properties)
388
+ return self.core_client.list_eventhouses(workspace_id=self.id, with_properties=with_properties)
878
389
 
879
390
  def create_eventhouse(self, display_name, description = None):
880
391
  """Create an eventhouse in a workspace"""
881
- return self.create_item(display_name = display_name,
882
- type = "eventhouses",
883
- definition = None,
884
- description = description)
392
+ return self.core_client.create_eventhouse(workspace_id=self.id, display_name=display_name, description=description)
885
393
 
886
394
  def get_eventhouse(self, eventhouse_id = None, eventhouse_name = None):
887
395
  """Get an eventhouse from a workspace"""
888
- if eventhouse_id is None and eventhouse_name is not None:
889
- return self.get_item_by_name(eventhouse_name, "Eventhouse")
890
- elif eventhouse_id is None:
891
- raise Exception("eventhouse_id or the eventhouse_name is required")
892
-
893
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/eventhouses/{eventhouse_id}"
894
-
895
- item_dict = self.get_item_internal(url)
896
- return Eventhouse.from_dict(item_dict, auth=self.auth)
396
+ return self.core_client.get_eventhouse(workspace_id=self.id, eventhouse_id=eventhouse_id,
397
+ eventhouse_name=eventhouse_name)
897
398
 
898
399
  def delete_eventhouse(self, eventhouse_id):
899
400
  """Delete an eventhouse from a workspace"""
900
- return self.get_item(item_id=eventhouse_id).delete(type="eventhouses")
401
+ return self.core_client.delete_eventhouse(workspace_id=self.id, eventhouse_id=eventhouse_id)
901
402
 
902
403
  def update_eventhouse(self, eventhouse_id, display_name = None, description = None):
903
404
  """Update an eventhouse in a workspace"""
904
- return self.get_item(item_id=eventhouse_id).update(display_name=display_name,
905
- description=description,
906
- type="eventhouses")
405
+ return self.core_client.update_eventhouse(workspace_id=self.id, eventhouse_id=eventhouse_id,
406
+ display_name=display_name, description=description)
907
407
 
908
408
  # eventstreams
909
409
 
910
- def list_eventstreams(self, with_properties = False):
911
- """List eventstreams in a workspace"""
912
- return self.list_items(type="eventstreams", with_properties=with_properties)
913
-
410
+
914
411
  def create_eventstream(self, display_name, description = None):
915
412
  """Create an eventstream in a workspace"""
916
- return self.create_item(display_name = display_name,
917
- type = "eventstreams",
918
- definition = None,
919
- description = description)
920
-
921
- def get_eventstream(self, eventstream_id = None, eventstream_name = None):
922
- """Get an eventstream from a workspace"""
923
- if eventstream_id is None and eventstream_name is not None:
924
- return self.get_item_by_name(eventstream_name, "Eventstream")
925
- elif eventstream_id is None:
926
- raise Exception("eventstream_id or the eventstream_name is required")
927
-
928
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/eventstreams/{eventstream_id}"
929
-
930
- item_dict = self.get_item_internal(url)
931
- return Eventstream.from_dict(item_dict, auth=self.auth)
413
+ return self.core_client.create_eventstream(workspace_id=self.id, display_name=display_name, description=description)
932
414
 
933
415
  def delete_eventstream(self, eventstream_id):
934
416
  """Delete an eventstream from a workspace"""
935
- return self.get_item(item_id=eventstream_id).delete(type="eventstreams")
417
+ return self.core_client.delete_eventstream(workspace_id=self.id, eventstream_id=eventstream_id)
418
+
419
+ def get_eventstream(self, eventstream_id = None, eventstream_name = None):
420
+ return self.core_client.get_eventstream(workspace_id=self.id, eventstream_id=eventstream_id, eventstream_name=eventstream_name)
421
+
422
+ def list_eventstreams(self, with_properties = False):
423
+ """List eventstreams in a workspace"""
424
+ return self.core_client.list_eventstreams(workspace_id=self.id, with_properties=with_properties)
936
425
 
937
426
  def update_eventstream(self, eventstream_id, display_name = None, description = None):
938
427
  """Update an eventstream in a workspace"""
939
- return self.get_item(item_id=eventstream_id).update(display_name=display_name,
940
- description=description,
941
- type="eventstreams")
428
+ return self.core_client.update_eventstream(workspace_id=self.id, eventstream_id=eventstream_id,
429
+ display_name=display_name, description=description)
942
430
 
943
431
  # kqlDatabases
944
432
 
945
- def list_kql_databases(self, with_properties = False):
946
- """List kql databases in a workspace"""
947
- return self.list_items(type="kqlDatabases", with_properties = with_properties)
948
-
433
+
949
434
  def create_kql_database(self, creation_payload, display_name, description = None, ):
950
435
  """Create a kql database in a workspace"""
951
- return self.create_item(display_name = display_name,
952
- type = "kqlDatabases",
953
- description = description,
954
- creation_payload = creation_payload)
436
+ return self.core_client.create_kql_database(workspace_id=self.id, creation_payload=creation_payload,
437
+ display_name=display_name, description=description)
438
+ def delete_kql_database(self, kql_database_id):
439
+ """Delete a kql database from a workspace"""
440
+ return self.core_client.delete_kql_database(workspace_id=self.id, kql_database_id=kql_database_id)
955
441
 
956
442
  def get_kql_database(self, kql_database_id = None, kql_database_name = None):
957
443
  """Get a kql database from a workspace"""
958
-
959
- if kql_database_id is None and kql_database_name is not None:
960
- return self.get_item_by_name(kql_database_name, "KQLDatabase")
961
- elif kql_database_id is None:
962
- raise Exception("kql_database_id or the kql_database_name is required")
963
-
964
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/kqlDatabases/{kql_database_id}"
965
-
966
- item_dict = self.get_item_internal(url)
967
- return KQLDatabase.from_dict(item_dict, auth=self.auth)
444
+ return self.core_client.get_kql_database(workspace_id=self.id, kql_database_id=kql_database_id,
445
+ kql_database_name=kql_database_name)
968
446
 
969
- def delete_kql_database(self, kql_database_id):
970
- """Delete a kql database from a workspace"""
971
- return self.get_item(item_id=kql_database_id).delete(type="kqlDatabases")
447
+
448
+ def list_kql_databases(self, with_properties = False):
449
+ """List kql databases in a workspace"""
450
+ return self.core_client.list_kql_databases(workspace_id=self.id, with_properties=with_properties)
972
451
 
973
452
  def update_kql_database(self, kql_database_id, display_name = None, description = None):
974
453
  """Update a kql database in a workspace"""
975
- return self.get_item(item_id=kql_database_id).update(display_name=display_name,
976
- description=description,
977
- type="kqlDatabases")
454
+ return self.core_client.update_kql_database(workspace_id=self.id, kql_database_id=kql_database_id,
455
+ display_name=display_name, description=description)
978
456
 
979
457
  # kqlQuerysets
980
458
 
981
- def list_kql_querysets(self, with_properties = False):
982
- """List kql querysets in a workspace"""
983
- return self.list_items(type="kqlQuerysets", with_properties = with_properties)
459
+ def delete_kql_queryset(self, kql_queryset_id):
460
+ """Delete a kql queryset from a workspace"""
461
+ return self.core_client.delete_kql_queryset(workspace_id=self.id, kql_queryset_id=kql_queryset_id)
984
462
 
985
463
  def get_kql_queryset(self, kql_queryset_id = None, kql_queryset_name = None):
986
464
  """Get a kql queryset from a workspace"""
987
-
988
- if kql_queryset_id is None and kql_queryset_name is not None:
989
- return self.get_item_by_name(kql_queryset_name, "KQLQueryset")
990
- elif kql_queryset_id is None:
991
- raise Exception("kql_queryset_id or the kql_queryset_name is required")
992
-
993
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/kqlQuerysets/{kql_queryset_id}"
994
-
995
- item_dict = self.get_item_internal(url)
996
- return KQLQueryset.from_dict(item_dict, auth=self.auth)
997
-
998
- def delete_kql_queryset(self, kql_queryset_id):
999
- """Delete a kql queryset from a workspace"""
1000
- return self.get_item(item_id=kql_queryset_id).delete(type="kqlQuerysets")
465
+ return self.core_client.get_kql_queryset(self.id, kql_queryset_id, kql_queryset_name)
1001
466
 
467
+ def list_kql_querysets(self, with_properties = False):
468
+ """List kql querysets in a workspace"""
469
+ return self.core_client.list_kql_querysets(workspace_id=self.id, with_properties=with_properties)
470
+
1002
471
  def update_kql_queryset(self, kql_queryset_id, display_name = None, description = None):
1003
472
  """Update a kql queryset in a workspace"""
1004
- return self.get_item(item_id=kql_queryset_id).update(display_name=display_name,
1005
- description=description,
1006
- type="kqlQuerysets")
1007
-
473
+ return self.core_client.update_kql_queryset(workspace_id=self.id, kql_queryset_id=kql_queryset_id,
474
+ display_name=display_name, description=description)
1008
475
 
1009
476
  # lakehouses
477
+ def run_on_demand_table_maintenance(self, lakehouse_id, execution_data,
478
+ job_type = "TableMaintenance", wait_for_completion = True):
479
+ """Run on demand table maintenance"""
480
+ return self.core_client.run_on_demand_table_maintenance(workspace_id=self.id, lakehouse_id=lakehouse_id,
481
+ execution_data=execution_data, job_type=job_type,
482
+ wait_for_completion=wait_for_completion)
1010
483
 
1011
- def list_lakehouses(self, with_properties = False):
1012
- """List lakehouses in a workspace"""
1013
- return self.list_items(with_properties = with_properties, type="lakehouses")
1014
-
1015
484
  def create_lakehouse(self, display_name, description = None):
1016
485
  """Create a lakehouse in a workspace"""
1017
- return self.create_item(display_name = display_name,
1018
- type = "lakehouses",
1019
- definition = None,
1020
- description = description)
486
+ return self.core_client.create_lakehouse(workspace_id=self.id, display_name=display_name, description=description)
1021
487
 
1022
488
  def delete_lakehouse(self, lakehouse_id):
1023
489
  """Delete a lakehouse from a workspace"""
1024
- return self.get_item(item_id=lakehouse_id).delete(type="lakehouses")
490
+ return self.core_client.delete_lakehouse(workspace_id=self.id, lakehouse_id=lakehouse_id)
491
+
492
+ def get_lakehouse(self, lakehouse_id = None, lakehouse_name = None):
493
+ """Get a lakehouse from a workspace"""
494
+ return self.core_client.get_lakehouse(workspace_id=self.id, lakehouse_id=lakehouse_id, lakehouse_name=lakehouse_name)
495
+
496
+ def list_lakehouses(self, with_properties = False):
497
+ """List lakehouses in a workspace"""
498
+ return self.core_client.list_lakehouses(workspace_id=self.id, with_properties=with_properties)
1025
499
 
1026
500
  def update_lakehouse(self, lakehouse_id, display_name = None, description = None):
1027
501
  """Update a lakehouse in a workspace"""
1028
- return self.get_item(item_id=lakehouse_id).update(display_name=display_name,
1029
- description=description,
1030
- type="lakehouses")
502
+ return self.core_client.update_lakehouse(workspace_id=self.id, lakehouse_id=lakehouse_id,
503
+ display_name=display_name, description=description)
1031
504
 
1032
- def get_lakehouse(self, lakehouse_id = None, lakehouse_name = None):
1033
- """Get a lakehouse from a workspace"""
1034
-
1035
- if lakehouse_id is None and lakehouse_name is not None:
1036
- return self.get_item_by_name(lakehouse_name, "Lakehouse")
1037
- elif lakehouse_id is None:
1038
- raise Exception("lakehouse_id or the lakehouse_name is required")
505
+ def list_tables(self, lakehouse_id):
506
+ """List tables in a workspace"""
507
+ return self.core_client.list_tables(workspace_id=self.id, lakehouse_id=lakehouse_id)
508
+
509
+ def load_table(self, lakehouse_id, table_name, path_type, relative_path,
510
+ file_extension = None, format_options = None,
511
+ mode = None, recursive = None, wait_for_completion = True):
1039
512
 
1040
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/lakehouses/{lakehouse_id}"
1041
-
1042
- item_dict = self.get_item_internal(url)
1043
- return Lakehouse.from_dict(item_dict, auth=self.auth)
513
+ return self.core_client.load_table(workspace_id=self.id, lakehouse_id=lakehouse_id, table_name=table_name,
514
+ path_type=path_type, relative_path=relative_path,
515
+ file_extension=file_extension, format_options=format_options,
516
+ mode=mode, recursive=recursive, wait_for_completion=wait_for_completion)
1044
517
 
518
+
1045
519
  # mlExperiments
1046
520
 
1047
- def list_ml_experiments(self, with_properties = False):
1048
- """List ml experiments in a workspace"""
1049
- return self.list_items(type="mlExperiments", with_properties = with_properties)
1050
-
1051
521
  def create_ml_experiment(self, display_name, description = None):
1052
522
  """Create an ml experiment in a workspace"""
1053
- return self.create_item(display_name = display_name,
1054
- type = "mlExperiments",
1055
- definition = None,
1056
- description = description)
523
+ return self.core_client.create_ml_experiment(workspace_id=self.id, display_name=display_name, description=description)
1057
524
 
525
+ def delete_ml_experiment(self, ml_experiment_id):
526
+ """Delete an ml experiment from a workspace"""
527
+ return self.core_client.delete_ml_experiment(workspace_id=self.id, ml_experiment_id=ml_experiment_id)
528
+
1058
529
  def get_ml_experiment(self, ml_experiment_id = None, ml_experiment_name = None):
1059
530
  """Get an ml experiment from a workspace"""
1060
- if ml_experiment_id is None and ml_experiment_name is not None:
1061
- return self.get_item_by_name(ml_experiment_name, "MLExperiment")
1062
- elif ml_experiment_id is None:
1063
- raise Exception("ml_experiment_id or the ml_experiment_name is required")
1064
-
1065
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/mlExperiments/{ml_experiment_id}"
531
+ return self.core_client.get_ml_experiment(workspace_id=self.id, ml_experiment_id=ml_experiment_id, ml_experiment_name=ml_experiment_name)
1066
532
 
1067
- item_dict = self.get_item_internal(url)
1068
- return MLExperiment.from_dict(item_dict, auth=self.auth)
1069
-
1070
- def delete_ml_experiment(self, ml_experiment_id):
1071
- """Delete an ml experiment from a workspace"""
1072
- return self.get_item(item_id=ml_experiment_id).delete(type="mlExperiments")
533
+ def list_ml_experiments(self, with_properties = False):
534
+ """List ml experiments in a workspace"""
535
+ return self.core_client.list_ml_experiments(workspace_id=self.id, with_properties=with_properties)
1073
536
 
1074
537
  def update_ml_experiment(self, ml_experiment_id, display_name = None, description = None):
1075
538
  """Update an ml experiment in a workspace"""
1076
- return self.get_item(item_id=ml_experiment_id).update(display_name=display_name,
1077
- description=description,
1078
- type="mlExperiments")
539
+ return self.core_client.update_ml_experiment(workspace_id=self.id, ml_experiment_id=ml_experiment_id, display_name=display_name, description=description)
1079
540
 
1080
541
  # mlModels
1081
542
 
1082
543
  def list_ml_models(self, with_properties = False):
1083
544
  """List ml models in a workspace"""
1084
- return self.list_items(type="mlModels", with_properties = with_properties)
545
+ return self.core_client.list_ml_models(workspace_id=self.id, with_properties=with_properties)
1085
546
 
1086
547
  def create_ml_model(self, display_name, description = None):
1087
548
  """Create an ml model in a workspace"""
1088
- return self.create_item(display_name = display_name,
1089
- type = "mlModels",
1090
- definition = None,
1091
- description = description)
549
+ return self.core_client.create_ml_model(workspace_id=self.id, display_name=display_name, description=description)
1092
550
 
1093
551
  def get_ml_model(self, ml_model_id = None, ml_model_name = None):
1094
552
  """Get an ml model from a workspace"""
1095
- if ml_model_id is None and ml_model_name is not None:
1096
- return self.get_item_by_name(ml_model_name, "MLModel")
1097
- elif ml_model_id is None:
1098
- raise Exception("ml_model_id or the ml_model_name is required")
1099
-
1100
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/mlModels/{ml_model_id}"
1101
-
1102
- item_dict = self.get_item_internal(url)
1103
- return MLModel.from_dict(item_dict, auth=self.auth)
553
+ return self.core_client.get_ml_model(workspace_id=self.id, ml_model_id=ml_model_id, ml_model_name=ml_model_name)
1104
554
 
1105
555
  def delete_ml_model(self, ml_model_id):
1106
556
  """Delete an ml model from a workspace"""
1107
- return self.get_item(item_id=ml_model_id).delete(type="mlModels")
557
+ return self.core_client.delete_ml_model(workspace_id=self.id, ml_model_id=ml_model_id)
1108
558
 
1109
559
  def update_ml_model(self, ml_model_id, display_name = None, description = None):
1110
560
  """Update an ml model in a workspace"""
1111
- return self.get_item(item_id=ml_model_id).update(display_name=display_name,
1112
- description=description,
1113
- type="mlModels")
561
+ return self.core_client.update_ml_model(workspace_id=self.id, ml_model_id=ml_model_id, display_name=display_name, description=description)
1114
562
 
1115
563
  # notebooks
1116
564
 
1117
- def list_notebooks(self, with_properties = False):
1118
- """List notebooks in a workspace"""
1119
- return self.list_items(type="notebooks", with_properties = with_properties)
1120
-
1121
565
  def create_notebook(self, display_name, definition = None, description = None):
1122
566
  """Create a notebook in a workspace"""
1123
- return self.create_item(display_name = display_name,
1124
- type = "notebooks",
1125
- definition = definition,
1126
- description = description)
1127
-
1128
- def get_notebook(self, notebook_id = None, notebook_name = None):
1129
- """Get a notebook from a workspace"""
1130
- if notebook_id is None and notebook_name is not None:
1131
- return self.get_item_by_name(notebook_name, "Notebook")
1132
- elif notebook_id is None:
1133
- raise Exception("notebook_id or the notebook_name is required")
1134
-
1135
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/notebooks/{notebook_id}"
567
+ return self.core_client.create_notebook(workspace_id=self.id, display_name=display_name,
568
+ definition=definition, description=description)
1136
569
 
1137
- item_dict = self.get_item_internal(url)
1138
- noteb = Notebook.from_dict(item_dict, auth=self.auth)
1139
- noteb.get_definition()
1140
- return noteb
1141
-
1142
570
  def delete_notebook(self, notebook_id):
1143
571
  """Delete a notebook from a workspace"""
1144
- return self.get_item(item_id=notebook_id).delete(type="notebooks")
1145
-
1146
- def update_notebook(self, notebook_id, display_name = None, description = None):
1147
- """Update a notebook in a workspace"""
1148
- return self.get_item(item_id=notebook_id).update(display_name=display_name,
1149
- description=description,
1150
- type="notebooks")
572
+ return self.core_client.delete_notebook(workspace_id=self.id, notebook_id=notebook_id)
573
+
574
+ def get_notebook(self, notebook_id = None, notebook_name = None):
575
+ """Get a notebook from a workspace"""
576
+ return self.core_client.get_notebook(workspace_id=self.id, notebook_id=notebook_id, notebook_name=notebook_name)
1151
577
 
1152
578
  def get_notebook_definition(self, notebook_id, format = None):
1153
579
  """Get the definition of a notebook from a workspace"""
1154
- return self.get_notebook(notebook_id=notebook_id).get_definition(format=format)
580
+ return self.core_client.get_notebook_definition(workspace_id=self.id, notebook_id=notebook_id, format=format)
581
+
582
+ def list_notebooks(self, with_properties = False):
583
+ """List notebooks in a workspace"""
584
+ return self.core_client.list_notebooks(workspace_id=self.id, with_properties=with_properties)
585
+
586
+ def update_notebook(self, notebook_id, display_name = None, description = None):
587
+ """Update a notebook in a workspace"""
588
+ return self.core_client.update_notebook(workspace_id=self.id, notebook_id=notebook_id, display_name=display_name, description=description)
1155
589
 
1156
590
  def update_notebook_definition(self, notebook_id, definition):
1157
591
  """Update the definition of a notebook in a workspace"""
1158
- return self.get_notebook(notebook_id=notebook_id).update_definition(definition=definition)
592
+ return self.core_client.update_notebook_definition(workspace_id=self.id, notebook_id=notebook_id, definition=definition)
1159
593
 
1160
594
  # reports
1161
595
 
1162
- def list_reports(self, with_properties = False):
1163
- """List reports in a workspace"""
1164
- return self.list_items(type="reports", with_properties = with_properties)
1165
-
1166
596
  def create_report(self, display_name, definition = None, description = None):
1167
597
  """Create a report in a workspace"""
1168
- return self.create_item(display_name = display_name,
1169
- type = "reports",
1170
- definition = definition,
1171
- description = description)
598
+ return self.core_client.create_report(workspace_id=self.id, display_name=display_name,
599
+ definition=definition, description=description)
1172
600
 
1173
601
  def get_report(self, report_id = None, report_name = None):
1174
602
  """Get a report from a workspace"""
1175
- if report_id is None and report_name is not None:
1176
- return self.get_item_by_name(report_name, "Report")
1177
- elif report_id is None:
1178
- raise Exception("report_id or the report_name is required")
1179
-
1180
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/reports/{report_id}"
1181
-
1182
- item_dict = self.get_item_internal(url)
1183
- rep = Report.from_dict(item_dict, auth=self.auth)
1184
- rep.get_definition()
1185
- return rep
603
+ return self.core_client.get_report(workspace_id=self.id, report_id=report_id, report_name=report_name)
1186
604
 
1187
605
  def delete_report(self, report_id):
1188
606
  """Delete a report from a workspace"""
1189
- return self.get_item(item_id=report_id).delete(type="reports")
607
+ return self.core_client.delete_report(workspace_id=self.id, report_id=report_id)
1190
608
 
1191
609
  def get_report_definition(self, report_id, format = None):
1192
610
  """Get the definition of a report from a workspace"""
1193
- return self.get_report(report_id=report_id).get_definition(format=format)
611
+ return self.core_client.get_report_definition(workspace_id=self.id, report_id=report_id, format=format)
612
+
613
+ def list_reports(self, with_properties = False):
614
+ """List reports in a workspace"""
615
+ return self.core_client.list_reports(workspace_id=self.id, with_properties=with_properties)
1194
616
 
1195
617
  def update_report_definition(self, report_id, definition):
1196
618
  """Update the definition of a report in a workspace"""
1197
- return self.get_report(report_id=report_id).update_definition(definition=definition)
619
+ return self.core_client.update_report_definition(workspace_id=self.id, report_id=report_id, definition=definition)
1198
620
 
1199
621
  # semanticModels
1200
622
 
1201
623
  def list_semantic_models(self, with_properties = False):
1202
624
  """List semantic models in a workspace"""
1203
- return self.list_items(type="semanticModels", with_properties = with_properties)
625
+ return self.core_client.list_semantic_models(workspace_id=self.id, with_properties=with_properties)
1204
626
 
1205
627
  def create_semantic_model(self, display_name, definition = None, description = None):
1206
628
  """Create a semantic model in a workspace"""
1207
- return self.create_item(display_name = display_name,
1208
- type = "semanticModels",
1209
- definition = definition,
1210
- description = description)
629
+ return self.core_client.create_semantic_model(workspace_id=self.id, display_name=display_name,
630
+ definition=definition, description=description)
1211
631
 
1212
632
  def get_semantic_model(self, semantic_model_id = None, semantic_model_name = None):
1213
633
  """Get a semantic model from a workspace"""
1214
- if semantic_model_id is None and semantic_model_name is not None:
1215
- return self.get_item_by_name(semantic_model_name, "SemanticModel")
1216
- elif semantic_model_id is None:
1217
- raise Exception("semantic_model_id or the semantic_model_name is required")
1218
-
1219
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/semanticModels/{semantic_model_id}"
1220
-
1221
- item_dict = self.get_item_internal(url)
1222
- semmodel = SemanticModel.from_dict(item_dict, auth=self.auth)
1223
- semmodel.get_definition()
1224
- return semmodel
634
+ return self.core_client.get_semantic_model(workspace_id=self.id, semantic_model_id=semantic_model_id,
635
+ semantic_model_name=semantic_model_name)
1225
636
 
1226
637
  def delete_semantic_model(self, semantic_model_id):
1227
638
  """Delete a semantic model from a workspace"""
1228
- return self.get_item(item_id=semantic_model_id).delete(type="semanticModels")
639
+ return self.core_client.delete_semantic_model(workspace_id=self.id, semantic_model_id=semantic_model_id)
1229
640
 
1230
641
  # def update_semantic_model(self, semantic_model_id, display_name = None, description = None):
1231
642
  # """Update a semantic model in a workspace"""
@@ -1235,282 +646,105 @@ class Workspace:
1235
646
 
1236
647
  def get_semantic_model_definition(self, semantic_model_id, format = None):
1237
648
  """Get the definition of a semantic model from a workspace"""
1238
- return self.get_semantic_model(semantic_model_id=semantic_model_id).get_definition(format=format)
649
+ return self.core_client.get_semantic_model_definition(workspace_id=self.id, semantic_model_id=semantic_model_id, format=format)
1239
650
 
1240
651
  def update_semantic_model_definition(self, semantic_model_id, definition):
1241
652
  """Update the definition of a semantic model in a workspace"""
1242
- return self.get_semantic_model(semantic_model_id=semantic_model_id).update_definition(definition=definition)
653
+ return self.core_client.update_semantic_model_definition(workspace_id=self.id, semantic_model_id=semantic_model_id, definition=definition)
654
+
655
+ # spark workspace custom pools
656
+
657
+ def list_workspace_custom_pools(self):
658
+ """List spark worspace custom pools in a workspace"""
659
+ return self.core_client.list_workspace_custom_pools(workspace_id=self.id)
1243
660
 
661
+ def create_workspace_custom_pool(self, name, node_family, node_size, auto_scale, dynamic_executor_allocation):
662
+ """Create a custom pool in a workspace"""
663
+ return self.core_client.create_workspace_custom_pool(workspace_id=self.id, name=name, node_family=node_family,
664
+ node_size=node_size, auto_scale=auto_scale,
665
+ dynamic_executor_allocation=dynamic_executor_allocation)
666
+
667
+ def get_workspace_custom_pool(self, pool_id):
668
+ """Get a custom pool in a workspace"""
669
+ return self.core_client.get_workspace_custom_pool(workspace_id=self.id, pool_id=pool_id)
670
+
671
+ def delete_workspace_custom_pool(self, pool_id):
672
+ """Delete a custom pool in a workspace"""
673
+ return self.core_client.delete_workspace_custom_pool(workspace_id=self.id, pool_id=pool_id)
674
+
675
+ def update_workspace_custom_pool(self, pool_id, name = None , node_family = None, node_size = None,
676
+ auto_scale = None,
677
+ dynamic_executor_allocation = None):
678
+ """Update a custom pool in a workspace"""
679
+ return self.core_client.update_workspace_custom_pool(workspace_id=self.id, pool_id=pool_id, name=name,
680
+ node_family=node_family, node_size=node_size,
681
+ auto_scale=auto_scale,
682
+ dynamic_executor_allocation=dynamic_executor_allocation)
683
+
684
+ # spark workspace settings
685
+
686
+ def get_spark_settings(self):
687
+ return self.core_client.get_spark_settings(workspace_id=self.id)
688
+
689
+ def update_spark_settings(self, automatic_log = None, environment = None, high_concurrency = None, pool = None):
690
+ return self.core_client.update_spark_settings(workspace_id=self.id, automatic_log=automatic_log,
691
+ environment=environment, high_concurrency=high_concurrency, pool=pool)
692
+
1244
693
  # sparkJobDefinitions
1245
694
 
1246
695
  def list_spark_job_definitions(self, with_properties = False):
1247
696
  """List spark job definitions in a workspace"""
1248
- return self.list_items(type="sparkJobDefinitions", with_properties = with_properties)
697
+ return self.core_client.list_spark_job_definitions(workspace_id=self.id, with_properties=with_properties)
1249
698
 
1250
699
  def create_spark_job_definition(self, display_name, definition = None, description = None):
1251
700
  """Create a spark job definition in a workspace"""
1252
- return self.create_item(display_name = display_name,
1253
- type = "sparkJobDefinitions",
1254
- definition = definition,
1255
- description = description)
701
+ return self.core_client.create_spark_job_definition(workspace_id=self.id, display_name=display_name,
702
+ definition=definition, description=description)
1256
703
 
1257
704
  def get_spark_job_definition(self, spark_job_definition_id = None, spark_job_definition_name = None):
1258
705
  """Get a spark job definition from a workspace"""
1259
- if spark_job_definition_id is None and spark_job_definition_name is not None:
1260
- return self.get_item_by_name(spark_job_definition_name, "SparkJobDefinition")
1261
- elif spark_job_definition_id is None:
1262
- raise Exception("spark_job_definition_id or the spark_job_definition_name is required")
1263
-
1264
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/sparkjobdefinitions/{spark_job_definition_id}"
1265
-
1266
- item_dict = self.get_item_internal(url)
1267
- sjd_obj = SparkJobDefinition.from_dict(item_dict, auth=self.auth)
1268
- sjd_obj.get_definition()
1269
- return sjd_obj
706
+ return self.core_client.get_spark_job_definition(workspace_id=self.id, spark_job_definition_id=spark_job_definition_id,
707
+ spark_job_definition_name=spark_job_definition_name)
1270
708
 
1271
709
  def delete_spark_job_definition(self, spark_job_definition_id):
1272
710
  """Delete a spark job definition from a workspace"""
1273
- return self.get_item(item_id=spark_job_definition_id).delete(type="sparkJobDefinitions")
711
+ return self.core_client.delete_spark_job_definition(workspace_id=self.id, spark_job_definition_id=spark_job_definition_id)
1274
712
 
1275
713
  def update_spark_job_definition(self, spark_job_definition_id, display_name = None, description = None):
1276
714
  """Update a spark job definition in a workspace"""
1277
- return self.get_spark_job_definition(spark_job_definition_id=spark_job_definition_id).update(display_name=display_name,
1278
- description=description,
1279
- type="sparkJobDefinitions")
715
+ return self.core_client.update_spark_job_definition(workspace_id=self.id, spark_job_definition_id=spark_job_definition_id,
716
+ display_name=display_name, description=description)
1280
717
 
1281
718
  def get_spark_job_definition_definition(self, spark_job_definition_id, format = None):
1282
719
  """Get the definition of a spark job definition from a workspace"""
1283
- return self.get_spark_job_definition(spark_job_definition_id=spark_job_definition_id).get_definition(format=format)
720
+ return self.core_client.get_spark_job_definition_definition(workspace_id=self.id, spark_job_definition_id=spark_job_definition_id, format=format)
1284
721
 
1285
722
  def update_spark_job_definition_definition(self, spark_job_definition_id, definition):
1286
723
  """Update the definition of a spark job definition in a workspace"""
1287
- return self.get_spark_job_definition(spark_job_definition_id=spark_job_definition_id).update_definition(definition=definition)
724
+ return self.core_client.update_spark_job_definition_definition(workspace_id=self.id, spark_job_definition_id=spark_job_definition_id, definition=definition)
1288
725
 
1289
726
  def run_on_demand_spark_job_definition(self, spark_job_definition_id, job_type = "sparkjob"):
1290
727
  """Run on demand spark job definition"""
1291
- sjd = self.get_spark_job_definition(spark_job_definition_id=spark_job_definition_id)
1292
- return sjd.run_on_demand_spark_job_definition(job_type=job_type)
1293
-
728
+ return self.core_client.run_on_demand_spark_job_definition(workspace_id=self.id, spark_job_definition_id=spark_job_definition_id, job_type=job_type)
729
+
1294
730
  # warehouses
1295
731
 
1296
732
  def list_warehouses(self, with_properties = False):
1297
733
  """List warehouses in a workspace"""
1298
- return self.list_items(type="warehouses", with_properties = with_properties)
734
+ return self.core_client.list_warehouses(workspace_id=self.id, with_properties=with_properties)
1299
735
 
1300
736
  def create_warehouse(self, display_name, description = None):
1301
737
  """Create a warehouse in a workspace"""
1302
- return self.create_item(display_name = display_name,
1303
- type = "warehouses",description = description)
738
+ return self.core_client.create_warehouse(workspace_id=self.id, display_name=display_name, description=description)
1304
739
 
1305
740
  def get_warehouse(self, warehouse_id = None, warehouse_name = None):
1306
741
  """Get a warehouse from a workspace"""
1307
- if warehouse_id is None and warehouse_name is not None:
1308
- return self.get_item_by_name(warehouse_name, "Warehouse")
1309
- elif warehouse_id is None:
1310
- raise Exception("warehouse_id or the warehouse_name is required")
1311
-
1312
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/warehouses/{warehouse_id}"
1313
-
1314
- item_dict = self.get_item_internal(url)
1315
- return Warehouse.from_dict(item_dict, auth=self.auth)
742
+ return self.core_client.get_warehouse(workspace_id=self.id, warehouse_id=warehouse_id, warehouse_name=warehouse_name)
1316
743
 
1317
744
  def delete_warehouse(self, warehouse_id):
1318
745
  """Delete a warehouse from a workspace"""
1319
- return self.get_item(item_id=warehouse_id).delete(type="warehouses")
746
+ return self.core_client.delete_warehouse(workspace_id=self.id, warehouse_id=warehouse_id)
1320
747
 
1321
748
  def update_warehouse(self, warehouse_id, display_name = None, description = None):
1322
749
  """Update a warehouse in a workspace"""
1323
- return self.get_item(item_id=warehouse_id).update(display_name=display_name,
1324
- description=description,
1325
- type="warehouses")
1326
-
1327
-
1328
-
1329
- # spark workspace custom pools
1330
-
1331
- def list_workspace_custom_pools(self, continuationToken = None):
1332
- """List spark worspace custom pools in a workspace"""
1333
- # GET http://api.fabric.microsoft.com/v1/workspaces/f089354e-8366-4e18-aea3-4cb4a3a50b48/spark/pools
1334
-
1335
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/spark/pools"
1336
-
1337
- if continuationToken:
1338
- url = f"{url}?continuationToken={continuationToken}"
1339
-
1340
- for _ in range(10):
1341
- response = requests.get(url=url, headers=self.auth.get_headers())
1342
- if response.status_code == 429:
1343
- print("Too many requests, waiting 10 seconds")
1344
- sleep(10)
1345
- continue
1346
- if response.status_code not in (200, 429):
1347
- raise Exception(f"Error listing custom spark pools: {response.status_code}, {response.text}")
1348
- break
1349
-
1350
- resp_dict = json.loads(response.text)
1351
- items = resp_dict["value"]
1352
- for item in items:
1353
- item["workspaceId"] = self.id
1354
- sppools = [SparkCustomPool.from_dict(item, auth=self.auth) for item in items]
1355
-
1356
- if "continuationToken" in resp_dict:
1357
- item_list_next = self.list_workspace_custom_pools(continuationToken=resp_dict["continuationToken"])
1358
- sppools.extend(item_list_next)
1359
-
1360
- return sppools
1361
-
1362
- def create_workspace_custom_pool(self, name, node_family, node_size, auto_scale, dynamic_executor_allocation):
1363
- """Create a custom pool in a workspace"""
1364
-
1365
- # POST http://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/spark/pools
1366
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/spark/pools"
1367
-
1368
- body = {
1369
- "name": name,
1370
- "nodeFamily": node_family,
1371
- "nodeSize": node_size,
1372
- "autoScale": auto_scale,
1373
- "dynamicExecutorAllocation": dynamic_executor_allocation
1374
- }
1375
-
1376
- for _ in range(10):
1377
- response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
1378
- if response.status_code == 429:
1379
- print("Too many requests, waiting 10 seconds")
1380
- sleep(10)
1381
- continue
1382
- if response.status_code not in (200, 201, 429):
1383
- raise Exception(f"Error creating custom spark pool: {response.status_code}, {response.text}")
1384
- break
1385
-
1386
- response_dict = json.loads(response.text)
1387
- response_dict["workspaceId"] = self.id
1388
- return SparkCustomPool.from_dict(response_dict, auth=self.auth)
1389
-
1390
- def get_workspace_custom_pool(self, pool_id):
1391
- """Get a custom pool in a workspace"""
1392
- # GET http://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/spark/pools/{poolId}
1393
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/spark/pools/{pool_id}"
1394
-
1395
- for _ in range(10):
1396
- response = requests.get(url=url, headers=self.auth.get_headers())
1397
- if response.status_code == 429:
1398
- print("Too many requests, waiting 10 seconds")
1399
- sleep(10)
1400
- continue
1401
- if response.status_code not in (200, 429):
1402
- raise Exception(f"Error getting custom spark pool: {response.status_code}, {response.text}")
1403
- break
1404
-
1405
- response_dict = json.loads(response.text)
1406
- response_dict["workspaceId"] = self.id
1407
- return SparkCustomPool.from_dict(response_dict, auth=self.auth)
1408
-
1409
- def delete_workspace_custom_pool(self, pool_id):
1410
- """Delete a custom pool in a workspace"""
1411
- pool = self.get_workspace_custom_pool(pool_id)
1412
- return pool.delete()
1413
-
1414
- def update_workspace_custom_pool(self, pool_id, name = None , node_family = None, node_size = None,
1415
- auto_scale = None,
1416
- dynamic_executor_allocation = None):
1417
- """Update a custom pool in a workspace"""
1418
- pool = self.get_workspace_custom_pool(pool_id)
1419
- return pool.update(name = name,
1420
- node_family = node_family,
1421
- node_size = node_size,
1422
- auto_scale = auto_scale,
1423
- dynamic_executor_allocation = dynamic_executor_allocation)
1424
-
1425
- # spark workspace settings
1426
-
1427
- def get_spark_settings(self):
1428
-
1429
- # GET http://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/spark/settings
1430
-
1431
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/spark/settings"
1432
-
1433
- for _ in range(10):
1434
- response = requests.get(url=url, headers=self.auth.get_headers())
1435
- if response.status_code == 429:
1436
- print("Too many requests, waiting 10 seconds")
1437
- sleep(10)
1438
- continue
1439
- if response.status_code not in (200, 429):
1440
- raise Exception(f"Error getting spark settings: {response.status_code}, {response.text}")
1441
- break
1442
-
1443
- return json.loads(response.text)
1444
-
1445
-
1446
- def update_spark_settings(self, automatic_log = None, environment = None, high_concurrency = None, pool = None):
1447
-
1448
- # PATCH http://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/spark/settings
1449
-
1450
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/spark/settings"
1451
-
1452
- body = {}
1453
-
1454
- if automatic_log:
1455
- body["automaticLog"] = automatic_log
1456
- if environment:
1457
- body["environment"] = environment
1458
- if high_concurrency:
1459
- body["highConcurrency"] = high_concurrency
1460
- if pool:
1461
- body["pool"] = pool
1462
-
1463
- for _ in range(10):
1464
- response = requests.patch(url=url, headers=self.auth.get_headers(), json=body)
1465
- if response.status_code == 429:
1466
- print("Too many requests, waiting 10 seconds")
1467
- sleep(10)
1468
- continue
1469
- if response.status_code not in (200, 429):
1470
- raise Exception(f"Error updating spark settings: {response.status_code}, {response.text}")
1471
- break
1472
-
1473
- return json.loads(response.text)
1474
-
1475
- # External Data Shares
1476
-
1477
- # create
1478
-
1479
- def create_external_data_share(self, item_id, paths, recipient):
1480
- item = self.get_item(item_id=item_id)
1481
- return item.create_external_data_share(paths = paths, recipient = recipient)
1482
-
1483
- # get
1484
-
1485
- def get_external_data_share(self, item_id, external_data_share_id):
1486
- item = self.get_item(item_id=item_id)
1487
- return item.get_external_data_share(external_data_share_id=external_data_share_id)
1488
-
1489
-
1490
- # list
1491
-
1492
- def list_external_data_shares_in_item(self, item_id):
1493
- item = self.get_item(item_id=item_id)
1494
- return item.list_external_data_shares_in_item()
1495
-
1496
- # revoke
1497
-
1498
- def revoke_external_data_share(self, item_id, external_data_share_id):
1499
- item = self.get_item(item_id=item_id)
1500
- return item.revoke_external_data_share(external_data_share_id=external_data_share_id)
1501
-
1502
-
1503
- # One Lake Data Access Security
1504
-
1505
- # create and update
1506
-
1507
- def create_or_update_data_access_roles(self, item_id, data_access_roles, dryrun = False, etag_match = None):
1508
- item = self.get_item(item_id=item_id).create_or_update_data_access_roles(data_access_roles = data_access_roles,
1509
- dryrun = dryrun, etag_match = etag_match)
1510
- return item
1511
-
1512
- # list
1513
-
1514
- def list_data_access_roles(self, item_id):
1515
- item = self.get_item(item_id=item_id)
1516
- return item.list_data_access_roles()
750
+ return self.core_client.update_warehouse(workspace_id=self.id, warehouse_id=warehouse_id, display_name=display_name, description=description)