Skip to content

Updated the list_dataflows function to accept a list of workspaces #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 46 additions & 23 deletions src/sempy_labs/_dataflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,49 @@
_create_dataframe,
resolve_workspace_name,
)
from typing import Optional, Tuple
from typing import Optional, Tuple, List
import sempy_labs._icons as icons
from uuid import UUID
import sempy.fabric as fabric


def list_dataflows(workspace: Optional[str | UUID] = None):
def list_dataflows(workspace: Optional[str | UUID | List[str | UUID]] = None):
"""
Shows a list of all dataflows which exist within a workspace.
Shows a list of all dataflows which exist within specified or all workspaces .

Parameters
----------
workspace : str | uuid.UUID, default=None
The Fabric workspace name or ID.
Defaults to None which resolves to the workspace of the attached lakehouse
or if no lakehouse attached, resolves to the workspace of the notebook.
workspace : str | uuid.UUID | List[str | uuid.UUID], default=None
The workspace or list of workspaces to scan. Supports both the workspace name and the workspace id.
Defaults to None which scans all accessible workspaces.

Returns
-------
pandas.DataFrame
A pandas dataframe showing the dataflows which exist within a workspace.
"""

(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
#Pulling all the workspaces details
dfW = fabric.list_workspaces("type ne 'AdminInsights'")
if workspace is None:
dfW_filt = dfW.copy()
else:
if isinstance(workspace, str):
workspace = [workspace]
dfW_filt = dfW[(dfW["Name"].isin(workspace)) | (dfW["Id"].isin(workspace))]

if dfW_filt.empty:
raise ValueError(
f"{icons.red_dot} There are no valid workspaces to assess. This is likely due to not having proper permissions to the workspace(s) entered in the 'workspace' parameter."
)

# Convert 'Name' column to list
workspaces_list = dfW_filt['Id'].tolist()


columns = {
"Workspace Id": "string",
"Workspace Name": "string",
"Dataflow Id": "string",
"Dataflow Name": "string",
"Configured By": "string",
Expand All @@ -40,24 +58,29 @@ def list_dataflows(workspace: Optional[str | UUID] = None):
}
df = _create_dataframe(columns=columns)

response = _base_api(request=f"/v1.0/myorg/groups/{workspace_id}/dataflows")

for workspace_id in workspaces_list:
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace_id)
response = _base_api(request=f"/v1.0/myorg/groups/{workspace_id}/dataflows")

data = [] # Collect rows here

for v in response.json().get("value", []):
new_data = {
"Dataflow Id": v.get("objectId"),
"Dataflow Name": v.get("name"),
"Configured By": v.get("configuredBy"),
"Users": v.get("users", []),
"Generation": v.get("generation"),
}
data.append(new_data)
data = [] # Collect rows here

if data:
df = pd.DataFrame(data)
for v in response.json().get("value", []):
new_data = {
"Workspace Id": workspace_id,
"Workspace Name": workspace_name,
"Dataflow Id": v.get("objectId"),
"Dataflow Name": v.get("name"),
"Configured By": v.get("configuredBy"),
"Users": v.get("users", []),
"Generation": v.get("generation"),
}
data.append(new_data)

_update_dataframe_datatypes(dataframe=df, column_map=columns)
if data:
df_temp = pd.DataFrame(data)
_update_dataframe_datatypes(dataframe=df_temp, column_map=columns)
df = pd.concat([df, df_temp], ignore_index=True)

return df

Expand Down