semantic-link-labs 0.8.3__py3-none-any.whl → 0.8.4__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.
- {semantic_link_labs-0.8.3.dist-info → semantic_link_labs-0.8.4.dist-info}/METADATA +33 -8
- {semantic_link_labs-0.8.3.dist-info → semantic_link_labs-0.8.4.dist-info}/RECORD +101 -98
- {semantic_link_labs-0.8.3.dist-info → semantic_link_labs-0.8.4.dist-info}/WHEEL +1 -1
- sempy_labs/__init__.py +24 -0
- sempy_labs/_bpa_translation/_model/_translations_am-ET.po +24 -5
- sempy_labs/_bpa_translation/_model/_translations_ar-AE.po +28 -4
- sempy_labs/_bpa_translation/_model/_translations_bg-BG.po +34 -4
- sempy_labs/_bpa_translation/_model/_translations_ca-ES.po +33 -4
- sempy_labs/_bpa_translation/_model/_translations_cs-CZ.po +31 -4
- sempy_labs/_bpa_translation/_model/_translations_da-DK.po +31 -4
- sempy_labs/_bpa_translation/_model/_translations_de-DE.po +34 -4
- sempy_labs/_bpa_translation/_model/_translations_el-GR.po +36 -4
- sempy_labs/_bpa_translation/_model/_translations_es-ES.po +90 -58
- sempy_labs/_bpa_translation/_model/_translations_fa-IR.po +31 -5
- sempy_labs/_bpa_translation/_model/_translations_fi-FI.po +31 -4
- sempy_labs/_bpa_translation/_model/_translations_fr-FR.po +34 -4
- sempy_labs/_bpa_translation/_model/_translations_ga-IE.po +34 -4
- sempy_labs/_bpa_translation/_model/_translations_he-IL.po +28 -4
- sempy_labs/_bpa_translation/_model/_translations_hi-IN.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_hu-HU.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_id-ID.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_is-IS.po +31 -4
- sempy_labs/_bpa_translation/_model/_translations_it-IT.po +34 -4
- sempy_labs/_bpa_translation/_model/_translations_ja-JP.po +24 -4
- sempy_labs/_bpa_translation/_model/_translations_ko-KR.po +72 -56
- sempy_labs/_bpa_translation/_model/_translations_mt-MT.po +34 -4
- sempy_labs/_bpa_translation/_model/_translations_nl-NL.po +34 -4
- sempy_labs/_bpa_translation/_model/_translations_pl-PL.po +95 -71
- sempy_labs/_bpa_translation/_model/_translations_pt-BR.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_pt-PT.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_ro-RO.po +33 -4
- sempy_labs/_bpa_translation/_model/_translations_ru-RU.po +34 -4
- sempy_labs/_bpa_translation/_model/_translations_sk-SK.po +31 -4
- sempy_labs/_bpa_translation/_model/_translations_sl-SL.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_sv-SE.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_ta-IN.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_te-IN.po +31 -4
- sempy_labs/_bpa_translation/_model/_translations_th-TH.po +31 -4
- sempy_labs/_bpa_translation/_model/_translations_tr-TR.po +32 -4
- sempy_labs/_bpa_translation/_model/_translations_uk-UA.po +100 -72
- sempy_labs/_bpa_translation/_model/_translations_zh-CN.po +23 -5
- sempy_labs/_bpa_translation/_model/_translations_zu-ZA.po +32 -4
- sempy_labs/_capacities.py +49 -14
- sempy_labs/_capacity_migration.py +1 -7
- sempy_labs/_data_pipelines.py +6 -0
- sempy_labs/_dataflows.py +4 -0
- sempy_labs/_deployment_pipelines.py +13 -7
- sempy_labs/_environments.py +6 -0
- sempy_labs/_eventhouses.py +6 -0
- sempy_labs/_eventstreams.py +6 -0
- sempy_labs/_external_data_shares.py +6 -4
- sempy_labs/_generate_semantic_model.py +26 -3
- sempy_labs/_git.py +14 -14
- sempy_labs/_helper_functions.py +172 -0
- sempy_labs/_icons.py +55 -22
- sempy_labs/_kql_databases.py +6 -0
- sempy_labs/_kql_querysets.py +6 -0
- sempy_labs/_list_functions.py +1 -1
- sempy_labs/_managed_private_endpoints.py +166 -0
- sempy_labs/_mirrored_warehouses.py +2 -0
- sempy_labs/_ml_experiments.py +6 -0
- sempy_labs/_ml_models.py +6 -0
- sempy_labs/_model_bpa.py +6 -1
- sempy_labs/_model_bpa_bulk.py +11 -25
- sempy_labs/_model_bpa_rules.py +8 -3
- sempy_labs/_notebooks.py +107 -12
- sempy_labs/_query_scale_out.py +8 -6
- sempy_labs/_refresh_semantic_model.py +299 -49
- sempy_labs/_spark.py +12 -5
- sempy_labs/_translations.py +2 -0
- sempy_labs/_vertipaq.py +58 -67
- sempy_labs/_warehouses.py +79 -0
- sempy_labs/_workloads.py +128 -0
- sempy_labs/_workspace_identity.py +4 -4
- sempy_labs/_workspaces.py +14 -1
- sempy_labs/admin/_basic_functions.py +85 -43
- sempy_labs/admin/_domains.py +18 -18
- sempy_labs/directlake/__init__.py +2 -0
- sempy_labs/directlake/_directlake_schema_sync.py +2 -1
- sempy_labs/directlake/_dl_helper.py +4 -1
- sempy_labs/directlake/_get_shared_expression.py +7 -1
- sempy_labs/directlake/_guardrails.py +2 -1
- sempy_labs/directlake/_show_unsupported_directlake_objects.py +1 -7
- sempy_labs/directlake/_update_directlake_model_lakehouse_connection.py +78 -0
- sempy_labs/directlake/_update_directlake_partition_entity.py +13 -32
- sempy_labs/lakehouse/_get_lakehouse_tables.py +6 -2
- sempy_labs/lakehouse/_shortcuts.py +4 -0
- sempy_labs/migration/_migrate_calctables_to_lakehouse.py +3 -2
- sempy_labs/migration/_migrate_calctables_to_semantic_model.py +2 -0
- sempy_labs/migration/_migrate_model_objects_to_semantic_model.py +2 -8
- sempy_labs/migration/_migrate_tables_columns_to_semantic_model.py +17 -0
- sempy_labs/migration/_migration_validation.py +2 -0
- sempy_labs/migration/_refresh_calc_tables.py +1 -0
- sempy_labs/report/__init__.py +4 -1
- sempy_labs/report/_generate_report.py +6 -0
- sempy_labs/report/_paginated.py +74 -0
- sempy_labs/report/_report_functions.py +6 -0
- sempy_labs/report/_report_rebind.py +2 -0
- sempy_labs/tom/_model.py +64 -33
- {semantic_link_labs-0.8.3.dist-info → semantic_link_labs-0.8.4.dist-info}/LICENSE +0 -0
- {semantic_link_labs-0.8.3.dist-info → semantic_link_labs-0.8.4.dist-info}/top_level.txt +0 -0
sempy_labs/_warehouses.py
CHANGED
|
@@ -19,6 +19,8 @@ def create_warehouse(
|
|
|
19
19
|
"""
|
|
20
20
|
Creates a Fabric warehouse.
|
|
21
21
|
|
|
22
|
+
This is a wrapper function for the following API: `Items - Create Warehouse <https://learn.microsoft.com/rest/api/fabric/warehouse/items/create-warehouse`_.
|
|
23
|
+
|
|
22
24
|
Parameters
|
|
23
25
|
----------
|
|
24
26
|
warehouse: str
|
|
@@ -61,6 +63,8 @@ def list_warehouses(workspace: Optional[str] = None) -> pd.DataFrame:
|
|
|
61
63
|
"""
|
|
62
64
|
Shows the warehouses within a workspace.
|
|
63
65
|
|
|
66
|
+
This is a wrapper function for the following API: `Items - List Warehouses <https://learn.microsoft.com/rest/api/fabric/warehouse/items/list-warehouses`_.
|
|
67
|
+
|
|
64
68
|
Parameters
|
|
65
69
|
----------
|
|
66
70
|
workspace : str, default=None
|
|
@@ -115,6 +119,8 @@ def delete_warehouse(name: str, workspace: Optional[str] = None):
|
|
|
115
119
|
"""
|
|
116
120
|
Deletes a Fabric warehouse.
|
|
117
121
|
|
|
122
|
+
This is a wrapper function for the following API: `Items - Delete Warehouse <https://learn.microsoft.com/rest/api/fabric/warehouse/items/delete-warehouse`_.
|
|
123
|
+
|
|
118
124
|
Parameters
|
|
119
125
|
----------
|
|
120
126
|
name: str
|
|
@@ -140,3 +146,76 @@ def delete_warehouse(name: str, workspace: Optional[str] = None):
|
|
|
140
146
|
print(
|
|
141
147
|
f"{icons.green_dot} The '{name}' warehouse within the '{workspace}' workspace has been deleted."
|
|
142
148
|
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def get_warehouse_tables(
|
|
152
|
+
warehouse: str, workspace: Optional[str] = None
|
|
153
|
+
) -> pd.DataFrame:
|
|
154
|
+
"""
|
|
155
|
+
Shows a list of the tables in the Fabric warehouse. This function is based on INFORMATION_SCHEMA.TABLES.
|
|
156
|
+
|
|
157
|
+
Parameters
|
|
158
|
+
----------
|
|
159
|
+
warehouse : str
|
|
160
|
+
Name of the Fabric warehouse.
|
|
161
|
+
workspace : str, default=None
|
|
162
|
+
The Fabric workspace name.
|
|
163
|
+
Defaults to None which resolves to the workspace of the attached lakehouse
|
|
164
|
+
or if no lakehouse attached, resolves to the workspace of the notebook.
|
|
165
|
+
|
|
166
|
+
Returns
|
|
167
|
+
-------
|
|
168
|
+
pandas.DataFrame
|
|
169
|
+
A pandas dataframe showing a list of the tables in the Fabric warehouse.
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
from sempy_labs._sql import ConnectWarehouse
|
|
173
|
+
|
|
174
|
+
with ConnectWarehouse(warehouse=warehouse, workspace=workspace) as sql:
|
|
175
|
+
df = sql.query(
|
|
176
|
+
"""
|
|
177
|
+
SELECT TABLE_SCHEMA AS [Schema], TABLE_NAME AS [Table Name], TABLE_TYPE AS [Table Type]
|
|
178
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
179
|
+
WHERE TABLE_TYPE = 'BASE TABLE'
|
|
180
|
+
"""
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
return df
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def get_warehouse_columns(
|
|
187
|
+
warehouse: str, workspace: Optional[str] = None
|
|
188
|
+
) -> pd.DataFrame:
|
|
189
|
+
"""
|
|
190
|
+
Shows a list of the columns in each table within the Fabric warehouse. This function is based on INFORMATION_SCHEMA.COLUMNS.
|
|
191
|
+
|
|
192
|
+
Parameters
|
|
193
|
+
----------
|
|
194
|
+
warehouse : str
|
|
195
|
+
Name of the Fabric warehouse.
|
|
196
|
+
workspace : str, default=None
|
|
197
|
+
The Fabric workspace name.
|
|
198
|
+
Defaults to None which resolves to the workspace of the attached lakehouse
|
|
199
|
+
or if no lakehouse attached, resolves to the workspace of the notebook.
|
|
200
|
+
|
|
201
|
+
Returns
|
|
202
|
+
-------
|
|
203
|
+
pandas.DataFrame
|
|
204
|
+
A pandas dataframe showing a list of the columns in each table within the Fabric warehouse.
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
from sempy_labs._sql import ConnectWarehouse
|
|
208
|
+
|
|
209
|
+
with ConnectWarehouse(warehouse=warehouse, workspace=workspace) as sql:
|
|
210
|
+
df = sql.query(
|
|
211
|
+
"""
|
|
212
|
+
SELECT t.TABLE_SCHEMA AS [Schema], t.TABLE_NAME AS [Table Name], c.COLUMN_NAME AS [Column Name], c.DATA_TYPE AS [Data Type], c.IS_NULLABLE AS [Is Nullable], c.CHARACTER_MAXIMUM_LENGTH AS [Character Max Length]
|
|
213
|
+
FROM INFORMATION_SCHEMA.TABLES AS t
|
|
214
|
+
LEFT JOIN INFORMATION_SCHEMA.COLUMNS AS c
|
|
215
|
+
ON t.TABLE_NAME = c.TABLE_NAME
|
|
216
|
+
AND t.TABLE_SCHEMA = c.TABLE_SCHEMA
|
|
217
|
+
WHERE t.TABLE_TYPE = 'BASE TABLE'
|
|
218
|
+
"""
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
return df
|
sempy_labs/_workloads.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import sempy.fabric as fabric
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from typing import Optional
|
|
4
|
+
import sempy_labs._icons as icons
|
|
5
|
+
from sempy.fabric.exceptions import FabricHTTPException
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def list_workloads(capacity_name: str) -> pd.DataFrame:
|
|
9
|
+
"""
|
|
10
|
+
Returns the current state of the specified capacity workloads.
|
|
11
|
+
If a workload is enabled, the percentage of maximum memory that the workload can consume is also returned.
|
|
12
|
+
|
|
13
|
+
This is a wrapper function for the following API: `Capacities - Get Workloads <https://learn.microsoft.com/rest/api/power-bi/capacities/get-workloads>`_.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
capacity_name : str
|
|
18
|
+
The capacity name.
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
-------
|
|
22
|
+
pandas.DataFrame
|
|
23
|
+
A pandas dataframe showing the current state of the specified capacity workloads.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from sempy_labs._helper_functions import resolve_capacity_id
|
|
27
|
+
|
|
28
|
+
df = pd.DataFrame(
|
|
29
|
+
columns=["Workload Name", "State", "Max Memory Percentage Set By User"]
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
capacity_id = resolve_capacity_id(capacity_name=capacity_name)
|
|
33
|
+
|
|
34
|
+
client = fabric.PowerBIRestClient()
|
|
35
|
+
response = client.get(f"/v1.0/myorg/capacities/{capacity_id}/Workloads")
|
|
36
|
+
|
|
37
|
+
if response.status_code != 200:
|
|
38
|
+
raise FabricHTTPException(response)
|
|
39
|
+
|
|
40
|
+
for v in response.json().get("value", []):
|
|
41
|
+
new_data = {
|
|
42
|
+
"Workload Name": v.get("name"),
|
|
43
|
+
"State": v.get("state"),
|
|
44
|
+
"Max Memory Percentage Set By User": v.get("maxMemoryPercentageSetByUser"),
|
|
45
|
+
}
|
|
46
|
+
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
|
|
47
|
+
|
|
48
|
+
int_cols = ["Max Memory Percentage Set By User"]
|
|
49
|
+
df[int_cols] = df[int_cols].astype(int)
|
|
50
|
+
|
|
51
|
+
return df
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def patch_workload(
|
|
55
|
+
capacity_name: str,
|
|
56
|
+
workload_name: str,
|
|
57
|
+
state: Optional[str] = None,
|
|
58
|
+
max_memory_percentage: Optional[int] = None,
|
|
59
|
+
):
|
|
60
|
+
"""
|
|
61
|
+
Changes the state of a specific workload to Enabled or Disabled.
|
|
62
|
+
When enabling a workload, specify the percentage of maximum memory that the workload can consume.
|
|
63
|
+
|
|
64
|
+
This is a wrapper function for the following API: `Capacities - Patch Workload <https://learn.microsoft.com/rest/api/power-bi/capacities/patch-workload>`_.
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
capacity_name : str
|
|
69
|
+
The capacity name.
|
|
70
|
+
workload_name : str
|
|
71
|
+
The workload name.
|
|
72
|
+
state : str, default=None
|
|
73
|
+
The capacity workload state.
|
|
74
|
+
max_memory_percentage : int, default=None
|
|
75
|
+
The percentage of the maximum memory that a workload can consume (set by the user).
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
from sempy_labs._helper_functions import resolve_capacity_id
|
|
79
|
+
|
|
80
|
+
capacity_id = resolve_capacity_id(capacity_name=capacity_name)
|
|
81
|
+
|
|
82
|
+
states = ["Disabled", "Enabled", "Unsupported"]
|
|
83
|
+
state = state.capitalize()
|
|
84
|
+
if state is not None and state not in states:
|
|
85
|
+
raise ValueError(
|
|
86
|
+
f"{icons.red_dot} Invalid 'state' parameter. Please choose from these options: {states}."
|
|
87
|
+
)
|
|
88
|
+
if max_memory_percentage is not None and (
|
|
89
|
+
max_memory_percentage < 0 or max_memory_percentage > 100
|
|
90
|
+
):
|
|
91
|
+
raise ValueError(
|
|
92
|
+
f"{icons.red_dot} Invalid max memory percentage. Must be a value between 0-100."
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
client = fabric.PowerBIRestClient()
|
|
96
|
+
url = f"/v1.0/myorg/capacities/{capacity_id}/Workloads/{workload_name}"
|
|
97
|
+
get_response = client.get(url)
|
|
98
|
+
if get_response.status_code != 200:
|
|
99
|
+
raise FabricHTTPException(get_response)
|
|
100
|
+
|
|
101
|
+
get_json = get_response.json().get("value")
|
|
102
|
+
current_state = get_json.get("state")
|
|
103
|
+
current_max_memory = get_json.get("maxMemoryPercentageSetByUser")
|
|
104
|
+
|
|
105
|
+
if current_state == state and str(current_max_memory) == str(max_memory_percentage):
|
|
106
|
+
print(
|
|
107
|
+
f"{icons.info} The current workload settings are the same as those specified in the parameters of this function. The workload has not been updated."
|
|
108
|
+
)
|
|
109
|
+
return
|
|
110
|
+
|
|
111
|
+
payload = {}
|
|
112
|
+
if state is not None:
|
|
113
|
+
payload["state"] = state
|
|
114
|
+
else:
|
|
115
|
+
payload["state"] = current_state
|
|
116
|
+
if max_memory_percentage is not None:
|
|
117
|
+
payload["maxMemoryPercentageSetByUser"] = max_memory_percentage
|
|
118
|
+
else:
|
|
119
|
+
payload["maxMemoryPercentageSetByUser"] = current_max_memory
|
|
120
|
+
|
|
121
|
+
response = client.patch(url, json=payload)
|
|
122
|
+
|
|
123
|
+
if response.status_code != 200:
|
|
124
|
+
raise FabricHTTPException(response)
|
|
125
|
+
|
|
126
|
+
print(
|
|
127
|
+
f"The '{workload_name}' workload within the '{capacity_name}' capacity has been updated accordingly."
|
|
128
|
+
)
|
|
@@ -12,6 +12,8 @@ def provision_workspace_identity(workspace: Optional[str] = None):
|
|
|
12
12
|
"""
|
|
13
13
|
Provisions a workspace identity for a workspace.
|
|
14
14
|
|
|
15
|
+
This is a wrapper function for the following API: `Workspaces - Provision Identity <https://learn.microsoft.com/rest/api/fabric/core/workspaces/provision-identity`_.
|
|
16
|
+
|
|
15
17
|
Parameters
|
|
16
18
|
----------
|
|
17
19
|
workspace : str, default=None
|
|
@@ -20,8 +22,6 @@ def provision_workspace_identity(workspace: Optional[str] = None):
|
|
|
20
22
|
or if no lakehouse attached, resolves to the workspace of the notebook.
|
|
21
23
|
"""
|
|
22
24
|
|
|
23
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/provision-identity?tabs=HTTP
|
|
24
|
-
|
|
25
25
|
workspace, workspace_id = resolve_workspace_name_and_id(workspace)
|
|
26
26
|
|
|
27
27
|
client = fabric.FabricRestClient()
|
|
@@ -41,6 +41,8 @@ def deprovision_workspace_identity(workspace: Optional[str] = None):
|
|
|
41
41
|
"""
|
|
42
42
|
Deprovisions a workspace identity for a workspace.
|
|
43
43
|
|
|
44
|
+
This is a wrapper function for the following API: `Workspaces - Derovision Identity <https://learn.microsoft.com/rest/api/fabric/core/workspaces/deprovision-identity`_.
|
|
45
|
+
|
|
44
46
|
Parameters
|
|
45
47
|
----------
|
|
46
48
|
workspace : str, default=None
|
|
@@ -49,8 +51,6 @@ def deprovision_workspace_identity(workspace: Optional[str] = None):
|
|
|
49
51
|
or if no lakehouse attached, resolves to the workspace of the notebook.
|
|
50
52
|
"""
|
|
51
53
|
|
|
52
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/deprovision-identity?tabs=HTTP
|
|
53
|
-
|
|
54
54
|
workspace, workspace_id = resolve_workspace_name_and_id(workspace)
|
|
55
55
|
|
|
56
56
|
client = fabric.FabricRestClient()
|
sempy_labs/_workspaces.py
CHANGED
|
@@ -14,6 +14,8 @@ def delete_user_from_workspace(email_address: str, workspace: Optional[str] = No
|
|
|
14
14
|
"""
|
|
15
15
|
Removes a user from a workspace.
|
|
16
16
|
|
|
17
|
+
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`_.
|
|
18
|
+
|
|
17
19
|
Parameters
|
|
18
20
|
----------
|
|
19
21
|
email_address : str
|
|
@@ -45,6 +47,8 @@ def update_workspace_user(
|
|
|
45
47
|
"""
|
|
46
48
|
Updates a user's role within a workspace.
|
|
47
49
|
|
|
50
|
+
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`_.
|
|
51
|
+
|
|
48
52
|
Parameters
|
|
49
53
|
----------
|
|
50
54
|
email_address : str
|
|
@@ -95,6 +99,8 @@ def list_workspace_users(workspace: Optional[str] = None) -> pd.DataFrame:
|
|
|
95
99
|
"""
|
|
96
100
|
A list of all the users of a workspace and their roles.
|
|
97
101
|
|
|
102
|
+
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`_.
|
|
103
|
+
|
|
98
104
|
Parameters
|
|
99
105
|
----------
|
|
100
106
|
workspace : str, default=None
|
|
@@ -142,6 +148,8 @@ def add_user_to_workspace(
|
|
|
142
148
|
"""
|
|
143
149
|
Adds a user to a workspace.
|
|
144
150
|
|
|
151
|
+
This is a wrapper function for the following API: `Groups - Add Group User <https://learn.microsoft.com/rest/api/power-bi/groups/add-group-user`_.
|
|
152
|
+
|
|
145
153
|
Parameters
|
|
146
154
|
----------
|
|
147
155
|
email_address : str
|
|
@@ -196,6 +204,8 @@ def assign_workspace_to_capacity(capacity_name: str, workspace: Optional[str] =
|
|
|
196
204
|
"""
|
|
197
205
|
Assigns a workspace to a capacity.
|
|
198
206
|
|
|
207
|
+
This is a wrapper function for the following API: `Workspaces - Assign To Capacity <https://learn.microsoft.com/rest/api/fabric/core/workspaces/assign-to-capacity`_.
|
|
208
|
+
|
|
199
209
|
Parameters
|
|
200
210
|
----------
|
|
201
211
|
capacity_name : str
|
|
@@ -228,6 +238,8 @@ def unassign_workspace_from_capacity(workspace: Optional[str] = None):
|
|
|
228
238
|
"""
|
|
229
239
|
Unassigns a workspace from its assigned capacity.
|
|
230
240
|
|
|
241
|
+
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`_.
|
|
242
|
+
|
|
231
243
|
Parameters
|
|
232
244
|
----------
|
|
233
245
|
workspace : str, default=None
|
|
@@ -236,7 +248,6 @@ def unassign_workspace_from_capacity(workspace: Optional[str] = None):
|
|
|
236
248
|
or if no lakehouse attached, resolves to the workspace of the notebook.
|
|
237
249
|
"""
|
|
238
250
|
|
|
239
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/unassign-from-capacity?tabs=HTTP
|
|
240
251
|
(workspace, workspace_id) = resolve_workspace_name_and_id(workspace)
|
|
241
252
|
|
|
242
253
|
client = fabric.FabricRestClient()
|
|
@@ -253,6 +264,8 @@ def list_workspace_role_assignments(workspace: Optional[str] = None) -> pd.DataF
|
|
|
253
264
|
"""
|
|
254
265
|
Shows the members of a given workspace.
|
|
255
266
|
|
|
267
|
+
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`_.
|
|
268
|
+
|
|
256
269
|
Parameters
|
|
257
270
|
----------
|
|
258
271
|
workspace : str, default=None
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import sempy.fabric as fabric
|
|
2
|
-
from typing import Optional, List, Union
|
|
2
|
+
from typing import Optional, List, Union, Tuple
|
|
3
3
|
from uuid import UUID
|
|
4
4
|
import sempy_labs._icons as icons
|
|
5
5
|
from sempy.fabric.exceptions import FabricHTTPException
|
|
@@ -10,18 +10,26 @@ from sempy_labs._helper_functions import (
|
|
|
10
10
|
import numpy as np
|
|
11
11
|
import pandas as pd
|
|
12
12
|
import time
|
|
13
|
+
import urllib.parse
|
|
14
|
+
from datetime import datetime
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
def list_workspaces(
|
|
16
|
-
top: Optional[int] = 5000,
|
|
18
|
+
top: Optional[int] = 5000,
|
|
19
|
+
filter: Optional[str] = None,
|
|
20
|
+
skip: Optional[int] = None,
|
|
17
21
|
) -> pd.DataFrame:
|
|
18
22
|
"""
|
|
19
23
|
Lists workspaces for the organization. This function is the admin version of list_workspaces.
|
|
20
24
|
|
|
25
|
+
This is a wrapper function for the following API: `Admin - Groups GetGroupsAsAdmin <https://learn.microsoft.com/rest/api/power-bi/admin/groups-get-groups-as-admin>`_.
|
|
26
|
+
|
|
21
27
|
Parameters
|
|
22
28
|
----------
|
|
23
29
|
top : int, default=5000
|
|
24
30
|
Returns only the first n results. This parameter is mandatory and must be in the range of 1-5000.
|
|
31
|
+
filter : str, default=None
|
|
32
|
+
Returns a subset of a results based on `Odata filter <https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptions>`_ query parameter condition.
|
|
25
33
|
skip : int, default=None
|
|
26
34
|
Skips the first n results. Use with top to fetch results beyond the first 5000.
|
|
27
35
|
|
|
@@ -48,6 +56,8 @@ def list_workspaces(
|
|
|
48
56
|
url = f"/v1.0/myorg/admin/groups?$top={top}"
|
|
49
57
|
if skip is not None:
|
|
50
58
|
url = f"{url}&$skip={skip}"
|
|
59
|
+
if filter is not None:
|
|
60
|
+
url = f"{url}&$filter={filter}"
|
|
51
61
|
|
|
52
62
|
client = fabric.PowerBIRestClient()
|
|
53
63
|
response = client.get(url)
|
|
@@ -91,6 +101,8 @@ def assign_workspaces_to_capacity(
|
|
|
91
101
|
"""
|
|
92
102
|
Assigns a workspace to a capacity. This function is the admin version.
|
|
93
103
|
|
|
104
|
+
This is a wrapper function for the following API: `Admin - Capacities AssignWorkspacesToCapacity <https://learn.microsoft.com/rest/api/power-bi/admin/capacities-assign-workspaces-to-capacity>`_.
|
|
105
|
+
|
|
94
106
|
Parameters
|
|
95
107
|
----------
|
|
96
108
|
source_capacity : str
|
|
@@ -113,9 +125,6 @@ def assign_workspaces_to_capacity(
|
|
|
113
125
|
target_capacity_id = dfC_filt["Capacity Id"].iloc[0]
|
|
114
126
|
|
|
115
127
|
if workspace is None:
|
|
116
|
-
# workspaces = fabric.list_workspaces(
|
|
117
|
-
# filter=f"capacityId eq '{source_capacity_id.upper()}'"
|
|
118
|
-
# )["Id"].values
|
|
119
128
|
dfW = list_workspaces()
|
|
120
129
|
dfW = dfW[dfW["Capacity Id"].str.upper() == source_capacity_id.upper()]
|
|
121
130
|
workspaces = dfW["Id"].tolist()
|
|
@@ -153,6 +162,8 @@ def list_capacities() -> pd.DataFrame:
|
|
|
153
162
|
"""
|
|
154
163
|
Shows the a list of capacities and their properties. This function is the admin version.
|
|
155
164
|
|
|
165
|
+
This is a wrapper function for the following API: `Admin - Get Capacities As Admin <https://learn.microsoft.com/rest/api/power-bi/admin/get-capacities-as-admin>`_.
|
|
166
|
+
|
|
156
167
|
Returns
|
|
157
168
|
-------
|
|
158
169
|
pandas.DataFrame
|
|
@@ -189,14 +200,14 @@ def list_tenant_settings() -> pd.DataFrame:
|
|
|
189
200
|
"""
|
|
190
201
|
Lists all tenant settings.
|
|
191
202
|
|
|
203
|
+
This is a wrapper function for the following API: `Tenants - List Tenant Settings <https://learn.microsoft.com/rest/api/fabric/admin/tenants/list-tenant-settings>`_.
|
|
204
|
+
|
|
192
205
|
Returns
|
|
193
206
|
-------
|
|
194
207
|
pandas.DataFrame
|
|
195
208
|
A pandas dataframe showing the tenant settings.
|
|
196
209
|
"""
|
|
197
210
|
|
|
198
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/admin/tenants/list-tenant-settings?tabs=HTTP
|
|
199
|
-
|
|
200
211
|
client = fabric.FabricRestClient()
|
|
201
212
|
response = client.get("/v1/admin/tenantsettings")
|
|
202
213
|
|
|
@@ -262,7 +273,9 @@ def _list_capacities_meta() -> pd.DataFrame:
|
|
|
262
273
|
|
|
263
274
|
def unassign_workspaces_from_capacity(workspaces: str | List[str]):
|
|
264
275
|
"""
|
|
265
|
-
Unassigns workspace(s) from their capacity.
|
|
276
|
+
Unassigns workspace(s) from their capacity.
|
|
277
|
+
|
|
278
|
+
This is a wrapper function for the following API: `Admin - Capacities UnassignWorkspacesFromCapacity <https://learn.microsoft.com/rest/api/power-bi/admin/capacities-unassign-workspaces-from-capacity>`_.
|
|
266
279
|
|
|
267
280
|
Parameters
|
|
268
281
|
----------
|
|
@@ -270,8 +283,6 @@ def unassign_workspaces_from_capacity(workspaces: str | List[str]):
|
|
|
270
283
|
The Fabric workspace name(s).
|
|
271
284
|
"""
|
|
272
285
|
|
|
273
|
-
# https://learn.microsoft.com/en-us/rest/api/power-bi/admin/capacities-unassign-workspaces-from-capacity
|
|
274
|
-
|
|
275
286
|
if isinstance(workspaces, str):
|
|
276
287
|
workspaces = [workspaces]
|
|
277
288
|
|
|
@@ -293,14 +304,14 @@ def list_external_data_shares():
|
|
|
293
304
|
"""
|
|
294
305
|
Lists external data shares in the tenant. This function is for admins.
|
|
295
306
|
|
|
307
|
+
This is a wrapper function for the following API: `External Data Shares - List External Data Shares <https://learn.microsoft.com/rest/api/fabric/admin/external-data-shares/list-external-data-shares>`_.
|
|
308
|
+
|
|
296
309
|
Returns
|
|
297
310
|
-------
|
|
298
311
|
pandas.DataFrame
|
|
299
312
|
A pandas dataframe showing a list of external data shares in the tenant.
|
|
300
313
|
"""
|
|
301
314
|
|
|
302
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/admin/external-data-shares/list-external-data-shares?tabs=HTTP
|
|
303
|
-
|
|
304
315
|
df = pd.DataFrame(
|
|
305
316
|
columns=[
|
|
306
317
|
"External Data Share Id",
|
|
@@ -355,6 +366,8 @@ def revoke_external_data_share(
|
|
|
355
366
|
"""
|
|
356
367
|
Revokes the specified external data share. Note: This action cannot be undone.
|
|
357
368
|
|
|
369
|
+
This is a wrapper function for the following API: `External Data Shares - Revoke External Data Share <https://learn.microsoft.com/rest/api/fabric/admin/external-data-shares/revoke-external-data-share`_.
|
|
370
|
+
|
|
358
371
|
Parameters
|
|
359
372
|
----------
|
|
360
373
|
external_data_share_id : UUID
|
|
@@ -365,8 +378,6 @@ def revoke_external_data_share(
|
|
|
365
378
|
The Fabric workspace name.
|
|
366
379
|
"""
|
|
367
380
|
|
|
368
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/admin/external-data-shares/revoke-external-data-share?tabs=HTTP
|
|
369
|
-
|
|
370
381
|
(workspace, workspace_id) = resolve_workspace_name_and_id(workspace)
|
|
371
382
|
|
|
372
383
|
client = fabric.FabricRestClient()
|
|
@@ -384,23 +395,23 @@ def revoke_external_data_share(
|
|
|
384
395
|
|
|
385
396
|
def list_capacities_delegated_tenant_settings(
|
|
386
397
|
return_dataframe: bool = True,
|
|
387
|
-
) ->
|
|
398
|
+
) -> pd.DataFrame | dict:
|
|
388
399
|
"""
|
|
389
400
|
Returns list of tenant setting overrides that override at the capacities.
|
|
390
401
|
|
|
402
|
+
This is a wrapper function for the following API: `Tenants - List Capacities Tenant Settings Overrides <https://learn.microsoft.com/rest/api/fabric/admin/tenants/list-capacities-tenant-settings-overrides`_.
|
|
403
|
+
|
|
391
404
|
Parameters
|
|
392
405
|
----------
|
|
393
406
|
return_dataframe : bool, default=True
|
|
394
|
-
If True, returns a dataframe. If False, returns a dictionary
|
|
407
|
+
If True, returns a dataframe. If False, returns a dictionary.
|
|
395
408
|
|
|
396
409
|
Returns
|
|
397
410
|
-------
|
|
398
|
-
pandas.DataFrame
|
|
411
|
+
pandas.DataFrame | dict
|
|
399
412
|
A pandas dataframe showing a list of tenant setting overrides that override at the capacities.
|
|
400
413
|
"""
|
|
401
414
|
|
|
402
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/admin/tenants/list-capacities-tenant-settings-overrides?tabs=HTTP
|
|
403
|
-
|
|
404
415
|
df = pd.DataFrame(
|
|
405
416
|
columns=[
|
|
406
417
|
"Capacity Id",
|
|
@@ -519,14 +530,14 @@ def list_datasets() -> pd.DataFrame:
|
|
|
519
530
|
"""
|
|
520
531
|
Shows a list of datasets for the organization.
|
|
521
532
|
|
|
533
|
+
This is a wrapper function for the following API: `Admin - Datasets GetDatasetsAsAdmin <https://learn.microsoft.com/rest/api/power-bi/admin/datasets-get-datasets-as-admin`_.
|
|
534
|
+
|
|
522
535
|
Returns
|
|
523
536
|
-------
|
|
524
537
|
pandas.DataFrame
|
|
525
538
|
A pandas dataframe showing a list of datasets for the organization.
|
|
526
539
|
"""
|
|
527
540
|
|
|
528
|
-
# https://learn.microsoft.com/en-us/rest/api/power-bi/admin/datasets-get-datasets-as-admin
|
|
529
|
-
|
|
530
541
|
df = pd.DataFrame(
|
|
531
542
|
columns=[
|
|
532
543
|
"Dataset Id",
|
|
@@ -609,6 +620,8 @@ def list_item_access_details(
|
|
|
609
620
|
"""
|
|
610
621
|
Returns a list of users (including groups and service principals) and lists their workspace roles.
|
|
611
622
|
|
|
623
|
+
This is a wrapper function for the following API: `Items - List Item Access Details <https://learn.microsoft.com/rest/api/fabric/admin/items/list-item-access-details`_.
|
|
624
|
+
|
|
612
625
|
Parameters
|
|
613
626
|
----------
|
|
614
627
|
item_name : str
|
|
@@ -626,13 +639,8 @@ def list_item_access_details(
|
|
|
626
639
|
A pandas dataframe showing a list of users (including groups and service principals) and lists their workspace roles.
|
|
627
640
|
"""
|
|
628
641
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
workspace = fabric.resolve_workspace_name(workspace)
|
|
632
|
-
workspace_id = fabric.resolve_workspace_id(workspace)
|
|
633
|
-
item_id = fabric.resolve_item_id(
|
|
634
|
-
item_name=item_name, type=type, workspace=workspace
|
|
635
|
-
)
|
|
642
|
+
workspace_name, workspace_id = _resolve_workspace_name_and_id(workspace)
|
|
643
|
+
item_id = _resolve_item_id(item_name=item_name, type=type, workspace=workspace_name)
|
|
636
644
|
|
|
637
645
|
df = pd.DataFrame(
|
|
638
646
|
columns=[
|
|
@@ -678,7 +686,9 @@ def list_access_entities(
|
|
|
678
686
|
user_email_address: str,
|
|
679
687
|
) -> pd.DataFrame:
|
|
680
688
|
"""
|
|
681
|
-
Shows a list of permission details for Fabric and
|
|
689
|
+
Shows a list of permission details for Fabric and Power BI items the specified user can access.
|
|
690
|
+
|
|
691
|
+
This is a wrapper function for the following API: `Users - List Access Entities <https://learn.microsoft.com/rest/api/fabric/admin/users/list-access-entities`_.
|
|
682
692
|
|
|
683
693
|
Parameters
|
|
684
694
|
----------
|
|
@@ -688,11 +698,9 @@ def list_access_entities(
|
|
|
688
698
|
Returns
|
|
689
699
|
-------
|
|
690
700
|
pandas.DataFrame
|
|
691
|
-
A pandas dataframe showing a list of permission details for Fabric and
|
|
701
|
+
A pandas dataframe showing a list of permission details for Fabric and Power BI items the specified user can access.
|
|
692
702
|
"""
|
|
693
703
|
|
|
694
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/admin/users/list-access-entities?tabs=HTTP
|
|
695
|
-
|
|
696
704
|
df = pd.DataFrame(
|
|
697
705
|
columns=[
|
|
698
706
|
"Item Id",
|
|
@@ -732,6 +740,8 @@ def list_workspace_access_details(
|
|
|
732
740
|
"""
|
|
733
741
|
Shows a list of users (including groups and Service Principals) that have access to the specified workspace.
|
|
734
742
|
|
|
743
|
+
This is a wrapper function for the following API: `Workspaces - List Workspace Access Details <https://learn.microsoft.com/rest/api/fabric/admin/workspaces/list-workspace-access-details`_.
|
|
744
|
+
|
|
735
745
|
Parameters
|
|
736
746
|
----------
|
|
737
747
|
workspace : str, default=None
|
|
@@ -745,10 +755,7 @@ def list_workspace_access_details(
|
|
|
745
755
|
A pandas dataframe showing a list of users (including groups and Service Principals) that have access to the specified workspace.
|
|
746
756
|
"""
|
|
747
757
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
workspace_name = fabric.resolve_workspace_name(workspace)
|
|
751
|
-
workspace_id = fabric.resolve_workspace_id(workspace_name)
|
|
758
|
+
workspace_name, workspace_id = _resolve_workspace_name_and_id(workspace)
|
|
752
759
|
|
|
753
760
|
df = pd.DataFrame(
|
|
754
761
|
columns=[
|
|
@@ -779,6 +786,32 @@ def list_workspace_access_details(
|
|
|
779
786
|
return df
|
|
780
787
|
|
|
781
788
|
|
|
789
|
+
def _resolve_item_id(
|
|
790
|
+
item_name: str, type: str, workspace: Optional[str] = None
|
|
791
|
+
) -> UUID:
|
|
792
|
+
|
|
793
|
+
workspace_name, workspace_id = _resolve_workspace_name_and_id(workspace)
|
|
794
|
+
dfI = list_items(workspace=workspace_name, type=type)
|
|
795
|
+
dfI_filt = dfI[dfI["Item Name"] == item_name]
|
|
796
|
+
|
|
797
|
+
if len(dfI_filt) == 0:
|
|
798
|
+
raise ValueError(
|
|
799
|
+
f"The '{item_name}' {type} does not exist within the '{workspace_name}' workspace."
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
return dfI_filt["Item Id"].iloc[0]
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
def _resolve_workspace_name_and_id(workspace: str) -> Tuple[str, UUID]:
|
|
806
|
+
|
|
807
|
+
filter_condition = urllib.parse.quote(workspace)
|
|
808
|
+
dfW_filt = list_workspaces(filter=f"name eq '{filter_condition}'")
|
|
809
|
+
workspace_name = dfW_filt["Name"].iloc[0]
|
|
810
|
+
workspace_id = dfW_filt["Id"].iloc[0]
|
|
811
|
+
|
|
812
|
+
return workspace_name, workspace_id
|
|
813
|
+
|
|
814
|
+
|
|
782
815
|
def list_items(
|
|
783
816
|
capacity_name: Optional[str] = None,
|
|
784
817
|
workspace: Optional[str] = None,
|
|
@@ -786,7 +819,9 @@ def list_items(
|
|
|
786
819
|
type: Optional[str] = None,
|
|
787
820
|
) -> pd.DataFrame:
|
|
788
821
|
"""
|
|
789
|
-
Shows a list of active Fabric and
|
|
822
|
+
Shows a list of active Fabric and Power BI items.
|
|
823
|
+
|
|
824
|
+
This is a wrapper function for the following API: `Items - List Items <https://learn.microsoft.com/rest/api/fabric/admin/items/list-items`_.
|
|
790
825
|
|
|
791
826
|
Parameters
|
|
792
827
|
----------
|
|
@@ -807,8 +842,6 @@ def list_items(
|
|
|
807
842
|
A pandas dataframe showing a list of active Fabric and Power BI items.
|
|
808
843
|
"""
|
|
809
844
|
|
|
810
|
-
# https://learn.microsoft.com/en-us/rest/api/fabric/admin/items/list-items?tabs=HTTP
|
|
811
|
-
|
|
812
845
|
url = "/v1/admin/items?"
|
|
813
846
|
|
|
814
847
|
df = pd.DataFrame(
|
|
@@ -829,8 +862,7 @@ def list_items(
|
|
|
829
862
|
)
|
|
830
863
|
|
|
831
864
|
if workspace is not None:
|
|
832
|
-
|
|
833
|
-
workspace_id = fabric.resolve_workspace_id(workspace)
|
|
865
|
+
workspace_name, workspace_id = _resolve_workspace_name_and_id(workspace)
|
|
834
866
|
url += f"workspaceId={workspace_id}&"
|
|
835
867
|
if capacity_name is not None:
|
|
836
868
|
dfC = list_capacities()
|
|
@@ -891,6 +923,8 @@ def list_activity_events(
|
|
|
891
923
|
"""
|
|
892
924
|
Shows a list of audit activity events for a tenant.
|
|
893
925
|
|
|
926
|
+
This is a wrapper function for the following API: `Admin - Get Activity Events <https://learn.microsoft.com/rest/api/power-bi/admin/get-activity-events`_.
|
|
927
|
+
|
|
894
928
|
Parameters
|
|
895
929
|
----------
|
|
896
930
|
start_time : str
|
|
@@ -908,7 +942,13 @@ def list_activity_events(
|
|
|
908
942
|
A pandas dataframe showing a list of audit activity events for a tenant.
|
|
909
943
|
"""
|
|
910
944
|
|
|
911
|
-
|
|
945
|
+
start_dt = datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%S")
|
|
946
|
+
end_dt = datetime.strptime(end_time, "%Y-%m-%dT%H:%M:%S")
|
|
947
|
+
|
|
948
|
+
if not start_dt.date() == end_dt.date():
|
|
949
|
+
raise ValueError(
|
|
950
|
+
f"{icons.red_dot} Start and End Times must be within the same UTC day. Please refer to the documentation here: https://learn.microsoft.com/rest/api/power-bi/admin/get-activity-events#get-audit-activity-events-within-a-time-window-and-for-a-specific-activity-type-and-user-id-example"
|
|
951
|
+
)
|
|
912
952
|
|
|
913
953
|
df = pd.DataFrame(
|
|
914
954
|
columns=[
|
|
@@ -948,7 +988,7 @@ def list_activity_events(
|
|
|
948
988
|
conditions.append(f"UserId{space}eq{space}{tic}{user_id_filter}{tic}")
|
|
949
989
|
|
|
950
990
|
filter_value = (
|
|
951
|
-
f"
|
|
991
|
+
f"&$filter={f'{space}and{space}'.join(conditions)}" if conditions else ""
|
|
952
992
|
)
|
|
953
993
|
|
|
954
994
|
full_url = f"{base_url}?startDateTime={tic}{start_time}{tic}&endDateTime={tic}{end_time}{tic}{filter_value}"
|
|
@@ -988,4 +1028,6 @@ def list_activity_events(
|
|
|
988
1028
|
ignore_index=True,
|
|
989
1029
|
)
|
|
990
1030
|
|
|
1031
|
+
df["Creation Time"] = pd.to_datetime(df["Creation Time"])
|
|
1032
|
+
|
|
991
1033
|
return df
|