Python Microsoft Fabric - Reports
Power BI reports and semantic models, refreshed after data loads from Python services.
Power BI lives inside Fabric - reports and the semantic models behind them are workspace items like everything else. The integration that matters most is the refresh - once your services load new data into a lakehouse, refreshing the semantic model is what makes the reports show it. You create a Fabric connection in the Dashboard and all of it is available to your services.
Listing reports
Reports are workspace items of the Report type.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ListReports(Service):
input = 'workspace_id'
def handle(self):
# Get the connection by its Dashboard name
conn = self.microsoft.fabric['My Fabric']
# List only the report items
response = conn.list_items(self.request.input.workspace_id, 'Report')
reports = []
for item in response['value']:
reports.append({
'id': item['id'],
'name': item['displayName'],
})
self.response.payload = {'reports': reports}
Listing semantic models
Semantic models - the datasets reports read from - are items of the SemanticModel type.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ListSemanticModels(Service):
input = 'workspace_id'
def handle(self):
conn = self.microsoft.fabric['My Fabric']
response = conn.list_items(self.request.input.workspace_id, 'SemanticModel')
models = []
for item in response['value']:
models.append({
'id': item['id'],
'name': item['displayName'],
})
self.response.payload = {'models': models}
Refreshing a semantic model after a data load
Refreshing a semantic model is a job of the DefaultSemanticModelRefresh type - the natural last step of a data load, so the dashboards built on the model show the new data.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class RefreshSalesModel(Service):
input = 'workspace_id', 'semantic_model_id'
def handle(self):
conn = self.microsoft.fabric['My Fabric']
# Start the refresh
conn.run_job(
self.request.input.workspace_id,
self.request.input.semantic_model_id,
'DefaultSemanticModelRefresh',
)
self.response.payload = {'status': 'refresh started'}
A typical end-to-end flow chains the pieces together - a pipeline loads the data, a notebook transforms it, and this refresh makes it visible in the reports.
Monitoring a refresh
Like every job, a refresh is monitored with conn.get_job - complete when its status says so.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class CheckModelRefresh(Service):
input = 'workspace_id', 'semantic_model_id', 'job_id'
def handle(self):
conn = self.microsoft.fabric['My Fabric']
job = conn.get_job(
self.request.input.workspace_id,
self.request.input.semantic_model_id,
self.request.input.job_id,
)
self.response.payload = {'status': job['status']}
Renaming a report
Reports are updated like any other item - conn.update_item changes the display name or description.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class RenameReport(Service):
input = 'workspace_id', 'report_id', 'new_name'
def handle(self):
conn = self.microsoft.fabric['My Fabric']
conn.update_item(
self.request.input.workspace_id,
self.request.input.report_id,
{'displayName': self.request.input.new_name},
)
self.response.payload = {'status': 'renamed'}