Semantic Link for Microsoft Fabric (SemPy)

0.14.0 · active · verified Sat Apr 11

Semantic link connects Microsoft Fabric's Power BI semantic models with data science tools. SemPy is the Python library that is part of semantic link, providing functionalities to analyze and manipulate data from Power BI models directly within notebooks. It integrates deeply with Fabric DataFrames and allows for tasks like listing Power BI items, reading tables, and calculating measures. The current version is 0.14.0, and it's actively developed by Microsoft.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a `FabricDataFrame` from a standard pandas DataFrame. It then attempts to use `sempy.fabric.list_workspaces()` to show interaction with Microsoft Fabric. Note that most `sempy.fabric` functions require execution within a Microsoft Fabric notebook environment with an authenticated session to function correctly.

import pandas as pd
from sempy.fabric import FabricDataFrame, list_workspaces

# Create a sample pandas DataFrame
df_pd = pd.DataFrame({
    'ID': [1, 2, 3],
    'Value': [100, 200, 150]
})

# Convert a pandas DataFrame to a FabricDataFrame
df_sempy = FabricDataFrame(df_pd)
print("--- FabricDataFrame created ---")
print(df_sempy.head())
print(f"Type: {type(df_sempy)}\n")

# Attempt to list Fabric workspaces
# This function (and most of sempy.fabric) requires an active Microsoft Fabric notebook environment
# and an authenticated session to execute successfully.
print("--- Attempting to list Fabric workspaces ---")
try:
    workspaces = list_workspaces()
    print(f"Successfully listed {len(workspaces)} workspaces.")
    if workspaces:
        print(f"First workspace: {workspaces[0]['display_name']}")
except Exception as e:
    print(f"Failed to list workspaces. This is expected if not running in a Fabric notebook or without proper authentication.\nError: {e}")

view raw JSON →