Skip to content

Commit 1ccb858

Browse files
committed
Merge branch 'm-kovalsky/list_domains-(nonadmin)'
2 parents 7d1f6de + 527fcd2 commit 1ccb858

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/sempy_labs/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@
344344
get_onelake_settings,
345345
modify_onelake_diagnostics,
346346
)
347+
from ._domains import (
348+
list_domains,
349+
)
347350

348351
__all__ = [
349352
"resolve_warehouse_id",
@@ -593,4 +596,5 @@
593596
"discover_dataflow_parameters",
594597
"get_onelake_settings",
595598
"modify_onelake_diagnostics",
599+
"list_domains",
596600
]

src/sempy_labs/_domains.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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_domains() -> pd.DataFrame:
11+
"""
12+
Returns a list of all the tenant's domains.
13+
14+
This is a wrapper function for the following API: `Domains - List Domains <https://learn.microsoft.com/rest/api/fabric/core/domains/list-domains>`_.
15+
16+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
17+
18+
Returns
19+
-------
20+
pandas.DataFrame
21+
A pandas dataframe showing a list of the domains.
22+
"""
23+
24+
columns = {
25+
"Domain Id": "string",
26+
"Domain Name": "string",
27+
"Description": "string",
28+
"Parent Domain Id": "string",
29+
}
30+
df = _create_dataframe(columns=columns)
31+
32+
responses = _base_api(
33+
request="/v1/domains", client="fabric_sp", uses_pagination=True
34+
)
35+
36+
rows = []
37+
for r in responses:
38+
for v in r.get("value", []):
39+
rows.append(
40+
{
41+
"Domain Id": v.get("id"),
42+
"Domain Name": v.get("displayName"),
43+
"Description": v.get("description"),
44+
"Parent Domain Id": v.get("parentDomainId"),
45+
}
46+
)
47+
48+
if rows:
49+
df = pd.DataFrame(rows, columns=list(columns.keys()))
50+
51+
return df

0 commit comments

Comments
 (0)