Skip to content

Commit 4c5cbe8

Browse files
authored
added delete_semantic_model (#557)
* added delete_semantic_model * added delete_workspace * added fabric_sp * date * added sql_database functions * fabric_sp * clean * list_capacities * black * fix * added schema to get_delta_table_history * support SP * black * updated sqldatabase * fixed sql
1 parent 2715e9d commit 4c5cbe8

22 files changed

+256
-172
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ An even better way to ensure the semantic-link-labs library is available in your
123123
2. Select your newly created environment within the 'Environment' drop down in the navigation bar at the top of the notebook
124124

125125
## Version History
126-
* [0.9.6](https://github.com/microsoft/semantic-link-labs/releases/tag/0.9.6) (March 11, 2025)
126+
* [0.9.6](https://github.com/microsoft/semantic-link-labs/releases/tag/0.9.6) (March 12, 2025)
127127
* [0.9.5](https://github.com/microsoft/semantic-link-labs/releases/tag/0.9.5) (March 7, 2025)
128128
* [0.9.4](https://github.com/microsoft/semantic-link-labs/releases/tag/0.9.4) (February 27, 2025)
129129
* [0.9.3](https://github.com/microsoft/semantic-link-labs/releases/tag/0.9.3) (February 13, 2025)

src/sempy_labs/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from sempy_labs._semantic_models import (
1111
get_semantic_model_refresh_schedule,
1212
enable_semantic_model_scheduled_refresh,
13+
delete_semantic_model,
1314
)
1415
from sempy_labs._graphQL import (
1516
list_graphql_apis,
@@ -151,6 +152,7 @@
151152
create_or_update_resource_group,
152153
list_resource_groups,
153154
get_resource_group,
155+
list_capacities,
154156
)
155157
from sempy_labs._spark import (
156158
get_spark_settings,
@@ -168,6 +170,7 @@
168170
assign_workspace_to_capacity,
169171
unassign_workspace_from_capacity,
170172
list_workspace_role_assignments,
173+
delete_workspace,
171174
)
172175
from sempy_labs._notebooks import (
173176
get_notebook_definition,
@@ -183,6 +186,9 @@
183186
from sempy_labs._sqldatabase import (
184187
get_sql_database_columns,
185188
get_sql_database_tables,
189+
create_sql_database,
190+
delete_sql_database,
191+
list_sql_databases,
186192
)
187193
from sempy_labs._workspace_identity import (
188194
provision_workspace_identity,
@@ -247,7 +253,6 @@
247253
list_semantic_model_objects,
248254
list_shortcuts,
249255
get_object_level_security,
250-
list_capacities,
251256
list_datamarts,
252257
list_lakehouses,
253258
list_sql_endpoints,
@@ -544,4 +549,9 @@
544549
"get_mounted_data_factory_definition",
545550
"delete_mounted_data_factory",
546551
"generate_dax_query_view_url",
552+
"delete_semantic_model",
553+
"delete_workspace",
554+
"create_sql_database",
555+
"delete_sql_database",
556+
"list_sql_databases",
547557
]

src/sempy_labs/_capacities.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def list_vcores() -> pd.DataFrame:
242242

243243
def get_capacity_resource_governance(capacity_name: str):
244244

245-
dfC = fabric.list_capacities()
245+
dfC = list_capacities()
246246
dfC_filt = dfC[dfC["Display Name"] == capacity_name]
247247
capacity_id = dfC_filt["Id"].iloc[0].upper()
248248

@@ -1131,3 +1131,39 @@ def get_resource_group(azure_subscription_id: str, resource_group: str) -> pd.Da
11311131
}
11321132

11331133
return pd.DataFrame(new_data, index=[0])
1134+
1135+
1136+
def list_capacities() -> pd.DataFrame:
1137+
"""
1138+
Shows the capacities and their properties.
1139+
1140+
Returns
1141+
-------
1142+
pandas.DataFrame
1143+
A pandas dataframe showing the capacities and their properties
1144+
"""
1145+
1146+
columns = {
1147+
"Id": "string",
1148+
"Display Name": "string",
1149+
"Sku": "string",
1150+
"Region": "string",
1151+
"State": "string",
1152+
"Admins": "string",
1153+
}
1154+
df = _create_dataframe(columns=columns)
1155+
1156+
response = _base_api(request="/v1.0/myorg/capacities", client="fabric_sp")
1157+
1158+
for i in response.json().get("value", []):
1159+
new_data = {
1160+
"Id": i.get("id").lower(),
1161+
"Display Name": i.get("displayName"),
1162+
"Sku": i.get("sku"),
1163+
"Region": i.get("region"),
1164+
"State": i.get("state"),
1165+
"Admins": [i.get("admins", [])],
1166+
}
1167+
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
1168+
1169+
return df

src/sempy_labs/_capacity_migration.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,25 @@ def migrate_workspaces(
106106
migrated_workspaces = []
107107

108108
for i, r in dfW.iterrows():
109-
workspace = r["Name"]
110-
111-
if workspaces is None or workspace in workspaces:
112-
pass
113-
else:
114-
continue
115-
116-
if assign_workspace_to_capacity(capacity=target_capacity, workspace=workspace):
117-
migrated_workspaces.append(workspace)
109+
workspace_id = r["Id"]
110+
workspace_name = r["Name"]
111+
if workspaces is None or workspace_name in workspaces:
112+
assign_workspace_to_capacity(
113+
capacity=target_capacity, workspace=workspace_id
114+
)
115+
migrated_workspaces.append(workspace_name)
118116

119117
if len(migrated_workspaces) < workspace_count:
120118
print(
121119
f"{icons.warning} Not all workspaces in the '{source_capacity}' capacity were migrated to the '{target_capacity}' capacity."
122120
)
123121
print(f"{icons.in_progress} Initiating rollback...")
124122
for i, r in dfW.iterrows():
125-
workspace = r["Name"]
126-
if workspace in migrated_workspaces:
123+
workspace_id = r["Id"]
124+
workspace_name = r["Name"]
125+
if workspace_name in migrated_workspaces:
127126
assign_workspace_to_capacity(
128-
capacity=source_capacity, workspace=workspace
127+
capacity=source_capacity, workspace=workspace_id
129128
)
130129
print(
131130
f"{icons.green_dot} Rollback of the workspaces to the '{source_capacity}' capacity is complete."

src/sempy_labs/_connections.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sempy.fabric as fabric
21
import pandas as pd
32
from typing import Optional
43
from sempy_labs._helper_functions import (

src/sempy_labs/_delta_analyzer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def get_delta_table_history(
429429
table_name: str,
430430
lakehouse: Optional[str | UUID] = None,
431431
workspace: Optional[str | UUID] = None,
432+
schema: Optional[str] = None,
432433
) -> pd.DataFrame:
433434
"""
434435
Returns the history of a delta table as a pandas dataframe.
@@ -444,6 +445,8 @@ def get_delta_table_history(
444445
The Fabric workspace name or ID used by the lakehouse.
445446
Defaults to None which resolves to the workspace of the attached lakehouse
446447
or if no lakehouse attached, resolves to the workspace of the notebook.
448+
schema : str, default=None
449+
The name of the schema to which the table belongs (for schema-enabled lakehouses). If None, the default schema is used.
447450
448451
Returns
449452
-------
@@ -460,7 +463,7 @@ def camel_to_title(text):
460463
(lakehouse_name, lakehouse_id) = resolve_lakehouse_name_and_id(
461464
lakehouse=lakehouse, workspace=workspace
462465
)
463-
path = create_abfss_path(lakehouse_id, workspace_id, table_name)
466+
path = create_abfss_path(lakehouse_id, workspace_id, table_name, schema)
464467

465468
from delta import DeltaTable
466469

src/sempy_labs/_environments.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def list_environments(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
4848
4949
This is a wrapper function for the following API: `Items - List Environments <https://learn.microsoft.com/rest/api/fabric/environment/items/list-environments>`_.
5050
51+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
52+
5153
Parameters
5254
----------
5355
workspace : str | uuid.UUID, default=None
@@ -71,7 +73,9 @@ def list_environments(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
7173
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
7274

7375
responses = _base_api(
74-
request=f"/v1/workspaces/{workspace_id}/environments", uses_pagination=True
76+
request=f"/v1/workspaces/{workspace_id}/environments",
77+
uses_pagination=True,
78+
client="fabric_sp",
7579
)
7680

7781
for r in responses:
@@ -113,6 +117,8 @@ def publish_environment(
113117
114118
This is a wrapper function for the following API: `Spark Libraries - Publish Environment <https://learn.microsoft.com/rest/api/fabric/environment/spark-libraries/publish-environment>`_.
115119
120+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
121+
116122
Parameters
117123
----------
118124
environment: str | uuid.UUID
@@ -133,6 +139,7 @@ def publish_environment(
133139
method="post",
134140
lro_return_status_code=True,
135141
status_codes=None,
142+
client="fabric_sp",
136143
)
137144

138145
print(

src/sempy_labs/_eventhouses.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def list_eventhouses(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
7272
7373
This is a wrapper function for the following API: `Items - List Eventhouses <https://learn.microsoft.com/rest/api/fabric/environment/items/list-eventhouses>`_.
7474
75+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
76+
7577
Parameters
7678
----------
7779
workspace : str | uuid.UUID, default=None
@@ -95,7 +97,9 @@ def list_eventhouses(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
9597
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
9698

9799
responses = _base_api(
98-
request=f"/v1/workspaces/{workspace_id}/eventhouses", uses_pagination=True
100+
request=f"/v1/workspaces/{workspace_id}/eventhouses",
101+
uses_pagination=True,
102+
client="fabric_sp",
99103
)
100104

101105
for r in responses:

src/sempy_labs/_graphQL.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def list_graphql_apis(workspace: Optional[str | UUID]) -> pd.DataFrame:
1515
1616
This is a wrapper function for the following API: `Items - List GraphQLApis <https://learn.microsoft.com/rest/api/fabric/graphqlapi/items/list-graphqlapi-s>`_.
1717
18+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
19+
1820
Parameters
1921
----------
2022
workspace : str | uuid.UUID, default=None
@@ -38,7 +40,9 @@ def list_graphql_apis(workspace: Optional[str | UUID]) -> pd.DataFrame:
3840
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
3941

4042
responses = _base_api(
41-
request=f"/v1/workspaces/{workspace_id}/GraphQLApis", uses_pagination=True
43+
request=f"/v1/workspaces/{workspace_id}/GraphQLApis",
44+
uses_pagination=True,
45+
client="fabric_sp",
4246
)
4347

4448
for r in responses:

src/sempy_labs/_helper_functions.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,12 +1043,13 @@ def resolve_workspace_capacity(
10431043
Tuple[uuid.UUID, str]
10441044
capacity Id; capacity came.
10451045
"""
1046+
from sempy_labs._capacities import list_capacities
10461047

10471048
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
10481049
filter_condition = urllib.parse.quote(workspace_id)
10491050
dfW = fabric.list_workspaces(filter=f"id eq '{filter_condition}'")
10501051
capacity_id = dfW["Capacity Id"].iloc[0]
1051-
dfC = fabric.list_capacities()
1052+
dfC = list_capacities()
10521053
dfC_filt = dfC[dfC["Id"] == capacity_id]
10531054
if len(dfC_filt) == 1:
10541055
capacity_name = dfC_filt["Display Name"].iloc[0]
@@ -1106,8 +1107,10 @@ def get_capacity_name(workspace: Optional[str | UUID] = None) -> str:
11061107
The capacity name.
11071108
"""
11081109

1110+
from sempy_labs._capacities import list_capacities
1111+
11091112
capacity_id = get_capacity_id(workspace)
1110-
dfC = fabric.list_capacities()
1113+
dfC = list_capacities()
11111114
dfC_filt = dfC[dfC["Id"] == capacity_id]
11121115
if dfC_filt.empty:
11131116
raise ValueError(
@@ -1133,11 +1136,12 @@ def resolve_capacity_name(capacity_id: Optional[UUID] = None) -> str:
11331136
str
11341137
The capacity name.
11351138
"""
1139+
from sempy_labs._capacities import list_capacities
11361140

11371141
if capacity_id is None:
11381142
return get_capacity_name()
11391143

1140-
dfC = fabric.list_capacities()
1144+
dfC = list_capacities()
11411145
dfC_filt = dfC[dfC["Id"] == capacity_id]
11421146

11431147
if dfC_filt.empty:
@@ -1164,6 +1168,7 @@ def resolve_capacity_id(capacity: Optional[str | UUID] = None, **kwargs) -> UUID
11641168
uuid.UUID
11651169
The capacity Id.
11661170
"""
1171+
from sempy_labs._capacities import list_capacities
11671172

11681173
if "capacity_name" in kwargs:
11691174
capacity = kwargs["capacity_name"]
@@ -1176,7 +1181,7 @@ def resolve_capacity_id(capacity: Optional[str | UUID] = None, **kwargs) -> UUID
11761181
if _is_valid_uuid(capacity):
11771182
return capacity
11781183

1179-
dfC = fabric.list_capacities()
1184+
dfC = list_capacities()
11801185
dfC_filt = dfC[dfC["Display Name"] == capacity]
11811186

11821187
if dfC_filt.empty:

0 commit comments

Comments
 (0)