semantic-link-labs 0.9.5__py3-none-any.whl → 0.9.7__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.

Potentially problematic release.


This version of semantic-link-labs might be problematic. Click here for more details.

Files changed (65) hide show
  1. {semantic_link_labs-0.9.5.dist-info → semantic_link_labs-0.9.7.dist-info}/METADATA +8 -5
  2. {semantic_link_labs-0.9.5.dist-info → semantic_link_labs-0.9.7.dist-info}/RECORD +65 -61
  3. {semantic_link_labs-0.9.5.dist-info → semantic_link_labs-0.9.7.dist-info}/WHEEL +1 -1
  4. sempy_labs/__init__.py +19 -1
  5. sempy_labs/_ai.py +3 -1
  6. sempy_labs/_capacities.py +37 -2
  7. sempy_labs/_capacity_migration.py +11 -14
  8. sempy_labs/_connections.py +2 -4
  9. sempy_labs/_dataflows.py +2 -2
  10. sempy_labs/_dax_query_view.py +57 -0
  11. sempy_labs/_delta_analyzer.py +16 -14
  12. sempy_labs/_delta_analyzer_history.py +298 -0
  13. sempy_labs/_environments.py +8 -1
  14. sempy_labs/_eventhouses.py +5 -1
  15. sempy_labs/_external_data_shares.py +4 -10
  16. sempy_labs/_generate_semantic_model.py +2 -1
  17. sempy_labs/_graphQL.py +5 -1
  18. sempy_labs/_helper_functions.py +440 -63
  19. sempy_labs/_icons.py +6 -6
  20. sempy_labs/_kql_databases.py +5 -1
  21. sempy_labs/_list_functions.py +8 -38
  22. sempy_labs/_managed_private_endpoints.py +9 -2
  23. sempy_labs/_mirrored_databases.py +3 -1
  24. sempy_labs/_ml_experiments.py +1 -1
  25. sempy_labs/_model_bpa.py +2 -11
  26. sempy_labs/_model_bpa_bulk.py +33 -38
  27. sempy_labs/_model_bpa_rules.py +1 -1
  28. sempy_labs/_one_lake_integration.py +2 -1
  29. sempy_labs/_semantic_models.py +20 -0
  30. sempy_labs/_sql.py +6 -2
  31. sempy_labs/_sqldatabase.py +61 -100
  32. sempy_labs/_vertipaq.py +8 -11
  33. sempy_labs/_warehouses.py +14 -3
  34. sempy_labs/_workspace_identity.py +6 -0
  35. sempy_labs/_workspaces.py +42 -2
  36. sempy_labs/admin/_basic_functions.py +29 -2
  37. sempy_labs/admin/_reports.py +1 -1
  38. sempy_labs/admin/_scanner.py +2 -4
  39. sempy_labs/admin/_tenant.py +8 -3
  40. sempy_labs/directlake/_directlake_schema_compare.py +2 -1
  41. sempy_labs/directlake/_directlake_schema_sync.py +65 -19
  42. sempy_labs/directlake/_dl_helper.py +0 -6
  43. sempy_labs/directlake/_generate_shared_expression.py +19 -12
  44. sempy_labs/directlake/_guardrails.py +2 -1
  45. sempy_labs/directlake/_update_directlake_model_lakehouse_connection.py +90 -57
  46. sempy_labs/directlake/_update_directlake_partition_entity.py +5 -2
  47. sempy_labs/graph/_groups.py +6 -0
  48. sempy_labs/graph/_teams.py +2 -0
  49. sempy_labs/graph/_users.py +4 -0
  50. sempy_labs/lakehouse/__init__.py +12 -3
  51. sempy_labs/lakehouse/_blobs.py +231 -0
  52. sempy_labs/lakehouse/_shortcuts.py +29 -8
  53. sempy_labs/migration/_direct_lake_to_import.py +47 -10
  54. sempy_labs/migration/_migration_validation.py +0 -4
  55. sempy_labs/report/__init__.py +4 -0
  56. sempy_labs/report/_download_report.py +4 -6
  57. sempy_labs/report/_generate_report.py +6 -6
  58. sempy_labs/report/_report_functions.py +5 -4
  59. sempy_labs/report/_report_helper.py +17 -5
  60. sempy_labs/report/_report_rebind.py +8 -6
  61. sempy_labs/report/_reportwrapper.py +17 -8
  62. sempy_labs/report/_save_report.py +147 -0
  63. sempy_labs/tom/_model.py +154 -23
  64. {semantic_link_labs-0.9.5.dist-info → semantic_link_labs-0.9.7.dist-info/licenses}/LICENSE +0 -0
  65. {semantic_link_labs-0.9.5.dist-info → semantic_link_labs-0.9.7.dist-info}/top_level.txt +0 -0
@@ -1,70 +1,69 @@
1
- import sempy.fabric as fabric
2
1
  from sempy_labs._helper_functions import (
3
2
  resolve_workspace_name_and_id,
4
3
  _base_api,
5
4
  _create_dataframe,
6
5
  _update_dataframe_datatypes,
6
+ create_item,
7
+ delete_item,
7
8
  )
8
9
  import pandas as pd
9
10
  from typing import Optional
10
- import sempy_labs._icons as icons
11
11
  from uuid import UUID
12
12
 
13
- ## Still debugging the creation of an sql database
14
- # def create_warehouse(
15
- # warehouse: str,
16
- # description: Optional[str] = None,
17
- # case_insensitive_collation: bool = False,
18
- # workspace: Optional[str | UUID] = None,
19
- # ):
20
- # """
21
- # Creates a Fabric warehouse.
22
-
23
- # This is a wrapper function for the following API: `Items - Create Warehouse <https://learn.microsoft.com/rest/api/fabric/warehouse/items/create-warehouse>`_.
24
-
25
- # Parameters
26
- # ----------
27
- # warehouse: str
28
- # Name of the warehouse.
29
- # description : str, default=None
30
- # A description of the warehouse.
31
- # case_insensitive_collation: bool, default=False
32
- # If True, creates the warehouse with case-insensitive collation.
33
- # workspace : str | uuid.UUID, default=None
34
- # The Fabric workspace name or ID.
35
- # Defaults to None which resolves to the workspace of the attached lakehouse
36
- # or if no lakehouse attached, resolves to the workspace of the notebook.
37
- # """
38
-
39
- # (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
40
-
41
- # payload = {"displayName": warehouse}
42
-
43
- # if description:
44
- # payload["description"] = description
45
- # if case_insensitive_collation:
46
- # payload.setdefault("creationPayload", {})
47
- # payload["creationPayload"][
48
- # "defaultCollation"
49
- # ] = "Latin1_General_100_CI_AS_KS_WS_SC_UTF8"
50
-
51
- # _base_api(
52
- # request=f"/v1/workspaces/{workspace_id}/warehouses",
53
- # payload=payload,
54
- # method="post",
55
- # lro_return_status_code=True,
56
- # status_codes=[201, 202],
57
- # )
58
-
59
- # print(
60
- # f"{icons.green_dot} The '{warehouse}' warehouse has been created within the '{workspace_name}' workspace."
61
- # )
62
-
63
-
64
- def _list_sql_databases(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
13
+
14
+ def create_sql_database(
15
+ name: str, description: Optional[str] = None, workspace: Optional[str | UUID] = None
16
+ ):
17
+ """
18
+ Creates a SQL database.
19
+
20
+ This is a wrapper function for the following API: `Items - Create SQL Database <https://learn.microsoft.com/rest/api/fabric/sqldatabase/items/create-sql-database>`_.
21
+
22
+ Parameters
23
+ ----------
24
+ name: str
25
+ Name of the SQL database.
26
+ description : str, default=None
27
+ A description of the SQL database.
28
+ workspace : str | uuid.UUID, default=None
29
+ The Fabric workspace name or ID.
30
+ Defaults to None which resolves to the workspace of the attached lakehouse
31
+ or if no lakehouse attached, resolves to the workspace of the notebook.
32
+ """
33
+
34
+ create_item(
35
+ name=name, description=description, type="SQLDatabase", workspace=workspace
36
+ )
37
+
38
+
39
+ def delete_sql_database(
40
+ sql_database: str | UUID, workspace: Optional[str | UUID] = None
41
+ ):
42
+ """
43
+ Deletes a SQL Database.
44
+
45
+ This is a wrapper function for the following API: `Items - Delete SQL Database <https://learn.microsoft.com/rest/api/fabric/sqldatabase/items/delete-sql-database>`_.
46
+
47
+ Parameters
48
+ ----------
49
+ sql_database: str | uuid.UUID
50
+ Name of the SQL database.
51
+ workspace : str | uuid.UUID, default=None
52
+ The Fabric workspace name or ID.
53
+ Defaults to None which resolves to the workspace of the attached lakehouse
54
+ or if no lakehouse attached, resolves to the workspace of the notebook.
65
55
  """
66
- Shows the databses within a workspace.
67
56
 
57
+ delete_item(item=sql_database, type="SQLDatabase", workspace=workspace)
58
+
59
+
60
+ def list_sql_databases(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
61
+ """
62
+ Lists all SQL databases in the Fabric workspace.
63
+
64
+ This is a wrapper function for the following API: `Items - List SQL Databases <https://learn.microsoft.com/rest/api/fabric/sqldatabase/items/list-sql-databases>`_.
65
+
66
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
68
67
 
69
68
  Parameters
70
69
  ----------
@@ -76,45 +75,39 @@ def _list_sql_databases(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
76
75
  Returns
77
76
  -------
78
77
  pandas.DataFrame
79
- A pandas dataframe showing the SQLDabatases within a workspace.
78
+ A pandas dataframe showing a list of SQL databases in the Fabric workspace.
80
79
  """
81
80
 
81
+ (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
82
+
82
83
  columns = {
83
84
  "SQL Database Name": "string",
84
85
  "SQL Database Id": "string",
85
86
  "Description": "string",
86
- "Connection Type": "string",
87
87
  "Connection Info": "string",
88
88
  "Database Name": "string",
89
89
  "Server FQDN": "string",
90
- "Provisioning Status": "string",
91
- "Created Date": "datetime",
92
- "Last Updated Time UTC": "datetime",
93
90
  }
94
91
  df = _create_dataframe(columns=columns)
95
92
 
96
- (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
97
-
98
93
  responses = _base_api(
99
- request=f"/v1/workspaces/{workspace_id}/sqldatabases", uses_pagination=True
94
+ request=f"/v1/workspaces/{workspace_id}/SQLDatabases",
95
+ uses_pagination=True,
96
+ client="fabric_sp",
100
97
  )
101
98
 
102
99
  for r in responses:
103
100
  for v in r.get("value", []):
104
101
  prop = v.get("properties", {})
105
-
106
102
  new_data = {
107
103
  "SQL Database Name": v.get("displayName"),
108
104
  "SQL Database Id": v.get("id"),
109
105
  "Description": v.get("description"),
110
- "Connection Type": v.get("type"),
111
106
  "Connection Info": prop.get("connectionInfo"),
112
107
  "Database Name": prop.get("databaseName"),
113
108
  "Server FQDN": prop.get("serverFqdn"),
114
- "Provisioning Status": prop.get("provisioningState"),
115
- "Created Date": prop.get("createdDate"),
116
- "Last Updated Time UTC": prop.get("lastUpdatedTimeUtc"),
117
109
  }
110
+
118
111
  df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
119
112
 
120
113
  _update_dataframe_datatypes(dataframe=df, column_map=columns)
@@ -122,38 +115,6 @@ def _list_sql_databases(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
122
115
  return df
123
116
 
124
117
 
125
- ## Still debugging the deletion of an sql database
126
- # def delete_warehouse(name: str, workspace: Optional[str | UUID] = None):
127
- # """
128
- # Deletes a Fabric warehouse.
129
-
130
- # This is a wrapper function for the following API: `Items - Delete Warehouse <https://learn.microsoft.com/rest/api/fabric/warehouse/items/delete-warehouse>`_.
131
-
132
- # Parameters
133
- # ----------
134
- # name: str
135
- # Name of the warehouse.
136
- # workspace : str | uuid.UUID, default=None
137
- # The Fabric workspace name or ID.
138
- # Defaults to None which resolves to the workspace of the attached lakehouse
139
- # or if no lakehouse attached, resolves to the workspace of the notebook.
140
- # """
141
-
142
- # (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
143
-
144
- # item_id = fabric.resolve_item_id(
145
- # item_name=name, type="Warehouse", workspace=workspace_id
146
- # )
147
-
148
- # _base_api(
149
- # request=f"/v1/workspaces/{workspace_id}/warehouses/{item_id}", method="delete"
150
- # )
151
-
152
- # print(
153
- # f"{icons.green_dot} The '{name}' warehouse within the '{workspace_name}' workspace has been deleted."
154
- # )
155
-
156
-
157
118
  def get_sql_database_tables(
158
119
  sql_database: str | UUID, workspace: Optional[str | UUID] = None
159
120
  ) -> pd.DataFrame:
sempy_labs/_vertipaq.py CHANGED
@@ -15,6 +15,8 @@ from sempy_labs._helper_functions import (
15
15
  resolve_workspace_name_and_id,
16
16
  resolve_dataset_name_and_id,
17
17
  _create_spark_session,
18
+ resolve_workspace_id,
19
+ resolve_workspace_name,
18
20
  )
19
21
  from sempy_labs._list_functions import list_relationships, list_tables
20
22
  from sempy_labs.lakehouse import lakehouse_attached, get_lakehouse_tables
@@ -196,8 +198,10 @@ def vertipaq_analyzer(
196
198
  & (~dfC["Column Name"].str.startswith("RowNumber-"))
197
199
  ]
198
200
 
199
- object_workspace = fabric.resolve_workspace_name(lakehouse_workspace_id)
200
- current_workspace_id = fabric.get_workspace_id()
201
+ object_workspace = resolve_workspace_name(
202
+ workspace_id=lakehouse_workspace_id
203
+ )
204
+ current_workspace_id = resolve_workspace_id()
201
205
  if current_workspace_id != lakehouse_workspace_id:
202
206
  lakeTables = get_lakehouse_tables(
203
207
  lakehouse=lakehouse_name, workspace=object_workspace
@@ -526,22 +530,15 @@ def vertipaq_analyzer(
526
530
  )
527
531
 
528
532
  if export == "table":
529
- lakehouse_id = fabric.get_lakehouse_id()
530
- lake_workspace = fabric.resolve_workspace_name()
531
- lakehouse = resolve_lakehouse_name(
532
- lakehouse_id=lakehouse_id, workspace=lake_workspace
533
- )
534
533
  lakeTName = "vertipaqanalyzer_model"
535
534
 
536
- lakeT = get_lakehouse_tables(lakehouse=lakehouse, workspace=lake_workspace)
535
+ lakeT = get_lakehouse_tables()
537
536
  lakeT_filt = lakeT[lakeT["Table Name"] == lakeTName]
538
537
 
539
538
  if len(lakeT_filt) == 0:
540
539
  runId = 1
541
540
  else:
542
- max_run_id = _get_column_aggregate(
543
- lakehouse=lakehouse, table_name=lakeTName
544
- )
541
+ max_run_id = _get_column_aggregate(table_name=lakeTName)
545
542
  runId = max_run_id + 1
546
543
 
547
544
  dfMap = {
sempy_labs/_warehouses.py CHANGED
@@ -16,7 +16,7 @@ def create_warehouse(
16
16
  description: Optional[str] = None,
17
17
  case_insensitive_collation: bool = False,
18
18
  workspace: Optional[str | UUID] = None,
19
- ):
19
+ ) -> UUID:
20
20
  """
21
21
  Creates a Fabric warehouse.
22
22
 
@@ -34,6 +34,11 @@ def create_warehouse(
34
34
  The Fabric workspace name or ID.
35
35
  Defaults to None which resolves to the workspace of the attached lakehouse
36
36
  or if no lakehouse attached, resolves to the workspace of the notebook.
37
+
38
+ Returns
39
+ -------
40
+ uuid.UUID
41
+ The ID of the created warehouse.
37
42
  """
38
43
 
39
44
  (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
@@ -48,7 +53,7 @@ def create_warehouse(
48
53
  "defaultCollation"
49
54
  ] = "Latin1_General_100_CI_AS_KS_WS_SC_UTF8"
50
55
 
51
- _base_api(
56
+ response = _base_api(
52
57
  request=f"/v1/workspaces/{workspace_id}/warehouses",
53
58
  payload=payload,
54
59
  method="post",
@@ -60,6 +65,8 @@ def create_warehouse(
60
65
  f"{icons.green_dot} The '{warehouse}' warehouse has been created within the '{workspace_name}' workspace."
61
66
  )
62
67
 
68
+ return response.get("id")
69
+
63
70
 
64
71
  def list_warehouses(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
65
72
  """
@@ -67,6 +74,8 @@ def list_warehouses(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
67
74
 
68
75
  This is a wrapper function for the following API: `Items - List Warehouses <https://learn.microsoft.com/rest/api/fabric/warehouse/items/list-warehouses>`_.
69
76
 
77
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
78
+
70
79
  Parameters
71
80
  ----------
72
81
  workspace : str | uuid.UUID, default=None
@@ -93,7 +102,9 @@ def list_warehouses(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
93
102
  (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
94
103
 
95
104
  responses = _base_api(
96
- request=f"/v1/workspaces/{workspace_id}/warehouses", uses_pagination=True
105
+ request=f"/v1/workspaces/{workspace_id}/warehouses",
106
+ uses_pagination=True,
107
+ client="fabric_sp",
97
108
  )
98
109
 
99
110
  for r in responses:
@@ -13,6 +13,8 @@ def provision_workspace_identity(workspace: Optional[str | UUID] = None):
13
13
 
14
14
  This is a wrapper function for the following API: `Workspaces - Provision Identity <https://learn.microsoft.com/rest/api/fabric/core/workspaces/provision-identity>`_.
15
15
 
16
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
17
+
16
18
  Parameters
17
19
  ----------
18
20
  workspace : str | uuid.UUID, default=None
@@ -28,6 +30,7 @@ def provision_workspace_identity(workspace: Optional[str | UUID] = None):
28
30
  method="post",
29
31
  lro_return_status_code=True,
30
32
  status_codes=None,
33
+ client="fabric_sp",
31
34
  )
32
35
 
33
36
  print(
@@ -41,6 +44,8 @@ def deprovision_workspace_identity(workspace: Optional[str | UUID] = None):
41
44
 
42
45
  This is a wrapper function for the following API: `Workspaces - Derovision Identity <https://learn.microsoft.com/rest/api/fabric/core/workspaces/deprovision-identity>`_.
43
46
 
47
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
48
+
44
49
  Parameters
45
50
  ----------
46
51
  workspace : str | uuid.UUID, default=None
@@ -56,6 +61,7 @@ def deprovision_workspace_identity(workspace: Optional[str | UUID] = None):
56
61
  method="post",
57
62
  lro_return_status_code=True,
58
63
  status_codes=None,
64
+ client="fabric_sp",
59
65
  )
60
66
 
61
67
  print(
sempy_labs/_workspaces.py CHANGED
@@ -18,6 +18,8 @@ def delete_user_from_workspace(
18
18
 
19
19
  This is a wrapper function for the following API: `Groups - Delete User In Group <https://learn.microsoft.com/rest/api/power-bi/groups/delete-user-in-group>`_.
20
20
 
21
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
22
+
21
23
  Parameters
22
24
  ----------
23
25
  email_address : str
@@ -33,6 +35,7 @@ def delete_user_from_workspace(
33
35
  _base_api(
34
36
  request=f"/v1.0/myorg/groups/{workspace_id}/users/{email_address}",
35
37
  method="delete",
38
+ client="fabric_sp",
36
39
  )
37
40
  print(
38
41
  f"{icons.green_dot} The '{email_address}' user has been removed from accessing the '{workspace_name}' workspace."
@@ -50,6 +53,8 @@ def update_workspace_user(
50
53
 
51
54
  This is a wrapper function for the following API: `Groups - Update Group User <https://learn.microsoft.com/rest/api/power-bi/groups/update-group-user>`_.
52
55
 
56
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
57
+
53
58
  Parameters
54
59
  ----------
55
60
  email_address : str
@@ -90,6 +95,7 @@ def update_workspace_user(
90
95
  request=f"/v1.0/myorg/groups/{workspace_id}/users",
91
96
  method="put",
92
97
  payload=payload,
98
+ client="fabric_sp",
93
99
  )
94
100
  print(
95
101
  f"{icons.green_dot} The '{email_address}' user has been updated to a '{role_name}' within the '{workspace_name}' workspace."
@@ -102,6 +108,8 @@ def list_workspace_users(workspace: Optional[str | UUID] = None) -> pd.DataFrame
102
108
 
103
109
  This is a wrapper function for the following API: `Workspaces - List Workspace Role Assignments <https://learn.microsoft.com/rest/api/fabric/core/workspaces/list-workspace-role-assignments>`_.
104
110
 
111
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
112
+
105
113
  Parameters
106
114
  ----------
107
115
  workspace : str | uuid.UUID, default=None
@@ -127,7 +135,9 @@ def list_workspace_users(workspace: Optional[str | UUID] = None) -> pd.DataFrame
127
135
  df = _create_dataframe(columns=columns)
128
136
 
129
137
  responses = _base_api(
130
- request=f"v1/workspaces/{workspace_id}/roleAssignments", uses_pagination=True
138
+ request=f"v1/workspaces/{workspace_id}/roleAssignments",
139
+ uses_pagination=True,
140
+ client="fabric_sp",
131
141
  )
132
142
 
133
143
  for r in responses:
@@ -251,6 +261,8 @@ def unassign_workspace_from_capacity(workspace: Optional[str | UUID] = None):
251
261
 
252
262
  This is a wrapper function for the following API: `Workspaces - Unassign From Capacity <https://learn.microsoft.com/rest/api/fabric/core/workspaces/unassign-from-capacity>`_.
253
263
 
264
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
265
+
254
266
  Parameters
255
267
  ----------
256
268
  workspace : str | uuid.UUID, default=None
@@ -265,6 +277,7 @@ def unassign_workspace_from_capacity(workspace: Optional[str | UUID] = None):
265
277
  request=f"/v1/workspaces/{workspace_id}/unassignFromCapacity",
266
278
  method="post",
267
279
  status_codes=[200, 202],
280
+ client="fabric_sp",
268
281
  )
269
282
  print(
270
283
  f"{icons.green_dot} The '{workspace_name}' workspace has been unassigned from its capacity."
@@ -279,6 +292,8 @@ def list_workspace_role_assignments(
279
292
 
280
293
  This is a wrapper function for the following API: `Workspaces - List Workspace Role Assignments <https://learn.microsoft.com/rest/api/fabric/core/workspaces/list-workspace-role-assignments>`_.
281
294
 
295
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
296
+
282
297
  Parameters
283
298
  ----------
284
299
  workspace : str | uuid.UUID, default=None
@@ -303,7 +318,9 @@ def list_workspace_role_assignments(
303
318
  df = _create_dataframe(columns=columns)
304
319
 
305
320
  responses = _base_api(
306
- request=f"v1/workspaces/{workspace_id}/roleAssignments", uses_pagination=True
321
+ request=f"v1/workspaces/{workspace_id}/roleAssignments",
322
+ uses_pagination=True,
323
+ client="fabric_sp",
307
324
  )
308
325
 
309
326
  for r in responses:
@@ -318,3 +335,26 @@ def list_workspace_role_assignments(
318
335
  df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
319
336
 
320
337
  return df
338
+
339
+
340
+ def delete_workspace(workspace: Optional[str | UUID] = None):
341
+ """
342
+ Deletes a workspace.
343
+
344
+ This is a wrapper function for the following API: `Workspaces - Delete Workspace <https://learn.microsoft.com/rest/api/fabric/core/workspaces/delete-workspace>`_.
345
+
346
+ Parameters
347
+ ----------
348
+ workspace : str | uuid.UUID, default=None
349
+ The Fabric workspace name or ID.
350
+ Defaults to None which resolves to the workspace of the attached lakehouse
351
+ or if no lakehouse attached, resolves to the workspace of the notebook.
352
+ """
353
+
354
+ (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
355
+
356
+ _base_api(
357
+ request=f"v1/workspaces/{workspace_id}", method="delete", client="fabric_sp"
358
+ )
359
+
360
+ print(f"{icons.green_dot} The '{workspace_name}' workspace has been deleted.")
@@ -350,13 +350,40 @@ def list_workspace_access_details(
350
350
  return df
351
351
 
352
352
 
353
+ def _resolve_workspace_name(workspace_id: Optional[UUID] = None) -> str:
354
+ from sempy_labs._helper_functions import _get_fabric_context_setting
355
+ from sempy.fabric.exceptions import FabricHTTPException
356
+
357
+ if workspace_id is None:
358
+ workspace_id = _get_fabric_context_setting(name="trident.workspace.id")
359
+
360
+ try:
361
+ workspace_name = (
362
+ _base_api(
363
+ request=f"/v1/admin/workspaces/{workspace_id}", client="fabric_sp"
364
+ )
365
+ .json()
366
+ .get("name")
367
+ )
368
+ except FabricHTTPException:
369
+ raise ValueError(
370
+ f"{icons.red_dot} The '{workspace_id}' workspace was not found."
371
+ )
372
+ return workspace_name
373
+
374
+
353
375
  def _resolve_workspace_name_and_id(
354
376
  workspace: str | UUID,
355
377
  ) -> Tuple[str, UUID]:
356
378
 
379
+ from sempy_labs._helper_functions import _get_fabric_context_setting
380
+
357
381
  if workspace is None:
358
- workspace_id = fabric.get_workspace_id()
359
- workspace_name = fabric.resolve_workspace_name(workspace_id)
382
+ workspace_id = _get_fabric_context_setting(name="trident.workspace.id")
383
+ workspace_name = _resolve_workspace_name(workspace_id)
384
+ elif _is_valid_uuid(workspace):
385
+ workspace_id = workspace
386
+ workspace_name = _resolve_workspace_name(workspace_id)
360
387
  else:
361
388
  dfW = list_workspaces(workspace=workspace)
362
389
  if not dfW.empty:
@@ -113,7 +113,7 @@ def list_report_users(report: str | UUID) -> pd.DataFrame:
113
113
  """
114
114
  Shows a list of users that have access to the specified report.
115
115
 
116
- This is a wrapper function for the following API: `Admin - Reports GetDatasetUsersAsAdmin <https://learn.microsoft.com/rest/api/power-bi/admin/datasets-get-report-users-as-admin>`_.
116
+ This is a wrapper function for the following API: `Admin - Reports GetDatasetUsersAsAdmin <https://learn.microsoft.com/rest/api/power-bi/admin/reports-get-report-users-as-admin>`_.
117
117
 
118
118
  Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
119
119
 
@@ -1,4 +1,3 @@
1
- import sempy.fabric as fabric
2
1
  from typing import Optional, List
3
2
  from uuid import UUID
4
3
  from sempy.fabric.exceptions import FabricHTTPException
@@ -10,6 +9,7 @@ from sempy_labs._helper_functions import (
10
9
  _base_api,
11
10
  _is_valid_uuid,
12
11
  _build_url,
12
+ resolve_workspace_name,
13
13
  )
14
14
 
15
15
 
@@ -54,7 +54,7 @@ def scan_workspaces(
54
54
  """
55
55
 
56
56
  if workspace is None:
57
- workspace = fabric.resolve_workspace_name()
57
+ workspace = resolve_workspace_name()
58
58
 
59
59
  if isinstance(workspace, str):
60
60
  workspace = [workspace]
@@ -115,6 +115,4 @@ def scan_workspaces(
115
115
  client="fabric_sp",
116
116
  )
117
117
 
118
- print(f"{icons.green_dot} Status: {scan_status}")
119
-
120
118
  return response.json()
@@ -126,11 +126,10 @@ def list_capacity_tenant_settings_overrides(
126
126
  if capacity_id is None:
127
127
  # If capacity_id is None, we access 'Overrides' -> 'tenantSettings'
128
128
  for override in r.get("overrides", []):
129
+ capacity_id = override.get("id")
129
130
  tenant_settings = override.get("tenantSettings", [])
130
131
  for setting in tenant_settings:
131
- data.append(
132
- create_new_data(setting)
133
- ) # No capacity_id needed here
132
+ data.append(create_new_data(setting, capacity_id))
134
133
  else:
135
134
  # If capacity_id is provided, we access 'value' directly for tenantSettings
136
135
  for setting in r.get("value", []):
@@ -391,6 +390,7 @@ def list_workspaces_tenant_settings_overrides() -> pd.DataFrame:
391
390
  """
392
391
 
393
392
  columns = {
393
+ "Workspace Id": "string",
394
394
  "Setting Name": "string",
395
395
  "Title": "string",
396
396
  "Enabled": "bool",
@@ -409,8 +409,10 @@ def list_workspaces_tenant_settings_overrides() -> pd.DataFrame:
409
409
 
410
410
  for r in responses:
411
411
  for v in r.get("value", []):
412
+ workspace_id = v.get("id")
412
413
  for setting in v.get("tenantSettings", []):
413
414
  new_data = {
415
+ "Workspace Id": workspace_id,
414
416
  "Setting Name": setting.get("settingName"),
415
417
  "Title": setting.get("title"),
416
418
  "Enabled": setting.get("enabled"),
@@ -447,6 +449,7 @@ def list_domain_tenant_settings_overrides() -> pd.DataFrame:
447
449
  """
448
450
 
449
451
  columns = {
452
+ "Domain Id": "string",
450
453
  "Setting Name": "string",
451
454
  "Title": "string",
452
455
  "Enabled": "bool",
@@ -466,8 +469,10 @@ def list_domain_tenant_settings_overrides() -> pd.DataFrame:
466
469
 
467
470
  for r in responses:
468
471
  for v in r.get("value", []):
472
+ domain_id = v.get("id")
469
473
  for setting in v.get("tenantSettings", []):
470
474
  new_data = {
475
+ "Domain Id": domain_id,
471
476
  "Setting Name": setting.get("settingName"),
472
477
  "Title": setting.get("title"),
473
478
  "Enabled": setting.get("enabled"),
@@ -4,6 +4,7 @@ from sempy_labs._helper_functions import (
4
4
  format_dax_object_name,
5
5
  resolve_workspace_name_and_id,
6
6
  resolve_dataset_name_and_id,
7
+ resolve_workspace_name,
7
8
  )
8
9
  from IPython.display import display
9
10
  from sempy_labs.lakehouse import get_lakehouse_columns
@@ -70,7 +71,7 @@ def direct_lake_schema_compare(
70
71
  f"{icons.red_dot} This function only supports Direct Lake semantic models where the source lakehouse resides in the same workpace as the semantic model."
71
72
  )
72
73
 
73
- lakehouse_workspace = fabric.resolve_workspace_name(lakehouse_workspace_id)
74
+ lakehouse_workspace = resolve_workspace_name(workspace_id=lakehouse_workspace_id)
74
75
  dfT = fabric.list_tables(dataset=dataset_id, workspace=workspace_id)
75
76
  dfC = fabric.list_columns(dataset=dataset_id, workspace=workspace_id)
76
77
  lc = get_lakehouse_columns(lakehouse_name, lakehouse_workspace)