semantic-link-labs 0.12.8__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.
- semantic_link_labs-0.12.8.dist-info/METADATA +354 -0
- semantic_link_labs-0.12.8.dist-info/RECORD +243 -0
- semantic_link_labs-0.12.8.dist-info/WHEEL +5 -0
- semantic_link_labs-0.12.8.dist-info/licenses/LICENSE +21 -0
- semantic_link_labs-0.12.8.dist-info/top_level.txt +1 -0
- sempy_labs/__init__.py +606 -0
- sempy_labs/_a_lib_info.py +2 -0
- sempy_labs/_ai.py +437 -0
- sempy_labs/_authentication.py +264 -0
- sempy_labs/_bpa_translation/_model/_translations_am-ET.po +869 -0
- sempy_labs/_bpa_translation/_model/_translations_ar-AE.po +908 -0
- sempy_labs/_bpa_translation/_model/_translations_bg-BG.po +968 -0
- sempy_labs/_bpa_translation/_model/_translations_ca-ES.po +963 -0
- sempy_labs/_bpa_translation/_model/_translations_cs-CZ.po +943 -0
- sempy_labs/_bpa_translation/_model/_translations_da-DK.po +945 -0
- sempy_labs/_bpa_translation/_model/_translations_de-DE.po +988 -0
- sempy_labs/_bpa_translation/_model/_translations_el-GR.po +993 -0
- sempy_labs/_bpa_translation/_model/_translations_es-ES.po +971 -0
- sempy_labs/_bpa_translation/_model/_translations_fa-IR.po +933 -0
- sempy_labs/_bpa_translation/_model/_translations_fi-FI.po +942 -0
- sempy_labs/_bpa_translation/_model/_translations_fr-FR.po +994 -0
- sempy_labs/_bpa_translation/_model/_translations_ga-IE.po +967 -0
- sempy_labs/_bpa_translation/_model/_translations_he-IL.po +902 -0
- sempy_labs/_bpa_translation/_model/_translations_hi-IN.po +944 -0
- sempy_labs/_bpa_translation/_model/_translations_hu-HU.po +963 -0
- sempy_labs/_bpa_translation/_model/_translations_id-ID.po +946 -0
- sempy_labs/_bpa_translation/_model/_translations_is-IS.po +939 -0
- sempy_labs/_bpa_translation/_model/_translations_it-IT.po +986 -0
- sempy_labs/_bpa_translation/_model/_translations_ja-JP.po +846 -0
- sempy_labs/_bpa_translation/_model/_translations_ko-KR.po +839 -0
- sempy_labs/_bpa_translation/_model/_translations_mt-MT.po +967 -0
- sempy_labs/_bpa_translation/_model/_translations_nl-NL.po +978 -0
- sempy_labs/_bpa_translation/_model/_translations_pl-PL.po +962 -0
- sempy_labs/_bpa_translation/_model/_translations_pt-BR.po +962 -0
- sempy_labs/_bpa_translation/_model/_translations_pt-PT.po +957 -0
- sempy_labs/_bpa_translation/_model/_translations_ro-RO.po +968 -0
- sempy_labs/_bpa_translation/_model/_translations_ru-RU.po +964 -0
- sempy_labs/_bpa_translation/_model/_translations_sk-SK.po +952 -0
- sempy_labs/_bpa_translation/_model/_translations_sl-SL.po +950 -0
- sempy_labs/_bpa_translation/_model/_translations_sv-SE.po +942 -0
- sempy_labs/_bpa_translation/_model/_translations_ta-IN.po +976 -0
- sempy_labs/_bpa_translation/_model/_translations_te-IN.po +947 -0
- sempy_labs/_bpa_translation/_model/_translations_th-TH.po +924 -0
- sempy_labs/_bpa_translation/_model/_translations_tr-TR.po +953 -0
- sempy_labs/_bpa_translation/_model/_translations_uk-UA.po +961 -0
- sempy_labs/_bpa_translation/_model/_translations_zh-CN.po +804 -0
- sempy_labs/_bpa_translation/_model/_translations_zu-ZA.po +969 -0
- sempy_labs/_capacities.py +1198 -0
- sempy_labs/_capacity_migration.py +660 -0
- sempy_labs/_clear_cache.py +351 -0
- sempy_labs/_connections.py +610 -0
- sempy_labs/_dashboards.py +69 -0
- sempy_labs/_data_access_security.py +98 -0
- sempy_labs/_data_pipelines.py +162 -0
- sempy_labs/_dataflows.py +668 -0
- sempy_labs/_dax.py +501 -0
- sempy_labs/_daxformatter.py +80 -0
- sempy_labs/_delta_analyzer.py +467 -0
- sempy_labs/_delta_analyzer_history.py +301 -0
- sempy_labs/_dictionary_diffs.py +221 -0
- sempy_labs/_documentation.py +147 -0
- sempy_labs/_domains.py +51 -0
- sempy_labs/_eventhouses.py +182 -0
- sempy_labs/_external_data_shares.py +230 -0
- sempy_labs/_gateways.py +521 -0
- sempy_labs/_generate_semantic_model.py +521 -0
- sempy_labs/_get_connection_string.py +84 -0
- sempy_labs/_git.py +543 -0
- sempy_labs/_graphQL.py +90 -0
- sempy_labs/_helper_functions.py +2833 -0
- sempy_labs/_icons.py +149 -0
- sempy_labs/_job_scheduler.py +609 -0
- sempy_labs/_kql_databases.py +149 -0
- sempy_labs/_kql_querysets.py +124 -0
- sempy_labs/_kusto.py +137 -0
- sempy_labs/_labels.py +124 -0
- sempy_labs/_list_functions.py +1720 -0
- sempy_labs/_managed_private_endpoints.py +253 -0
- sempy_labs/_mirrored_databases.py +416 -0
- sempy_labs/_mirrored_warehouses.py +60 -0
- sempy_labs/_ml_experiments.py +113 -0
- sempy_labs/_model_auto_build.py +140 -0
- sempy_labs/_model_bpa.py +557 -0
- sempy_labs/_model_bpa_bulk.py +378 -0
- sempy_labs/_model_bpa_rules.py +859 -0
- sempy_labs/_model_dependencies.py +343 -0
- sempy_labs/_mounted_data_factories.py +123 -0
- sempy_labs/_notebooks.py +441 -0
- sempy_labs/_one_lake_integration.py +151 -0
- sempy_labs/_onelake.py +131 -0
- sempy_labs/_query_scale_out.py +433 -0
- sempy_labs/_refresh_semantic_model.py +435 -0
- sempy_labs/_semantic_models.py +468 -0
- sempy_labs/_spark.py +455 -0
- sempy_labs/_sql.py +241 -0
- sempy_labs/_sql_audit_settings.py +207 -0
- sempy_labs/_sql_endpoints.py +214 -0
- sempy_labs/_tags.py +201 -0
- sempy_labs/_translations.py +43 -0
- sempy_labs/_user_delegation_key.py +44 -0
- sempy_labs/_utils.py +79 -0
- sempy_labs/_vertipaq.py +1021 -0
- sempy_labs/_vpax.py +388 -0
- sempy_labs/_warehouses.py +234 -0
- sempy_labs/_workloads.py +140 -0
- sempy_labs/_workspace_identity.py +72 -0
- sempy_labs/_workspaces.py +595 -0
- sempy_labs/admin/__init__.py +170 -0
- sempy_labs/admin/_activities.py +167 -0
- sempy_labs/admin/_apps.py +145 -0
- sempy_labs/admin/_artifacts.py +65 -0
- sempy_labs/admin/_basic_functions.py +463 -0
- sempy_labs/admin/_capacities.py +508 -0
- sempy_labs/admin/_dataflows.py +45 -0
- sempy_labs/admin/_datasets.py +186 -0
- sempy_labs/admin/_domains.py +522 -0
- sempy_labs/admin/_external_data_share.py +100 -0
- sempy_labs/admin/_git.py +72 -0
- sempy_labs/admin/_items.py +265 -0
- sempy_labs/admin/_labels.py +211 -0
- sempy_labs/admin/_reports.py +241 -0
- sempy_labs/admin/_scanner.py +118 -0
- sempy_labs/admin/_shared.py +82 -0
- sempy_labs/admin/_sharing_links.py +110 -0
- sempy_labs/admin/_tags.py +131 -0
- sempy_labs/admin/_tenant.py +503 -0
- sempy_labs/admin/_tenant_keys.py +89 -0
- sempy_labs/admin/_users.py +140 -0
- sempy_labs/admin/_workspaces.py +236 -0
- sempy_labs/deployment_pipeline/__init__.py +23 -0
- sempy_labs/deployment_pipeline/_items.py +580 -0
- sempy_labs/directlake/__init__.py +57 -0
- sempy_labs/directlake/_autosync.py +58 -0
- sempy_labs/directlake/_directlake_schema_compare.py +120 -0
- sempy_labs/directlake/_directlake_schema_sync.py +161 -0
- sempy_labs/directlake/_dl_helper.py +274 -0
- sempy_labs/directlake/_generate_shared_expression.py +94 -0
- sempy_labs/directlake/_get_directlake_lakehouse.py +62 -0
- sempy_labs/directlake/_get_shared_expression.py +34 -0
- sempy_labs/directlake/_guardrails.py +96 -0
- sempy_labs/directlake/_list_directlake_model_calc_tables.py +70 -0
- sempy_labs/directlake/_show_unsupported_directlake_objects.py +90 -0
- sempy_labs/directlake/_update_directlake_model_lakehouse_connection.py +239 -0
- sempy_labs/directlake/_update_directlake_partition_entity.py +259 -0
- sempy_labs/directlake/_warm_cache.py +236 -0
- sempy_labs/dotnet_lib/dotnet.runtime.config.json +10 -0
- sempy_labs/environment/__init__.py +23 -0
- sempy_labs/environment/_items.py +212 -0
- sempy_labs/environment/_pubstage.py +223 -0
- sempy_labs/eventstream/__init__.py +37 -0
- sempy_labs/eventstream/_items.py +263 -0
- sempy_labs/eventstream/_topology.py +652 -0
- sempy_labs/graph/__init__.py +59 -0
- sempy_labs/graph/_groups.py +651 -0
- sempy_labs/graph/_sensitivity_labels.py +120 -0
- sempy_labs/graph/_teams.py +125 -0
- sempy_labs/graph/_user_licenses.py +96 -0
- sempy_labs/graph/_users.py +516 -0
- sempy_labs/graph_model/__init__.py +15 -0
- sempy_labs/graph_model/_background_jobs.py +63 -0
- sempy_labs/graph_model/_items.py +149 -0
- sempy_labs/lakehouse/__init__.py +67 -0
- sempy_labs/lakehouse/_blobs.py +247 -0
- sempy_labs/lakehouse/_get_lakehouse_columns.py +102 -0
- sempy_labs/lakehouse/_get_lakehouse_tables.py +274 -0
- sempy_labs/lakehouse/_helper.py +250 -0
- sempy_labs/lakehouse/_lakehouse.py +351 -0
- sempy_labs/lakehouse/_livy_sessions.py +143 -0
- sempy_labs/lakehouse/_materialized_lake_views.py +157 -0
- sempy_labs/lakehouse/_partitioning.py +165 -0
- sempy_labs/lakehouse/_schemas.py +217 -0
- sempy_labs/lakehouse/_shortcuts.py +440 -0
- sempy_labs/migration/__init__.py +35 -0
- sempy_labs/migration/_create_pqt_file.py +238 -0
- sempy_labs/migration/_direct_lake_to_import.py +105 -0
- sempy_labs/migration/_migrate_calctables_to_lakehouse.py +398 -0
- sempy_labs/migration/_migrate_calctables_to_semantic_model.py +148 -0
- sempy_labs/migration/_migrate_model_objects_to_semantic_model.py +533 -0
- sempy_labs/migration/_migrate_tables_columns_to_semantic_model.py +172 -0
- sempy_labs/migration/_migration_validation.py +71 -0
- sempy_labs/migration/_refresh_calc_tables.py +131 -0
- sempy_labs/mirrored_azure_databricks_catalog/__init__.py +15 -0
- sempy_labs/mirrored_azure_databricks_catalog/_discover.py +213 -0
- sempy_labs/mirrored_azure_databricks_catalog/_refresh_catalog_metadata.py +45 -0
- sempy_labs/ml_model/__init__.py +23 -0
- sempy_labs/ml_model/_functions.py +427 -0
- sempy_labs/report/_BPAReportTemplate.json +232 -0
- sempy_labs/report/__init__.py +55 -0
- sempy_labs/report/_bpareporttemplate/.pbi/localSettings.json +9 -0
- sempy_labs/report/_bpareporttemplate/.platform +11 -0
- sempy_labs/report/_bpareporttemplate/StaticResources/SharedResources/BaseThemes/CY24SU06.json +710 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/page.json +11 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/1b08bce3bebabb0a27a8/visual.json +191 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/2f22ddb70c301693c165/visual.json +438 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/3b1182230aa6c600b43a/visual.json +127 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/58577ba6380c69891500/visual.json +576 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/a2a8fa5028b3b776c96c/visual.json +207 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/adfd47ef30652707b987/visual.json +506 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/b6a80ee459e716e170b1/visual.json +127 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/ce3130a721c020cc3d81/visual.json +513 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/92735ae19b31712208ad/page.json +8 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/92735ae19b31712208ad/visuals/66e60dfb526437cd78d1/visual.json +112 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/page.json +11 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/07deb8bce824e1be37d7/visual.json +513 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/0b1c68838818b32ad03b/visual.json +352 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/0c171de9d2683d10b930/visual.json +37 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/0efa01be0510e40a645e/visual.json +542 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/6bf2f0eb830ab53cc668/visual.json +221 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/88d8141cb8500b60030c/visual.json +127 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/a753273590beed656a03/visual.json +576 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/b8fdc82cddd61ac447bc/visual.json +127 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/d37dce724a0ccc30044b/page.json +9 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/d37dce724a0ccc30044b/visuals/ce8532a7e25020271077/visual.json +38 -0
- sempy_labs/report/_bpareporttemplate/definition/pages/pages.json +10 -0
- sempy_labs/report/_bpareporttemplate/definition/report.json +176 -0
- sempy_labs/report/_bpareporttemplate/definition/version.json +4 -0
- sempy_labs/report/_bpareporttemplate/definition.pbir +14 -0
- sempy_labs/report/_download_report.py +76 -0
- sempy_labs/report/_export_report.py +257 -0
- sempy_labs/report/_generate_report.py +427 -0
- sempy_labs/report/_paginated.py +76 -0
- sempy_labs/report/_report_bpa.py +354 -0
- sempy_labs/report/_report_bpa_rules.py +115 -0
- sempy_labs/report/_report_functions.py +581 -0
- sempy_labs/report/_report_helper.py +227 -0
- sempy_labs/report/_report_list_functions.py +110 -0
- sempy_labs/report/_report_rebind.py +149 -0
- sempy_labs/report/_reportwrapper.py +3100 -0
- sempy_labs/report/_save_report.py +147 -0
- sempy_labs/snowflake_database/__init__.py +10 -0
- sempy_labs/snowflake_database/_items.py +105 -0
- sempy_labs/sql_database/__init__.py +21 -0
- sempy_labs/sql_database/_items.py +201 -0
- sempy_labs/sql_database/_mirroring.py +79 -0
- sempy_labs/theme/__init__.py +12 -0
- sempy_labs/theme/_org_themes.py +129 -0
- sempy_labs/tom/__init__.py +3 -0
- sempy_labs/tom/_model.py +5977 -0
- sempy_labs/variable_library/__init__.py +19 -0
- sempy_labs/variable_library/_functions.py +403 -0
- sempy_labs/warehouse/__init__.py +28 -0
- sempy_labs/warehouse/_items.py +234 -0
- sempy_labs/warehouse/_restore_points.py +309 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from sempy_labs._helper_functions import (
|
|
4
|
+
_base_api,
|
|
5
|
+
_create_dataframe,
|
|
6
|
+
_update_dataframe_datatypes,
|
|
7
|
+
_is_valid_uuid,
|
|
8
|
+
)
|
|
9
|
+
from uuid import UUID
|
|
10
|
+
import sempy_labs._icons as icons
|
|
11
|
+
from sempy._utils._log import log
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@log
|
|
15
|
+
def list_reports(
|
|
16
|
+
top: Optional[int] = None,
|
|
17
|
+
skip: Optional[int] = None,
|
|
18
|
+
filter: Optional[str] = None,
|
|
19
|
+
) -> pd.DataFrame:
|
|
20
|
+
"""
|
|
21
|
+
Shows a list of reports for the organization.
|
|
22
|
+
|
|
23
|
+
This is a wrapper function for the following API: `Admin - Reports GetReportsAsAdmin <https://learn.microsoft.com/rest/api/power-bi/admin/reports-get-reports-as-admin>`_.
|
|
24
|
+
|
|
25
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
top : int, default=None
|
|
30
|
+
Returns only the first n results.
|
|
31
|
+
skip : int, default=None
|
|
32
|
+
Skips the first n results.
|
|
33
|
+
filter : str, default=None
|
|
34
|
+
Returns a subset of a results based on Odata filter query parameter condition.
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
pandas.DataFrame
|
|
39
|
+
A pandas dataframe showing a list of reports for the organization.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
columns = {
|
|
43
|
+
"Report Id": "string",
|
|
44
|
+
"Report Name": "string",
|
|
45
|
+
"Type": "string",
|
|
46
|
+
"Web URL": "string",
|
|
47
|
+
"Embed URL": "string",
|
|
48
|
+
"Dataset Id": "string",
|
|
49
|
+
"Created Date": "datetime_coerce",
|
|
50
|
+
"Modified Date": "datetime_coerce",
|
|
51
|
+
"Created By": "string",
|
|
52
|
+
"Modified By": "string",
|
|
53
|
+
"Sensitivity Label Id": "string",
|
|
54
|
+
"Users": "string",
|
|
55
|
+
"Subscriptions": "string",
|
|
56
|
+
"Workspace Id": "string",
|
|
57
|
+
"Report Flags": "int_fillna",
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
df = _create_dataframe(columns=columns)
|
|
61
|
+
|
|
62
|
+
url = "/v1.0/myorg/admin/reports?"
|
|
63
|
+
if top is not None:
|
|
64
|
+
url += f"$top={top}&"
|
|
65
|
+
if skip is not None:
|
|
66
|
+
url += f"$skip={skip}&"
|
|
67
|
+
if filter is not None:
|
|
68
|
+
url += f"$filter={filter}&"
|
|
69
|
+
|
|
70
|
+
url.rstrip("$").rstrip("?")
|
|
71
|
+
response = _base_api(request=url, client="fabric_sp")
|
|
72
|
+
|
|
73
|
+
rows = []
|
|
74
|
+
for v in response.json().get("value", []):
|
|
75
|
+
rows.append(
|
|
76
|
+
{
|
|
77
|
+
"Report Id": v.get("id"),
|
|
78
|
+
"Report Name": v.get("name"),
|
|
79
|
+
"Type": v.get("reportType"),
|
|
80
|
+
"Web URL": v.get("webUrl"),
|
|
81
|
+
"Embed URL": v.get("embedUrl"),
|
|
82
|
+
"Dataset Id": v.get("datasetId"),
|
|
83
|
+
"Created Date": v.get("createdDateTime"),
|
|
84
|
+
"Modified Date": v.get("modifiedDateTime"),
|
|
85
|
+
"Created By": v.get("createdBy"),
|
|
86
|
+
"Modified By": v.get("modifiedBy"),
|
|
87
|
+
"Sensitivity Label Id": v.get("sensitivityLabel", {}).get("labelId"),
|
|
88
|
+
"Users": v.get("users"),
|
|
89
|
+
"Subscriptions": v.get("subscriptions"),
|
|
90
|
+
"Workspace Id": v.get("workspaceId"),
|
|
91
|
+
"Report Flags": v.get("reportFlags"),
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
if rows:
|
|
96
|
+
df = pd.DataFrame(rows, columns=list(columns.keys()))
|
|
97
|
+
_update_dataframe_datatypes(dataframe=df, column_map=columns)
|
|
98
|
+
|
|
99
|
+
return df
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@log
|
|
103
|
+
def _resolve_report_id(report: str | UUID) -> str:
|
|
104
|
+
if _is_valid_uuid(report):
|
|
105
|
+
return report
|
|
106
|
+
else:
|
|
107
|
+
df = list_reports()
|
|
108
|
+
df_filt = df[df["Report Name"] == report]
|
|
109
|
+
if df_filt.empty:
|
|
110
|
+
raise ValueError(f"{icons.red_dot} The '{report}' report does not exist.")
|
|
111
|
+
return df_filt["Report Id"].iloc[0]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@log
|
|
115
|
+
def list_report_users(report: str | UUID) -> pd.DataFrame:
|
|
116
|
+
"""
|
|
117
|
+
Shows a list of users that have access to the specified report.
|
|
118
|
+
|
|
119
|
+
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>`_.
|
|
120
|
+
|
|
121
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
122
|
+
|
|
123
|
+
Parameters
|
|
124
|
+
----------
|
|
125
|
+
report : str | uuid.UUID
|
|
126
|
+
The name or ID of the report.
|
|
127
|
+
|
|
128
|
+
Returns
|
|
129
|
+
-------
|
|
130
|
+
pandas.DataFrame
|
|
131
|
+
A pandas dataframe showing a list of users that have access to the specified report.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
report_id = _resolve_report_id(report)
|
|
135
|
+
|
|
136
|
+
columns = {
|
|
137
|
+
"User Name": "string",
|
|
138
|
+
"Email Address": "string",
|
|
139
|
+
"Report User Access Right": "string",
|
|
140
|
+
"Identifier": "string",
|
|
141
|
+
"Graph Id": "string",
|
|
142
|
+
"Principal Type": "string",
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
df = _create_dataframe(columns=columns)
|
|
146
|
+
|
|
147
|
+
url = f"/v1.0/myorg/admin/reports/{report_id}/users"
|
|
148
|
+
response = _base_api(request=url, client="fabric_sp")
|
|
149
|
+
|
|
150
|
+
rows = []
|
|
151
|
+
for v in response.json().get("value", []):
|
|
152
|
+
rows.append(
|
|
153
|
+
{
|
|
154
|
+
"User Name": v.get("displayName"),
|
|
155
|
+
"Email Address": v.get("emailAddress"),
|
|
156
|
+
"Report User Access Right": v.get("reportUserAccessRight"),
|
|
157
|
+
"Identifier": v.get("identifier"),
|
|
158
|
+
"Graph Id": v.get("graphId"),
|
|
159
|
+
"Principal Type": v.get("principalType"),
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
if rows:
|
|
164
|
+
df = pd.DataFrame(rows, columns=list(columns.keys()))
|
|
165
|
+
_update_dataframe_datatypes(dataframe=df, column_map=columns)
|
|
166
|
+
|
|
167
|
+
return df
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@log
|
|
171
|
+
def list_report_subscriptions(report: str | UUID) -> pd.DataFrame:
|
|
172
|
+
"""
|
|
173
|
+
Shows a list of report subscriptions along with subscriber details. This is a preview API call.
|
|
174
|
+
|
|
175
|
+
This is a wrapper function for the following API: `Admin - Reports GetReportSubscriptionsAsAdmin <https://learn.microsoft.com/rest/api/power-bi/admin/reports-get-report-subscriptions-as-admin>`_.
|
|
176
|
+
|
|
177
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
178
|
+
|
|
179
|
+
Parameters
|
|
180
|
+
----------
|
|
181
|
+
report : str | uuid.UUID
|
|
182
|
+
The name or ID of the report.
|
|
183
|
+
|
|
184
|
+
Returns
|
|
185
|
+
-------
|
|
186
|
+
pandas.DataFrame
|
|
187
|
+
A pandas dataframe showing a list of report subscriptions along with subscriber details. This is a preview API call.
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
report_id = _resolve_report_id(report)
|
|
191
|
+
|
|
192
|
+
columns = {
|
|
193
|
+
"Subscription Id": "string",
|
|
194
|
+
"Title": "string",
|
|
195
|
+
"Artifact Id": "string",
|
|
196
|
+
"Artifact Name": "string",
|
|
197
|
+
"Sub Artifact Name": "string",
|
|
198
|
+
"Artifact Type": "string",
|
|
199
|
+
"Is Enabled": "bool",
|
|
200
|
+
"Frequency": "string",
|
|
201
|
+
"Start Date": "datetime",
|
|
202
|
+
"End Date": "string",
|
|
203
|
+
"Link To Content": "bool",
|
|
204
|
+
"Preview Image": "bool",
|
|
205
|
+
"Attachment Format": "string",
|
|
206
|
+
"Users": "list",
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
df = _create_dataframe(columns=columns)
|
|
210
|
+
|
|
211
|
+
response = _base_api(
|
|
212
|
+
request=f"/v1.0/myorg/admin/reports/{report_id}/subscriptions",
|
|
213
|
+
client="fabric_sp",
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
rows = []
|
|
217
|
+
for v in response.json().get("value", []):
|
|
218
|
+
rows.append(
|
|
219
|
+
{
|
|
220
|
+
"Subscription Id": v.get("id"),
|
|
221
|
+
"Title": v.get("title"),
|
|
222
|
+
"Artifact Id": v.get("artifactId"),
|
|
223
|
+
"Artifact Name": v.get("artifactDisplayName"),
|
|
224
|
+
"Sub Artifact Name": v.get("subArtifactDisplayName"),
|
|
225
|
+
"Artifact Type": v.get("artifactType"),
|
|
226
|
+
"Is Enabled": v.get("isEnabled"),
|
|
227
|
+
"Frequency": v.get("frequency"),
|
|
228
|
+
"Start Date": v.get("startDate"),
|
|
229
|
+
"End Date": v.get("endDate"),
|
|
230
|
+
"Link To Content": v.get("linkToContent"),
|
|
231
|
+
"Preview Image": v.get("previewImage"),
|
|
232
|
+
"Attachment Format": v.get("attachmentFormat"),
|
|
233
|
+
"Users": v.get("users", []),
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
if rows:
|
|
238
|
+
df = pd.DataFrame(rows, columns=list(columns.keys()))
|
|
239
|
+
_update_dataframe_datatypes(dataframe=df, column_map=columns)
|
|
240
|
+
|
|
241
|
+
return df
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from typing import Optional, List
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
from sempy.fabric.exceptions import FabricHTTPException
|
|
4
|
+
import time
|
|
5
|
+
import sempy_labs._icons as icons
|
|
6
|
+
from sempy_labs.admin._basic_functions import list_workspaces
|
|
7
|
+
from sempy._utils._log import log
|
|
8
|
+
from sempy_labs._helper_functions import (
|
|
9
|
+
_base_api,
|
|
10
|
+
_is_valid_uuid,
|
|
11
|
+
_build_url,
|
|
12
|
+
resolve_workspace_name,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@log
|
|
17
|
+
def scan_workspaces(
|
|
18
|
+
data_source_details: bool = False,
|
|
19
|
+
dataset_schema: bool = False,
|
|
20
|
+
dataset_expressions: bool = False,
|
|
21
|
+
lineage: bool = False,
|
|
22
|
+
artifact_users: bool = False,
|
|
23
|
+
workspace: Optional[str | List[str] | UUID | List[UUID]] = None,
|
|
24
|
+
) -> dict:
|
|
25
|
+
"""
|
|
26
|
+
Gets the scan result for the specified scan.
|
|
27
|
+
|
|
28
|
+
This is a wrapper function for the following APIs:
|
|
29
|
+
`Admin - WorkspaceInfo PostWorkspaceInfo <https://learn.microsoft.com/rest/api/power-bi/admin/workspace-info-post-workspace-info>`_.
|
|
30
|
+
`Admin - WorkspaceInfo GetScanStatus <https://learn.microsoft.com/rest/api/power-bi/admin/workspace-info-get-scan-status>`_.
|
|
31
|
+
`Admin - WorkspaceInfo GetScanResult <https://learn.microsoft.com/rest/api/power-bi/admin/workspace-info-get-scan-result>`_.
|
|
32
|
+
|
|
33
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
data_source_details : bool, default=False
|
|
38
|
+
Whether to return dataset expressions (DAX and Mashup queries). If you set this parameter to true, you must fully enable metadata scanning in order for data to be returned. For more information, see Enable tenant settings for metadata scanning.
|
|
39
|
+
dataset_schema: bool = False
|
|
40
|
+
Whether to return dataset schema (tables, columns and measures). If you set this parameter to true, you must fully enable metadata scanning in order for data to be returned. For more information, see Enable tenant settings for metadata scanning.
|
|
41
|
+
dataset_expressions : bool, default=False
|
|
42
|
+
Whether to return data source details.
|
|
43
|
+
lineage : bool, default=False
|
|
44
|
+
Whether to return lineage info (upstream dataflows, tiles, data source IDs)
|
|
45
|
+
artifact_users : bool, default=False
|
|
46
|
+
Whether to return user details for a Power BI item (such as a report or a dashboard).
|
|
47
|
+
workspace : str | List[str] | UUID | List[UUID], default=None
|
|
48
|
+
The required workspace name(s) or id(s) to be scanned. It supports a limit of 100 workspaces and only IDs in GUID format.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
dict
|
|
53
|
+
A json object with the scan result.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
if workspace is None:
|
|
57
|
+
workspace = resolve_workspace_name()
|
|
58
|
+
|
|
59
|
+
if isinstance(workspace, str):
|
|
60
|
+
workspace = [workspace]
|
|
61
|
+
|
|
62
|
+
if len(workspace) > 100:
|
|
63
|
+
print(
|
|
64
|
+
f"{icons.yellow_dot} More than 100 workspaces where provided. Truncating to the fist 100."
|
|
65
|
+
)
|
|
66
|
+
workspace = workspace[:100]
|
|
67
|
+
|
|
68
|
+
workspace_list = []
|
|
69
|
+
|
|
70
|
+
for w in workspace:
|
|
71
|
+
if _is_valid_uuid(w):
|
|
72
|
+
workspace_list.append(w)
|
|
73
|
+
else:
|
|
74
|
+
dfW = list_workspaces(workspace=w)
|
|
75
|
+
workspace_list = (
|
|
76
|
+
workspace_list + dfW[dfW["Name"].isin(workspace)]["Id"].tolist()
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
url = "/v1.0/myorg/admin/workspaces/getInfo"
|
|
80
|
+
params = {}
|
|
81
|
+
params["lineage"] = lineage
|
|
82
|
+
params["datasourceDetails"] = data_source_details
|
|
83
|
+
params["datasetSchema"] = dataset_schema
|
|
84
|
+
params["datasetExpressions"] = dataset_expressions
|
|
85
|
+
params["getArtifactUsers"] = artifact_users
|
|
86
|
+
|
|
87
|
+
url = _build_url(url, params)
|
|
88
|
+
|
|
89
|
+
payload = {"workspaces": workspace_list}
|
|
90
|
+
|
|
91
|
+
response = _base_api(
|
|
92
|
+
request=url,
|
|
93
|
+
method="post",
|
|
94
|
+
payload=payload,
|
|
95
|
+
status_codes=202,
|
|
96
|
+
client="fabric_sp",
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
scan_id = response.json()["id"]
|
|
100
|
+
scan_status = response.json().get("status")
|
|
101
|
+
|
|
102
|
+
while scan_status not in ["Succeeded", "Failed"]:
|
|
103
|
+
time.sleep(1)
|
|
104
|
+
response = _base_api(
|
|
105
|
+
request=f"/v1.0/myorg/admin/workspaces/scanStatus/{scan_id}",
|
|
106
|
+
client="fabric_sp",
|
|
107
|
+
)
|
|
108
|
+
scan_status = response.json().get("status")
|
|
109
|
+
|
|
110
|
+
if scan_status == "Failed":
|
|
111
|
+
raise FabricHTTPException(response)
|
|
112
|
+
|
|
113
|
+
response = _base_api(
|
|
114
|
+
request=f"/v1.0/myorg/admin/workspaces/scanResult/{scan_id}",
|
|
115
|
+
client="fabric_sp",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return response.json()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from sempy_labs._helper_functions import (
|
|
3
|
+
_base_api,
|
|
4
|
+
_create_dataframe,
|
|
5
|
+
)
|
|
6
|
+
from sempy._utils._log import log
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@log
|
|
10
|
+
def list_widely_shared_artifacts(
|
|
11
|
+
api_name: str = "LinksSharedToWholeOrganization",
|
|
12
|
+
) -> pd.DataFrame:
|
|
13
|
+
"""
|
|
14
|
+
Returns a list of Power BI reports that are shared with the whole organization through links or a list of Power BI items (such as reports or dashboards) that are published to the web.
|
|
15
|
+
|
|
16
|
+
This is a wrapper function for the following APIs:
|
|
17
|
+
`Admin - WidelySharedArtifacts LinksSharedToWholeOrganization <https://learn.microsoft.com/rest/api/power-bi/admin/widely-shared-artifacts-links-shared-to-whole-organization>`_.
|
|
18
|
+
`Admin - WidelySharedArtifacts PublishedToWeb <https://learn.microsoft.com/rest/api/power-bi/admin/widely-shared-artifacts-published-to-web>`_.
|
|
19
|
+
|
|
20
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
api_name : str, default = "LinksSharedToWholeOrganization"
|
|
25
|
+
The name of the API to call. Either "LinksSharedToWholeOrganization" or "PublishedToWeb".
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
pandas.DataFrame
|
|
30
|
+
A pandas dataframe showing a list of Power BI reports that are shared with the whole organization through links or a list of Power BI items (such as reports or dashboards) that are published to the web.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
columns = {
|
|
34
|
+
"Artifact Id": "string",
|
|
35
|
+
"Artifact Name": "string",
|
|
36
|
+
"Artifact Type": "string",
|
|
37
|
+
"Access Right": "string",
|
|
38
|
+
"Share Type": "string",
|
|
39
|
+
"Sharer Name": "string",
|
|
40
|
+
"Sharer Email Address": "string",
|
|
41
|
+
"Sharer Identifier": "string",
|
|
42
|
+
"Sharer Graph Id": "string",
|
|
43
|
+
"Sharer Principal Type": "string",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
df = _create_dataframe(columns=columns)
|
|
47
|
+
|
|
48
|
+
api = (
|
|
49
|
+
"linksSharedToWholeOrganization"
|
|
50
|
+
if api_name == "LinksSharedToWholeOrganization"
|
|
51
|
+
else "publishedToWeb"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
responses = _base_api(
|
|
55
|
+
request=f"/v1.0/myorg/admin/widelySharedArtifacts/{api}",
|
|
56
|
+
client="fabric_sp",
|
|
57
|
+
uses_pagination=True,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
rows = []
|
|
61
|
+
for r in responses:
|
|
62
|
+
for v in r.get("ArtifactAccessEntities", []):
|
|
63
|
+
sharer = v.get("sharer", {})
|
|
64
|
+
rows.append(
|
|
65
|
+
{
|
|
66
|
+
"Artifact Id": v.get("artifactId"),
|
|
67
|
+
"Artifact Name": v.get("displayName"),
|
|
68
|
+
"Artifact Type": v.get("artifactType"),
|
|
69
|
+
"Access Right": v.get("accessRight"),
|
|
70
|
+
"Share Type": v.get("shareType"),
|
|
71
|
+
"Sharer Name": sharer.get("displayName"),
|
|
72
|
+
"Sharer Email Address": sharer.get("emailAddress"),
|
|
73
|
+
"Sharer Identifier": sharer.get("identifier"),
|
|
74
|
+
"Sharer Graph Id": sharer.get("graphId"),
|
|
75
|
+
"Sharer Principal Type": sharer.get("principalType"),
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
if rows:
|
|
80
|
+
df = pd.DataFrame(rows, columns=list(columns.keys()))
|
|
81
|
+
|
|
82
|
+
return df
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from sempy._utils._log import log
|
|
2
|
+
from sempy_labs._helper_functions import (
|
|
3
|
+
_base_api,
|
|
4
|
+
_is_valid_uuid,
|
|
5
|
+
)
|
|
6
|
+
import sempy_labs._icons as icons
|
|
7
|
+
from typing import List
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@log
|
|
11
|
+
def remove_all_sharing_links(sharing_link_type: str = "OrgLink"):
|
|
12
|
+
"""
|
|
13
|
+
Deletes all organization sharing links for all Fabric items in the tenant. This action cannot be undone.
|
|
14
|
+
|
|
15
|
+
This is a wrapper function for the following API: `Sharing Links - Remove All Sharing Links <https://learn.microsoft.com/rest/api/fabric/admin/sharing-links/remove-all-sharing-links>`_.
|
|
16
|
+
|
|
17
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
sharing_link_type : str, default='OrgLink'
|
|
22
|
+
Specifies the type of sharing link that is required to be deleted. Additional sharing link types may be added over time.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
payload = {"sharingLinkType": sharing_link_type}
|
|
26
|
+
|
|
27
|
+
_base_api(
|
|
28
|
+
request="/v1/admin/items/removeAllSharingLinks",
|
|
29
|
+
client="fabric_sp",
|
|
30
|
+
lro_return_status_code=True,
|
|
31
|
+
status_codes=[200, 202],
|
|
32
|
+
method="post",
|
|
33
|
+
payload=payload,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
print(
|
|
37
|
+
f"{icons.green_dot} All organization sharing links for all Fbric items in the tenant have been deleted."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@log
|
|
42
|
+
def remove_sharing_links(items: List[dict], sharing_link_type: str = "OrgLink"):
|
|
43
|
+
"""
|
|
44
|
+
Deletes all organization sharing links for the specified Fabric items. This action cannot be undone.
|
|
45
|
+
|
|
46
|
+
This is a wrapper function for the following API: `Sharing Links - Bulk Remove Sharing Links <https://learn.microsoft.com/rest/api/fabric/admin/sharing-links/bulk-remove-sharing-links>`_.
|
|
47
|
+
|
|
48
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
items : List[dict]
|
|
53
|
+
A list of dictionaries, each representing an item. The 'item' and 'workspace' accepts either name or ID. Examples:
|
|
54
|
+
|
|
55
|
+
[
|
|
56
|
+
{
|
|
57
|
+
"item": "MyReport",
|
|
58
|
+
"type": "Report",
|
|
59
|
+
"workspace": "Workpsace 1",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"item": "MyReport2",
|
|
63
|
+
"type": "Report",
|
|
64
|
+
"workspace": "Workspace 2",
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[
|
|
69
|
+
{
|
|
70
|
+
"item": "fe472f5e-636e-4c10-a1c6-7e9edc0b542a",
|
|
71
|
+
"type": "Report",
|
|
72
|
+
"workspace": "Workspace 1",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"item": "fe472f5e-636e-4c10-a1c6-7e9edc0b542c",
|
|
76
|
+
"type": "Notebook",
|
|
77
|
+
"workspace": "476fcafe-b514-495d-b13f-ca9a4f0b1d8f",
|
|
78
|
+
},
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
sharing_link_type : str, default='OrgLink'
|
|
82
|
+
Specifies the type of sharing link that is required to be deleted. Additional sharing link types may be added over time.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
from sempy_labs.admin._items import _resolve_item_id
|
|
86
|
+
|
|
87
|
+
payload = {"items": [], "sharingLinkType": sharing_link_type}
|
|
88
|
+
|
|
89
|
+
for i in items:
|
|
90
|
+
item = i.get("item")
|
|
91
|
+
type = i.get("type")
|
|
92
|
+
workspace = i.get("workspace")
|
|
93
|
+
if _is_valid_uuid(item):
|
|
94
|
+
payload["items"].append({"id": item, "type": type})
|
|
95
|
+
else:
|
|
96
|
+
item_id = _resolve_item_id(item=item, type=type, workspace=workspace)
|
|
97
|
+
payload["items"].append({"id": item_id, "type": type})
|
|
98
|
+
|
|
99
|
+
_base_api(
|
|
100
|
+
request="/v1/admin/items/bulkRemoveSharingLinks",
|
|
101
|
+
client="fabric_sp",
|
|
102
|
+
method="post",
|
|
103
|
+
payload=payload,
|
|
104
|
+
lro_return_status_code=True,
|
|
105
|
+
status_codes=[200, 202],
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
print(
|
|
109
|
+
f"{icons.green_dot} Organizational sharing links for all specified items have been deleted."
|
|
110
|
+
)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
from .._helper_functions import (
|
|
2
|
+
_base_api,
|
|
3
|
+
_is_valid_uuid,
|
|
4
|
+
)
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
from sempy_labs._tags import list_tags
|
|
7
|
+
import sempy_labs._icons as icons
|
|
8
|
+
from typing import List
|
|
9
|
+
from sempy._utils._log import log
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@log
|
|
13
|
+
def resolve_tag_id(tag: str | UUID):
|
|
14
|
+
|
|
15
|
+
if _is_valid_uuid(tag):
|
|
16
|
+
tag_id = tag
|
|
17
|
+
else:
|
|
18
|
+
df = list_tags()
|
|
19
|
+
df[df["Tag Name"] == tag]
|
|
20
|
+
if df.empty:
|
|
21
|
+
raise ValueError(f"{icons.red_dot} The '{tag}' tag does not exist.")
|
|
22
|
+
tag_id = df.iloc[0]["Tag Id"]
|
|
23
|
+
|
|
24
|
+
return tag_id
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@log
|
|
28
|
+
def create_tags(tags: str | List[str]):
|
|
29
|
+
"""
|
|
30
|
+
Creates a new tag or tags.
|
|
31
|
+
|
|
32
|
+
This is a wrapper function for the following API: `Tags - Bulk Create Tags <https://learn.microsoft.com/rest/api/fabric/admin/tags/bulk-create-tags>`_.
|
|
33
|
+
|
|
34
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
tags : str | List[str]
|
|
39
|
+
The name of the tag or tags to create.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
if isinstance(tags, str):
|
|
43
|
+
tags = [tags]
|
|
44
|
+
|
|
45
|
+
# Check the length of the tags
|
|
46
|
+
for tag in tags:
|
|
47
|
+
if len(tag) > 40:
|
|
48
|
+
raise ValueError(
|
|
49
|
+
f"{icons.red_dot} The '{tag}' tag name is too long. It must be 40 characters or less."
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Check if the tags already exist
|
|
53
|
+
df = list_tags()
|
|
54
|
+
existing_names = df["Tag Name"].tolist()
|
|
55
|
+
existing_ids = df["Tag Id"].tolist()
|
|
56
|
+
|
|
57
|
+
available_tags = [
|
|
58
|
+
tag for tag in tags if tag not in existing_names and tag not in existing_ids
|
|
59
|
+
]
|
|
60
|
+
unavailable_tags = [
|
|
61
|
+
tag for tag in tags if tag in existing_names or tag in existing_ids
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
print(f"{icons.warning} The following tags already exist: {unavailable_tags}")
|
|
65
|
+
if not available_tags:
|
|
66
|
+
print(f"{icons.info} No new tags to create.")
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
payload = [{"displayName": name} for name in available_tags]
|
|
70
|
+
|
|
71
|
+
for tag in tags:
|
|
72
|
+
_base_api(
|
|
73
|
+
request="/v1/admin/bulkCreateTags",
|
|
74
|
+
client="fabric_sp",
|
|
75
|
+
method="post",
|
|
76
|
+
payload=payload,
|
|
77
|
+
status_codes=201,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
print(f"{icons.green_dot} The '{available_tags}' tag(s) have been created.")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@log
|
|
84
|
+
def delete_tag(tag: str | UUID):
|
|
85
|
+
"""
|
|
86
|
+
Deletes a tag.
|
|
87
|
+
|
|
88
|
+
This is a wrapper function for the following API: `Tags - Delete Tag <https://learn.microsoft.com/rest/api/fabric/admin/tags/delete-tag>`_.
|
|
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
|
+
tag : str | uuid.UUID
|
|
95
|
+
The name or ID of the tag to delete.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
tag_id = resolve_tag_id(tag)
|
|
99
|
+
|
|
100
|
+
_base_api(request=f"/v1/admin/tags/{tag_id}", client="fabric_sp", method="delete")
|
|
101
|
+
|
|
102
|
+
print(f"{icons.green_dot} The '{tag}' tag has been deleted.")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@log
|
|
106
|
+
def update_tag(name: str, tag: str | UUID):
|
|
107
|
+
"""
|
|
108
|
+
Updates the name of a tag.
|
|
109
|
+
|
|
110
|
+
This is a wrapper function for the following API: `Tags - Update Tag <https://learn.microsoft.com/rest/api/fabric/admin/tags/update-tag>`_.
|
|
111
|
+
|
|
112
|
+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
|
|
113
|
+
|
|
114
|
+
Parameters
|
|
115
|
+
----------
|
|
116
|
+
name : str
|
|
117
|
+
The new name of the tag.
|
|
118
|
+
tag : str | uuid.UUID
|
|
119
|
+
The name or ID of the tag to update.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
tag_id = resolve_tag_id(tag)
|
|
123
|
+
|
|
124
|
+
_base_api(
|
|
125
|
+
request=f"/v1/admin/tags/{tag_id}",
|
|
126
|
+
client="fabric_sp",
|
|
127
|
+
method="patch",
|
|
128
|
+
payload={"displayName": name},
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
print(f"{icons.green_dot} The '{tag}' tag has been renamed to '{name}'.")
|