semantic-link-labs 0.11.1__py3-none-any.whl → 0.11.3__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 (137) hide show
  1. {semantic_link_labs-0.11.1.dist-info → semantic_link_labs-0.11.3.dist-info}/METADATA +7 -6
  2. semantic_link_labs-0.11.3.dist-info/RECORD +212 -0
  3. sempy_labs/__init__.py +65 -71
  4. sempy_labs/_a_lib_info.py +1 -1
  5. sempy_labs/_ai.py +1 -1
  6. sempy_labs/_capacities.py +2 -2
  7. sempy_labs/_capacity_migration.py +5 -5
  8. sempy_labs/_clear_cache.py +1 -1
  9. sempy_labs/_connections.py +2 -2
  10. sempy_labs/_dashboards.py +16 -16
  11. sempy_labs/_data_pipelines.py +1 -1
  12. sempy_labs/_dataflows.py +101 -26
  13. sempy_labs/_dax.py +3 -3
  14. sempy_labs/_delta_analyzer.py +4 -4
  15. sempy_labs/_delta_analyzer_history.py +1 -1
  16. sempy_labs/_deployment_pipelines.py +1 -1
  17. sempy_labs/_environments.py +22 -21
  18. sempy_labs/_eventhouses.py +12 -11
  19. sempy_labs/_eventstreams.py +12 -11
  20. sempy_labs/_external_data_shares.py +78 -23
  21. sempy_labs/_gateways.py +47 -45
  22. sempy_labs/_generate_semantic_model.py +3 -3
  23. sempy_labs/_git.py +1 -1
  24. sempy_labs/_graphQL.py +12 -11
  25. sempy_labs/_helper_functions.py +169 -5
  26. sempy_labs/_job_scheduler.py +56 -54
  27. sempy_labs/_kql_databases.py +16 -17
  28. sempy_labs/_kql_querysets.py +12 -11
  29. sempy_labs/_kusto.py +2 -2
  30. sempy_labs/_labels.py +126 -0
  31. sempy_labs/_list_functions.py +2 -2
  32. sempy_labs/_managed_private_endpoints.py +18 -15
  33. sempy_labs/_mirrored_databases.py +16 -15
  34. sempy_labs/_mirrored_warehouses.py +12 -11
  35. sempy_labs/_ml_experiments.py +11 -10
  36. sempy_labs/_model_auto_build.py +3 -3
  37. sempy_labs/_model_bpa.py +5 -5
  38. sempy_labs/_model_bpa_bulk.py +3 -3
  39. sempy_labs/_model_dependencies.py +1 -1
  40. sempy_labs/_mounted_data_factories.py +12 -12
  41. sempy_labs/_notebooks.py +151 -2
  42. sempy_labs/_one_lake_integration.py +1 -1
  43. sempy_labs/_query_scale_out.py +1 -1
  44. sempy_labs/_refresh_semantic_model.py +1 -1
  45. sempy_labs/_semantic_models.py +30 -28
  46. sempy_labs/_spark.py +1 -1
  47. sempy_labs/_sql.py +1 -1
  48. sempy_labs/_sql_endpoints.py +12 -11
  49. sempy_labs/_sqldatabase.py +15 -15
  50. sempy_labs/_tags.py +11 -10
  51. sempy_labs/_translations.py +1 -1
  52. sempy_labs/_user_delegation_key.py +2 -2
  53. sempy_labs/_vertipaq.py +3 -3
  54. sempy_labs/_vpax.py +1 -1
  55. sempy_labs/_warehouses.py +15 -14
  56. sempy_labs/_workloads.py +1 -1
  57. sempy_labs/_workspace_identity.py +1 -1
  58. sempy_labs/_workspaces.py +14 -13
  59. sempy_labs/admin/__init__.py +18 -18
  60. sempy_labs/admin/_activities.py +46 -46
  61. sempy_labs/admin/_apps.py +28 -26
  62. sempy_labs/admin/_artifacts.py +15 -15
  63. sempy_labs/admin/_basic_functions.py +1 -2
  64. sempy_labs/admin/_capacities.py +84 -82
  65. sempy_labs/admin/_dataflows.py +2 -2
  66. sempy_labs/admin/_datasets.py +50 -48
  67. sempy_labs/admin/_domains.py +25 -19
  68. sempy_labs/admin/_external_data_share.py +24 -22
  69. sempy_labs/admin/_git.py +17 -17
  70. sempy_labs/admin/_items.py +47 -45
  71. sempy_labs/admin/_reports.py +61 -58
  72. sempy_labs/admin/_scanner.py +2 -2
  73. sempy_labs/admin/_shared.py +18 -18
  74. sempy_labs/admin/_tags.py +2 -2
  75. sempy_labs/admin/_tenant.py +57 -51
  76. sempy_labs/admin/_users.py +16 -15
  77. sempy_labs/admin/_workspaces.py +2 -2
  78. sempy_labs/directlake/__init__.py +12 -12
  79. sempy_labs/directlake/_directlake_schema_compare.py +3 -3
  80. sempy_labs/directlake/_directlake_schema_sync.py +9 -7
  81. sempy_labs/directlake/_dl_helper.py +5 -2
  82. sempy_labs/directlake/_generate_shared_expression.py +1 -1
  83. sempy_labs/directlake/_get_directlake_lakehouse.py +1 -1
  84. sempy_labs/directlake/_guardrails.py +1 -1
  85. sempy_labs/directlake/_list_directlake_model_calc_tables.py +3 -3
  86. sempy_labs/directlake/_show_unsupported_directlake_objects.py +1 -1
  87. sempy_labs/directlake/_update_directlake_model_lakehouse_connection.py +3 -3
  88. sempy_labs/directlake/_update_directlake_partition_entity.py +4 -4
  89. sempy_labs/directlake/_warm_cache.py +3 -3
  90. sempy_labs/graph/__init__.py +3 -3
  91. sempy_labs/graph/_groups.py +81 -78
  92. sempy_labs/graph/_teams.py +21 -21
  93. sempy_labs/graph/_users.py +109 -10
  94. sempy_labs/lakehouse/__init__.py +7 -7
  95. sempy_labs/lakehouse/_blobs.py +30 -30
  96. sempy_labs/lakehouse/_get_lakehouse_columns.py +2 -2
  97. sempy_labs/lakehouse/_get_lakehouse_tables.py +29 -27
  98. sempy_labs/lakehouse/_helper.py +38 -1
  99. sempy_labs/lakehouse/_lakehouse.py +16 -7
  100. sempy_labs/lakehouse/_livy_sessions.py +47 -42
  101. sempy_labs/lakehouse/_shortcuts.py +22 -21
  102. sempy_labs/migration/__init__.py +8 -8
  103. sempy_labs/migration/_create_pqt_file.py +2 -2
  104. sempy_labs/migration/_migrate_calctables_to_lakehouse.py +35 -44
  105. sempy_labs/migration/_migrate_calctables_to_semantic_model.py +9 -20
  106. sempy_labs/migration/_migrate_model_objects_to_semantic_model.py +5 -9
  107. sempy_labs/migration/_migrate_tables_columns_to_semantic_model.py +11 -20
  108. sempy_labs/migration/_migration_validation.py +1 -2
  109. sempy_labs/migration/_refresh_calc_tables.py +2 -2
  110. sempy_labs/mirrored_azure_databricks_catalog/__init__.py +2 -2
  111. sempy_labs/mirrored_azure_databricks_catalog/_discover.py +40 -40
  112. sempy_labs/mirrored_azure_databricks_catalog/_refresh_catalog_metadata.py +1 -1
  113. sempy_labs/ml_model/__init__.py +23 -0
  114. sempy_labs/ml_model/_functions.py +427 -0
  115. sempy_labs/report/__init__.py +10 -10
  116. sempy_labs/report/_download_report.py +2 -2
  117. sempy_labs/report/_export_report.py +2 -2
  118. sempy_labs/report/_generate_report.py +1 -1
  119. sempy_labs/report/_paginated.py +1 -1
  120. sempy_labs/report/_report_bpa.py +4 -3
  121. sempy_labs/report/_report_functions.py +3 -3
  122. sempy_labs/report/_report_list_functions.py +3 -3
  123. sempy_labs/report/_report_rebind.py +1 -1
  124. sempy_labs/report/_reportwrapper.py +248 -250
  125. sempy_labs/report/_save_report.py +3 -3
  126. sempy_labs/theme/_org_themes.py +19 -6
  127. sempy_labs/tom/__init__.py +1 -1
  128. sempy_labs/tom/_model.py +13 -8
  129. sempy_labs/variable_library/__init__.py +19 -0
  130. sempy_labs/variable_library/_functions.py +403 -0
  131. semantic_link_labs-0.11.1.dist-info/RECORD +0 -210
  132. sempy_labs/_dax_query_view.py +0 -57
  133. sempy_labs/_ml_models.py +0 -110
  134. sempy_labs/_variable_libraries.py +0 -91
  135. {semantic_link_labs-0.11.1.dist-info → semantic_link_labs-0.11.3.dist-info}/WHEEL +0 -0
  136. {semantic_link_labs-0.11.1.dist-info → semantic_link_labs-0.11.3.dist-info}/licenses/LICENSE +0 -0
  137. {semantic_link_labs-0.11.1.dist-info → semantic_link_labs-0.11.3.dist-info}/top_level.txt +0 -0
@@ -3,9 +3,9 @@ import base64
3
3
  import json
4
4
  import sempy.fabric as fabric
5
5
  import sempy_labs._icons as icons
6
- from sempy_labs.report._generate_report import get_report_definition
7
- from sempy_labs._generate_semantic_model import get_semantic_model_definition
8
- from sempy_labs._helper_functions import (
6
+ from ._generate_report import get_report_definition
7
+ from .._generate_semantic_model import get_semantic_model_definition
8
+ from .._helper_functions import (
9
9
  _mount,
10
10
  resolve_workspace_name_and_id,
11
11
  resolve_item_name,
@@ -1,6 +1,6 @@
1
1
  import pandas as pd
2
2
  from uuid import UUID
3
- from sempy_labs._helper_functions import (
3
+ from .._helper_functions import (
4
4
  _is_valid_uuid,
5
5
  _base_api,
6
6
  _update_dataframe_datatypes,
@@ -24,8 +24,8 @@ def list_org_themes() -> pd.DataFrame:
24
24
  """
25
25
  Lists all `organizational themes <https://www.linkedin.com/pulse/organizational-themes-preview-pbicorevisuals-j7jxe/>`_ in Power BI. Note that this uses an internal API and may break at any time.
26
26
 
27
- Returns:
28
- --------
27
+ Returns
28
+ -------
29
29
  pandas.DataFrame
30
30
  A dataframe containing the details of the organizational themes.
31
31
  """
@@ -67,6 +67,19 @@ def list_org_themes() -> pd.DataFrame:
67
67
 
68
68
 
69
69
  def resolve_theme_id(theme: str | UUID):
70
+ """
71
+ Resolves the ID of an organization theme by its name or ID.
72
+
73
+ Parameters
74
+ ----------
75
+ theme : str | uuid.UUID
76
+ The name or ID of the organization theme.
77
+
78
+ Returns
79
+ -------
80
+ uuid.UUID
81
+ The ID of the organization theme.
82
+ """
70
83
 
71
84
  if _is_valid_uuid(theme):
72
85
  return theme
@@ -83,13 +96,13 @@ def get_org_theme_json(theme: str | UUID) -> dict:
83
96
  """
84
97
  Retrieves the JSON representation of an organization theme by its name or ID.
85
98
 
86
- Parameters:
99
+ Parameters
87
100
  ----------
88
101
  theme : str | uuid.UUID
89
102
  The name or ID of the organization theme.
90
103
 
91
- Returns:
92
- --------
104
+ Returns
105
+ -------
93
106
  dict
94
107
  The JSON representation of the organization theme.
95
108
  """
@@ -1,3 +1,3 @@
1
- from sempy_labs.tom._model import TOMWrapper, connect_semantic_model
1
+ from ._model import TOMWrapper, connect_semantic_model
2
2
 
3
3
  __all__ = ["TOMWrapper", "connect_semantic_model"]
sempy_labs/tom/_model.py CHANGED
@@ -6,7 +6,7 @@ import os
6
6
  import json
7
7
  from datetime import datetime
8
8
  from decimal import Decimal
9
- from sempy_labs._helper_functions import (
9
+ from .._helper_functions import (
10
10
  format_dax_object_name,
11
11
  generate_guid,
12
12
  _make_list_unique,
@@ -18,9 +18,9 @@ from sempy_labs._helper_functions import (
18
18
  resolve_lakehouse_id,
19
19
  _validate_weight,
20
20
  )
21
- from sempy_labs._list_functions import list_relationships
22
- from sempy_labs._refresh_semantic_model import refresh_semantic_model
23
- from sempy_labs.directlake._dl_helper import check_fallback_reason
21
+ from .._list_functions import list_relationships
22
+ from .._refresh_semantic_model import refresh_semantic_model
23
+ from ..directlake._dl_helper import check_fallback_reason
24
24
  from contextlib import contextmanager
25
25
  from typing import List, Iterator, Optional, Union, TYPE_CHECKING, Literal
26
26
  from sempy._utils._log import log
@@ -28,7 +28,7 @@ import sempy_labs._icons as icons
28
28
  import ast
29
29
  from uuid import UUID
30
30
  import sempy_labs._authentication as auth
31
- from sempy_labs.lakehouse._lakehouse import lakehouse_attached
31
+ from ..lakehouse._lakehouse import lakehouse_attached
32
32
 
33
33
 
34
34
  if TYPE_CHECKING:
@@ -1200,7 +1200,7 @@ class TOMWrapper:
1200
1200
  entity_name: str,
1201
1201
  expression: Optional[str] = None,
1202
1202
  description: Optional[str] = None,
1203
- schema_name: str = "dbo",
1203
+ schema_name: str = None,
1204
1204
  ):
1205
1205
  """
1206
1206
  Adds an entity partition to a table within a semantic model.
@@ -1216,7 +1216,7 @@ class TOMWrapper:
1216
1216
  Defaults to None which resolves to the 'DatabaseQuery' expression.
1217
1217
  description : str, default=None
1218
1218
  A description for the partition.
1219
- schema_name : str, default="dbo"
1219
+ schema_name : str, default=None
1220
1220
  The schema name.
1221
1221
  """
1222
1222
  import Microsoft.AnalysisServices.Tabular as TOM
@@ -1228,7 +1228,8 @@ class TOMWrapper:
1228
1228
  ep.ExpressionSource = self.model.Expressions["DatabaseQuery"]
1229
1229
  else:
1230
1230
  ep.ExpressionSource = self.model.Expressions[expression]
1231
- ep.SchemaName = schema_name
1231
+ if schema_name:
1232
+ ep.SchemaName = schema_name
1232
1233
  p = TOM.Partition()
1233
1234
  p.Name = table_name
1234
1235
  p.Source = ep
@@ -1236,6 +1237,10 @@ class TOMWrapper:
1236
1237
  if description is not None:
1237
1238
  p.Description = description
1238
1239
 
1240
+ # For the source lineage tag
1241
+ if schema_name is None:
1242
+ schema_name = "dbo"
1243
+
1239
1244
  self.model.Tables[table_name].Partitions.Add(p)
1240
1245
  self.model.Tables[table_name].SourceLineageTag = (
1241
1246
  f"[{schema_name}].[{entity_name}]"
@@ -0,0 +1,19 @@
1
+ from ._functions import (
2
+ get_variable_library,
3
+ list_variables,
4
+ list_variable_libraries,
5
+ delete_variable_library,
6
+ get_variable_library_definition,
7
+ get_variable_values,
8
+ get_variable_value,
9
+ )
10
+
11
+ __all__ = [
12
+ "get_variable_library",
13
+ "list_variables",
14
+ "list_variable_libraries",
15
+ "delete_variable_library",
16
+ "get_variable_library_definition",
17
+ "get_variable_values",
18
+ "get_variable_value",
19
+ ]
@@ -0,0 +1,403 @@
1
+ from sempy_labs._helper_functions import (
2
+ resolve_item_id,
3
+ resolve_workspace_id,
4
+ _base_api,
5
+ _create_dataframe,
6
+ _update_dataframe_datatypes,
7
+ delete_item,
8
+ _decode_b64,
9
+ )
10
+ import pandas as pd
11
+ from typing import Any, Optional, List, Union
12
+ from uuid import UUID
13
+ from sempy._utils._log import log
14
+ import json
15
+ import sempy_labs._icons as icons
16
+
17
+
18
+ @log
19
+ def get_variable_library(
20
+ variable_library: str | UUID, workspace: Optional[str | UUID] = None
21
+ ) -> pd.DataFrame:
22
+ """
23
+ Returns properties of the specified variable library.
24
+
25
+ This is a wrapper function for the following API: `Items - Get Variable Library <https://learn.microsoft.com/rest/api/fabric/variablelibrary/items/get-variable-library>`_.
26
+
27
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
28
+
29
+ Parameters
30
+ ----------
31
+ variable_library : str | uuid.UUID
32
+ Name or ID of the variable library.
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
+ Returns
39
+ -------
40
+ pandas.DataFrame
41
+ A pandas dataframe showing the properties of the variable library.
42
+ """
43
+
44
+ columns = {
45
+ "Variable Library Name": "string",
46
+ "Variable Library Id": "string",
47
+ "Description": "string",
48
+ "Active Value Set Name": "string",
49
+ }
50
+ df = _create_dataframe(columns=columns)
51
+
52
+ workspace_id = resolve_workspace_id(workspace)
53
+ variable_library_id = resolve_item_id(
54
+ item=variable_library, type="VariableLibrary", workspace=workspace
55
+ )
56
+
57
+ response = _base_api(
58
+ request=f"/v1/workspaces/{workspace_id}/variableLibraries/{variable_library_id}",
59
+ client="fabric_sp",
60
+ )
61
+
62
+ result = response.json()
63
+ prop = result.get("properties", {})
64
+
65
+ if prop:
66
+ df = pd.DataFrame(
67
+ [
68
+ {
69
+ "Variable Library Name": result.get("displayName"),
70
+ "Variable Library Id": result.get("id"),
71
+ "Description": result.get("description"),
72
+ "Active Value Set Name": prop.get("activeValueSetName"),
73
+ }
74
+ ],
75
+ columns=list(columns.keys()),
76
+ )
77
+
78
+ _update_dataframe_datatypes(dataframe=df, column_map=columns)
79
+
80
+ return df
81
+
82
+
83
+ @log
84
+ def list_variable_libraries(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
85
+ """
86
+ Shows the variable libraries within a workspace.
87
+
88
+ This is a wrapper function for the following API: `Items - List Variable Libraries <https://learn.microsoft.com/rest/api/fabric/variablelibrary/items/list-variable-libraries>`_.
89
+
90
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
91
+
92
+ Parameters
93
+ ----------
94
+ workspace : str | uuid.UUID, default=None
95
+ The Fabric workspace name or ID.
96
+ Defaults to None which resolves to the workspace of the attached lakehouse
97
+ or if no lakehouse attached, resolves to the workspace of the notebook.
98
+
99
+ Returns
100
+ -------
101
+ pandas.DataFrame
102
+ A pandas dataframe showing the variable libraries within a workspace.
103
+ """
104
+
105
+ columns = {
106
+ "Variable Library Name": "string",
107
+ "Variable Library Id": "string",
108
+ "Description": "string",
109
+ "Active Value Set Name": "string",
110
+ }
111
+ df = _create_dataframe(columns=columns)
112
+
113
+ workspace_id = resolve_workspace_id(workspace)
114
+
115
+ responses = _base_api(
116
+ request=f"/v1/workspaces/{workspace_id}/VariableLibraries",
117
+ uses_pagination=True,
118
+ client="fabric_sp",
119
+ )
120
+
121
+ rows = []
122
+ for r in responses:
123
+ for v in r.get("value", []):
124
+ prop = v.get("properties", {})
125
+
126
+ rows.append(
127
+ {
128
+ "Variable Library Name": v.get("displayName"),
129
+ "Variable Library Id": v.get("id"),
130
+ "Description": v.get("description"),
131
+ "Active Value Set Name": prop.get("activeValueSetName"),
132
+ }
133
+ )
134
+
135
+ if rows:
136
+ df = pd.DataFrame(rows, columns=list(columns.keys()))
137
+ _update_dataframe_datatypes(dataframe=df, column_map=columns)
138
+
139
+ return df
140
+
141
+
142
+ @log
143
+ def delete_variable_library(
144
+ variable_library: str | UUID, workspace: Optional[str | UUID] = None
145
+ ):
146
+ """
147
+ Deletes a variable library.
148
+
149
+ This is a wrapper function for the following API: `Items - Delete Variable Library https://learn.microsoft.com/rest/api/fabric/variablelibrary/items/delete-variable-library>`_.
150
+
151
+ Parameters
152
+ ----------
153
+ navariable_libraryme: str | uuid.UUID
154
+ Name or ID of the variable library.
155
+ workspace : str | uuid.UUID, default=None
156
+ The Fabric workspace name or ID.
157
+ Defaults to None which resolves to the workspace of the attached lakehouse
158
+ or if no lakehouse attached, resolves to the workspace of the notebook.
159
+ """
160
+
161
+ delete_item(item=variable_library, type="VariableLibrary", workspace=workspace)
162
+
163
+
164
+ @log
165
+ def get_variable_library_definition(
166
+ variable_library: str | UUID,
167
+ workspace: Optional[str | UUID] = None,
168
+ decode: bool = True,
169
+ return_dataframe: bool = False,
170
+ ) -> dict | pd.DataFrame:
171
+ """
172
+ Gets the definition of a variable library.
173
+
174
+ This is a wrapper function for the following API: `Items - Get Variable Library Definition <https://learn.microsoft.com/rest/api/fabric/variablelibrary/items/delete-variable-library>`_.
175
+
176
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
177
+
178
+ Parameters
179
+ ----------
180
+ workspace : str | uuid.UUID, default=None
181
+ The Fabric workspace name or ID.
182
+ Defaults to None which resolves to the workspace of the attached lakehouse
183
+ or if no lakehouse attached, resolves to the workspace of the notebook.
184
+
185
+ Returns
186
+ -------
187
+ dict | pandas.DataFrame
188
+ A dictionary showing the definition or a pandas dataframe showing the definition.
189
+ """
190
+
191
+ workspace_id = resolve_workspace_id(workspace)
192
+ variable_library_id = resolve_item_id(
193
+ item=variable_library, type="VariableLibrary", workspace=workspace
194
+ )
195
+
196
+ result = _base_api(
197
+ request=f"/v1/workspaces/{workspace_id}/variableLibraries/{variable_library_id}/getDefinition",
198
+ method="post",
199
+ client="fabric_sp",
200
+ status_codes=None,
201
+ lro_return_json=True,
202
+ )
203
+
204
+ if decode:
205
+ definition = {"definition": {"parts": []}}
206
+
207
+ for part in result.get("definition", {}).get("parts", []):
208
+ path = part.get("path")
209
+ payload = _decode_b64(part.get("payload"))
210
+ definition["definition"]["parts"].append({"path": path, "payload": payload})
211
+ else:
212
+ definition = result.copy()
213
+
214
+ if return_dataframe:
215
+ df = pd.DataFrame(definition["definition"]["parts"])
216
+ df.columns = ["Path", "Payload", "Payload Type"]
217
+ return df
218
+ else:
219
+ return definition
220
+
221
+
222
+ @log
223
+ def list_variables(
224
+ variable_library: str | UUID, workspace: Optional[str | UUID] = None
225
+ ) -> pd.DataFrame:
226
+ """
227
+ Lists the variables in a variable library.
228
+
229
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
230
+
231
+ Parameters
232
+ ----------
233
+ variable_library : str | uuid.UUID
234
+ Name or ID of the variable library.
235
+ workspace : str | uuid.UUID, default=None
236
+ The Fabric workspace name or ID.
237
+ Defaults to None which resolves to the workspace of the attached lakehouse
238
+ or if no lakehouse attached, resolves to the workspace of the notebook.
239
+
240
+ Returns
241
+ -------
242
+ pandas.DataFrame
243
+ A pandas dataframe showing the variables within a variable library.
244
+ """
245
+
246
+ result = get_variable_library_definition(
247
+ variable_library=variable_library,
248
+ workspace=workspace,
249
+ decode=True,
250
+ return_dataframe=False,
251
+ )
252
+
253
+ columns = {
254
+ "Variable Name": "string",
255
+ "Note": "string",
256
+ "Type": "string",
257
+ "Value": "string",
258
+ }
259
+
260
+ df = _create_dataframe(columns=columns)
261
+
262
+ rows = []
263
+ for part in result.get("definition").get("parts"):
264
+ path = part.get("path")
265
+ payload = json.loads(part.get("payload"))
266
+ if path == "variables.json":
267
+
268
+ for variable in payload.get("variables", []):
269
+ rows.append(
270
+ {
271
+ "Variable Name": variable.get("name"),
272
+ "Note": variable.get("note"),
273
+ "Type": variable.get("type"),
274
+ "Value": variable.get("value"),
275
+ }
276
+ )
277
+
278
+ if rows:
279
+ df = pd.DataFrame(rows, columns=list(columns.keys()))
280
+
281
+ for part in result.get("definition", {}).get("parts", []):
282
+ path = part.get("path")
283
+ if path.startswith("valueSets") and path.endswith(".json"):
284
+ payload = json.loads(part.get("payload"))
285
+ value_set_name = payload.get("name")
286
+
287
+ # Initialize the new column with None (or pd.NA)
288
+ df[value_set_name] = None
289
+
290
+ for override in payload.get("variableOverrides", []):
291
+ variable_name = override.get("name")
292
+ variable_value = override.get("value")
293
+
294
+ # Set the value in the appropriate row and column
295
+ df.loc[df["Variable Name"] == variable_name, value_set_name] = (
296
+ variable_value
297
+ )
298
+
299
+ return df
300
+
301
+
302
+ @log
303
+ def get_variable_values(
304
+ variable_names: List[str],
305
+ variable_library: Union[str, UUID],
306
+ workspace: Optional[Union[str, UUID]] = None,
307
+ value_set: Optional[str] = None,
308
+ ) -> dict:
309
+ """
310
+ Gets the values of multiple variables from a variable library with a single call to list_variables.
311
+
312
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
313
+
314
+ Parameters
315
+ ----------
316
+ variable_names : List[str]
317
+ A list of variable names to retrieve.
318
+ variable_library : str | uuid.UUID
319
+ Name or ID of the variable library.
320
+ workspace : str | uuid.UUID, default=None
321
+ The Fabric workspace name or ID.
322
+ Defaults to None which resolves to the workspace of the attached lakehouse
323
+ or if no lakehouse attached, resolves to the workspace of the notebook.
324
+ value_set : str, default=None
325
+ The name of the value set to use for variable overrides.
326
+ If None, the active value set of the variable library will be used.
327
+
328
+ Returns
329
+ -------
330
+ dict
331
+ Dictionary mapping variable names to their corresponding values.
332
+ """
333
+
334
+ if isinstance(variable_names, str):
335
+ variable_names = [variable_names]
336
+
337
+ if value_set is None:
338
+ vl_df = get_variable_library(
339
+ variable_library=variable_library, workspace=workspace
340
+ )
341
+ if vl_df.empty:
342
+ raise ValueError(
343
+ f"{icons.red_dot} The variable library '{variable_library}' does not exist within the '{workspace}' workspace."
344
+ )
345
+ value_set = vl_df["Active Value Set Name"].iloc[0]
346
+
347
+ df = list_variables(variable_library=variable_library, workspace=workspace)
348
+ found_variables = df[df["Variable Name"].isin(variable_names)]
349
+
350
+ missing = set(variable_names) - set(found_variables["Variable Name"])
351
+ if missing:
352
+ raise ValueError(
353
+ f"{icons.red_dot} The following variables do not exist in the '{variable_library}' variable library: {', '.join(missing)}"
354
+ )
355
+
356
+ if value_set == "Default value set":
357
+ value_set = "Value"
358
+ if value_set not in df.columns:
359
+ raise ValueError(
360
+ f"{icons.red_dot} The value set '{value_set}' does not exist in the variable library '{variable_library}' within the '{workspace}' workspace."
361
+ )
362
+
363
+ return dict(zip(found_variables["Variable Name"], found_variables[value_set]))
364
+
365
+
366
+ @log
367
+ def get_variable_value(
368
+ variable_name: str,
369
+ variable_library: str | UUID,
370
+ workspace: Optional[str | UUID] = None,
371
+ value_set: Optional[str] = None,
372
+ ) -> Any:
373
+ """
374
+ Gets the value of a single variable in a variable library.
375
+
376
+ Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
377
+
378
+ Parameters
379
+ ----------
380
+ variable_name : str
381
+ Name of the variable.
382
+ variable_library : str | uuid.UUID
383
+ Name or ID of the variable library.
384
+ workspace : str | uuid.UUID, default=None
385
+ The Fabric workspace name or ID.
386
+ Defaults to None which resolves to the workspace of the attached lakehouse
387
+ or if no lakehouse attached, resolves to the workspace of the notebook.
388
+ value_set : str, default=None
389
+ The name of the value set to use for variable overrides.
390
+ If None, the active value set of the variable library will be used.
391
+
392
+ Returns
393
+ -------
394
+ Any
395
+ The value of the variable.
396
+ """
397
+
398
+ return get_variable_values(
399
+ variable_names=[variable_name],
400
+ variable_library=variable_library,
401
+ workspace=workspace,
402
+ value_set=value_set,
403
+ )[variable_name]