Skip to content

Commit 72105e9

Browse files
Added get_dataflow_definition
This is a wrapper function for the following API: Dataflows - Get Dataflow <https://learn.microsoft.com/rest/api/power-bi/dataflows/get-dataflow>
1 parent 24f0e42 commit 72105e9

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/sempy_labs/_dataflows.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,51 @@ def _resolve_dataflow_name_and_id(
245245
dataflow_name = dfD_filt["Dataflow Name"].iloc[0]
246246

247247
return dataflow_name, dataflow_id
248+
249+
250+
def get_dataflow_definition(
251+
name: str, workspace: Optional[str] = None, decode: bool = True
252+
) -> dict | pd.DataFrame:
253+
"""
254+
Obtains the definition of a dataflow.
255+
256+
This is a wrapper function for the following API: `Dataflows - Get Dataflow <https://learn.microsoft.com/rest/api/power-bi/dataflows/get-dataflow>`_.
257+
258+
Parameters
259+
----------
260+
name : str
261+
The name of the dataflow.
262+
workspace : str, default=None
263+
The Fabric workspace name.
264+
Defaults to None which resolves to the workspace of the attached lakehouse
265+
or if no lakehouse attached, resolves to the workspace of the notebook.
266+
decode : bool, default=True
267+
decode : bool, default=True
268+
If True, decodes the dataflow definition file into .json format.
269+
If False, obtains the dataflow definition file a pandas DataFrame format.
270+
271+
Returns
272+
-------
273+
dict | pandas.DataFrame
274+
A pandas dataframe showing the data pipelines within a workspace.
275+
"""
276+
277+
workspace = fabric.resolve_workspace_name(workspace)
278+
workspace_id = fabric.resolve_workspace_id(workspace)
279+
dataflow_name, item_id = _resolve_dataflow_name_and_id(
280+
dataflow=name, workspace=workspace
281+
)
282+
283+
client = fabric.PowerBIRestClient()
284+
response = client.get(
285+
f"v1.0/myorg/groups/{workspace_id}/dataflows/{item_id}"
286+
)
287+
288+
result = lro(client, response).json()
289+
290+
df = pd.json_normalize(result)
291+
292+
if not decode:
293+
return df
294+
295+
return result

0 commit comments

Comments
 (0)