semantic-link-labs 0.4.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.

Potentially problematic release.


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

Files changed (52) hide show
  1. semantic_link_labs-0.4.1.dist-info/LICENSE +21 -0
  2. semantic_link_labs-0.4.1.dist-info/METADATA +22 -0
  3. semantic_link_labs-0.4.1.dist-info/RECORD +52 -0
  4. semantic_link_labs-0.4.1.dist-info/WHEEL +5 -0
  5. semantic_link_labs-0.4.1.dist-info/top_level.txt +1 -0
  6. sempy_labs/__init__.py +154 -0
  7. sempy_labs/_ai.py +496 -0
  8. sempy_labs/_clear_cache.py +39 -0
  9. sempy_labs/_connections.py +234 -0
  10. sempy_labs/_dax.py +70 -0
  11. sempy_labs/_generate_semantic_model.py +280 -0
  12. sempy_labs/_helper_functions.py +506 -0
  13. sempy_labs/_icons.py +4 -0
  14. sempy_labs/_list_functions.py +1372 -0
  15. sempy_labs/_model_auto_build.py +143 -0
  16. sempy_labs/_model_bpa.py +1354 -0
  17. sempy_labs/_model_dependencies.py +341 -0
  18. sempy_labs/_one_lake_integration.py +155 -0
  19. sempy_labs/_query_scale_out.py +447 -0
  20. sempy_labs/_refresh_semantic_model.py +184 -0
  21. sempy_labs/_tom.py +3766 -0
  22. sempy_labs/_translations.py +378 -0
  23. sempy_labs/_vertipaq.py +893 -0
  24. sempy_labs/directlake/__init__.py +45 -0
  25. sempy_labs/directlake/_directlake_schema_compare.py +110 -0
  26. sempy_labs/directlake/_directlake_schema_sync.py +128 -0
  27. sempy_labs/directlake/_fallback.py +62 -0
  28. sempy_labs/directlake/_get_directlake_lakehouse.py +69 -0
  29. sempy_labs/directlake/_get_shared_expression.py +59 -0
  30. sempy_labs/directlake/_guardrails.py +84 -0
  31. sempy_labs/directlake/_list_directlake_model_calc_tables.py +54 -0
  32. sempy_labs/directlake/_show_unsupported_directlake_objects.py +89 -0
  33. sempy_labs/directlake/_update_directlake_model_lakehouse_connection.py +81 -0
  34. sempy_labs/directlake/_update_directlake_partition_entity.py +64 -0
  35. sempy_labs/directlake/_warm_cache.py +210 -0
  36. sempy_labs/lakehouse/__init__.py +24 -0
  37. sempy_labs/lakehouse/_get_lakehouse_columns.py +81 -0
  38. sempy_labs/lakehouse/_get_lakehouse_tables.py +250 -0
  39. sempy_labs/lakehouse/_lakehouse.py +85 -0
  40. sempy_labs/lakehouse/_shortcuts.py +296 -0
  41. sempy_labs/migration/__init__.py +29 -0
  42. sempy_labs/migration/_create_pqt_file.py +239 -0
  43. sempy_labs/migration/_migrate_calctables_to_lakehouse.py +429 -0
  44. sempy_labs/migration/_migrate_calctables_to_semantic_model.py +150 -0
  45. sempy_labs/migration/_migrate_model_objects_to_semantic_model.py +524 -0
  46. sempy_labs/migration/_migrate_tables_columns_to_semantic_model.py +165 -0
  47. sempy_labs/migration/_migration_validation.py +227 -0
  48. sempy_labs/migration/_refresh_calc_tables.py +129 -0
  49. sempy_labs/report/__init__.py +35 -0
  50. sempy_labs/report/_generate_report.py +253 -0
  51. sempy_labs/report/_report_functions.py +855 -0
  52. sempy_labs/report/_report_rebind.py +131 -0
@@ -0,0 +1,253 @@
1
+ import sempy
2
+ import sempy.fabric as fabric
3
+ import pandas as pd
4
+ import json, base64, time
5
+ from typing import Optional
6
+ from sempy_labs._helper_functions import resolve_workspace_name_and_id
7
+
8
+
9
+ def create_report_from_reportjson(
10
+ report: str,
11
+ dataset: str,
12
+ report_json: str,
13
+ theme_json: Optional[str] = None,
14
+ workspace: Optional[str] = None,
15
+ ):
16
+ """
17
+ Creates a report based on a report.json file (and an optional themes.json file).
18
+
19
+ Parameters
20
+ ----------
21
+ report : str
22
+ Name of the report.
23
+ dataset : str
24
+ Name of the semantic model to connect to the report.
25
+ report_json : str
26
+ The report.json file to be used to create the report.
27
+ theme_json : str, default=None
28
+ The theme.json file to be used for the theme of the report.
29
+ workspace : str, default=None
30
+ The Fabric workspace name.
31
+ Defaults to None which resolves to the workspace of the attached lakehouse
32
+ or if no lakehouse attached, resolves to the workspace of the notebook.
33
+ """
34
+
35
+ (workspace, workspace_id) = resolve_workspace_name_and_id(workspace)
36
+
37
+ objectType = "Report"
38
+
39
+ dfI_m = fabric.list_items(workspace=workspace, type="SemanticModel")
40
+ dfI_model = dfI_m[(dfI_m["Display Name"] == dataset)]
41
+
42
+ if len(dfI_model) == 0:
43
+ print(
44
+ f"ERROR: The '{dataset}' semantic model does not exist in the '{workspace}' workspace."
45
+ )
46
+ return
47
+
48
+ datasetId = dfI_model["Id"].iloc[0]
49
+
50
+ dfI_r = fabric.list_items(workspace=workspace, type="Report")
51
+ dfI_rpt = dfI_r[(dfI_r["Display Name"] == report)]
52
+
53
+ if len(dfI_rpt) > 0:
54
+ print(
55
+ f"WARNING: '{report}' already exists as a report in the '{workspace}' workspace."
56
+ )
57
+ return
58
+
59
+ client = fabric.FabricRestClient()
60
+ defPBIR = {
61
+ "version": "1.0",
62
+ "datasetReference": {
63
+ "byPath": None,
64
+ "byConnection": {
65
+ "connectionString": None,
66
+ "pbiServiceModelId": None,
67
+ "pbiModelVirtualServerName": "sobe_wowvirtualserver",
68
+ "pbiModelDatabaseName": datasetId,
69
+ "name": "EntityDataSource",
70
+ "connectionType": "pbiServiceXmlaStyleLive",
71
+ },
72
+ },
73
+ }
74
+
75
+ def conv_b64(file):
76
+
77
+ loadJson = json.dumps(file)
78
+ f = base64.b64encode(loadJson.encode("utf-8")).decode("utf-8")
79
+
80
+ return f
81
+
82
+ definitionPBIR = conv_b64(defPBIR)
83
+ payloadReportJson = conv_b64(report_json)
84
+
85
+ if theme_json == None:
86
+ request_body = {
87
+ "displayName": report,
88
+ "type": objectType,
89
+ "definition": {
90
+ "parts": [
91
+ {
92
+ "path": "report.json",
93
+ "payload": payloadReportJson,
94
+ "payloadType": "InlineBase64",
95
+ },
96
+ {
97
+ "path": "definition.pbir",
98
+ "payload": definitionPBIR,
99
+ "payloadType": "InlineBase64",
100
+ },
101
+ ]
102
+ },
103
+ }
104
+ else:
105
+ payloadThemeJson = conv_b64(theme_json)
106
+ themeID = theme_json["payload"]["blob"]["displayName"]
107
+ themePath = "StaticResources/SharedResources/BaseThemes/" + themeID + ".json"
108
+ request_body = {
109
+ "displayName": report,
110
+ "type": objectType,
111
+ "definition": {
112
+ "parts": [
113
+ {
114
+ "path": "report.json",
115
+ "payload": payloadReportJson,
116
+ "payloadType": "InlineBase64",
117
+ },
118
+ {
119
+ "path": themePath,
120
+ "payload": payloadThemeJson,
121
+ "payloadType": "InlineBase64",
122
+ },
123
+ {
124
+ "path": "definition.pbir",
125
+ "payload": definitionPBIR,
126
+ "payloadType": "InlineBase64",
127
+ },
128
+ ]
129
+ },
130
+ }
131
+
132
+ response = client.post(f"/v1/workspaces/{workspace_id}/items", json=request_body)
133
+
134
+ if response.status_code == 201:
135
+ print("Report creation succeeded")
136
+ print(response.json())
137
+ elif response.status_code == 202:
138
+ operationId = response.headers["x-ms-operation-id"]
139
+ response = client.get(f"/v1/operations/{operationId}")
140
+ response_body = json.loads(response.content)
141
+ while response_body["status"] != "Succeeded":
142
+ time.sleep(3)
143
+ response = client.get(f"/v1/operations/{operationId}")
144
+ response_body = json.loads(response.content)
145
+ response = client.get(f"/v1/operations/{operationId}/result")
146
+ print("Report creation succeeded")
147
+ print(response.json())
148
+
149
+
150
+ def update_report_from_reportjson(
151
+ report: str, report_json: str, workspace: Optional[str] = None
152
+ ):
153
+ """
154
+ Updates a report based on a report.json file.
155
+
156
+ Parameters
157
+ ----------
158
+ report : str
159
+ Name of the report.
160
+ report_json : str
161
+ The report.json file to be used to update the report.
162
+ workspace : str, default=None
163
+ The Fabric workspace name in which the report resides.
164
+ Defaults to None which resolves to the workspace of the attached lakehouse
165
+ or if no lakehouse attached, resolves to the workspace of the notebook.
166
+ """
167
+
168
+ (workspace, workspace_id) = resolve_workspace_name_and_id(workspace)
169
+
170
+ objectType = "Report"
171
+
172
+ dfR = fabric.list_reports(workspace=workspace)
173
+ dfR_filt = dfR[(dfR["Name"] == report) & (dfR["Report Type"] == "PowerBIReport")]
174
+
175
+ if len(dfR_filt) == 0:
176
+ print(f"The '{report}' report does not exist in the '{workspace}' workspace.")
177
+ return
178
+
179
+ reportId = dfR_filt["Id"].iloc[0]
180
+ client = fabric.FabricRestClient()
181
+
182
+ response = client.post(
183
+ f"/v1/workspaces/{workspace_id}/items/{reportId}/getDefinition"
184
+ )
185
+ df_items = pd.json_normalize(response.json()["definition"]["parts"])
186
+ df_items_filt = df_items[df_items["path"] == "definition.pbir"]
187
+ rptDefFile = df_items_filt["payload"].iloc[0]
188
+ # datasetId = dfR_filt['Dataset Id'].iloc[0]
189
+ # datasetWorkspaceId = dfR_filt['Dataset Workspace Id'].iloc[0]
190
+
191
+ # defPBIR = {
192
+ # "version": "1.0",
193
+ # "datasetReference": {
194
+ # "byPath": None,
195
+ # "byConnection": {
196
+ # "connectionString": None,
197
+ # "pbiServiceModelId": None,
198
+ # "pbiModelVirtualServerName": "sobe_wowvirtualserver",
199
+ # "pbiModelDatabaseName": datasetId,
200
+ # "name": "EntityDataSource",
201
+ # "connectionType": "pbiServiceXmlaStyleLive"
202
+ # }
203
+ # }
204
+ # }
205
+
206
+ def conv_b64(file):
207
+
208
+ loadJson = json.dumps(file)
209
+ f = base64.b64encode(loadJson.encode("utf-8")).decode("utf-8")
210
+
211
+ return f
212
+
213
+ # definitionPBIR = conv_b64(defPBIR)
214
+ payloadReportJson = conv_b64(report_json)
215
+
216
+ request_body = {
217
+ "displayName": report,
218
+ "type": objectType,
219
+ "definition": {
220
+ "parts": [
221
+ {
222
+ "path": "report.json",
223
+ "payload": payloadReportJson,
224
+ "payloadType": "InlineBase64",
225
+ },
226
+ {
227
+ "path": "definition.pbir",
228
+ "payload": rptDefFile,
229
+ "payloadType": "InlineBase64",
230
+ },
231
+ ]
232
+ },
233
+ }
234
+
235
+ response = client.post(
236
+ f"/v1/workspaces/{workspace_id}/reports/{reportId}/updateDefinition",
237
+ json=request_body,
238
+ )
239
+
240
+ if response.status_code == 201:
241
+ print(f"The '{report}' report has been successfully updated.")
242
+ # print(response.json())
243
+ elif response.status_code == 202:
244
+ operationId = response.headers["x-ms-operation-id"]
245
+ response = client.get(f"/v1/operations/{operationId}")
246
+ response_body = json.loads(response.content)
247
+ while response_body["status"] != "Succeeded":
248
+ time.sleep(3)
249
+ response = client.get(f"/v1/operations/{operationId}")
250
+ response_body = json.loads(response.content)
251
+ response = client.get(f"/v1/operations/{operationId}/result")
252
+ print(f"The '{report}' report has been successfully updated.")
253
+ # print(response.json())