Python Microsoft Fabric tutorial
Entra app registration, the first Fabric connection, and loading and querying the first table.
This tutorial walks you through your first Microsoft Fabric integration with Zato - from creating the Entra app registration to loading and querying your first lakehouse table from a Python service.
Step 1 - Register the Entra application
Fabric authenticates through Entra ID, so the connection needs an app registration:
- In the Azure portal, go to
Microsoft Entra ID → App registrationsand click "New registration" - Give it a name, e.g.
Zato Fabric, and register it - Note down the "Application (client) ID" and the "Directory (tenant) ID" from the overview page
- Under
Certificates and secrets, create a new client secret and note down its value - In the Fabric admin portal, under
Tenant settings → Developer settings, enable "Service principals can use Fabric APIs" - Add the service principal to the workspaces it should access - in each workspace, use
Manage accessand grant it the role your scenario requires, e.g. Contributor
Step 2 - Create the connection
Open the Dashboard and go to Cloud → Microsoft Fabric. Click "Create a new connection" and fill in the form:
| Field | Value |
|---|---|
| Name | My Fabric |
| Address | https://api.fabric.microsoft.com/v1 |
| Tenant ID | The directory (tenant) ID from step 1 |
| Client ID | The application (client) ID from step 1 |
| Client secret | The client secret from step 1 |
You can now click "Ping" to confirm that everything works - it obtains a token and lists the workspaces the principal has access to.
Step 3 - Load and query a table
Create a service that writes rows to a lakehouse table and reads them back with SQL:
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class LoadAndQuery(Service):
input = 'workspace_id', 'lakehouse_id'
def handle(self):
conn = self.microsoft.fabric['My Fabric']
# Write rows to a table ..
rows = [
{'region': 'EMEA', 'total': 1250.50},
{'region': 'APAC', 'total': 875.25},
]
conn.write_table(self.request.input.workspace_id, self.request.input.lakehouse_id, 'daily_totals', rows)
# .. and query them back.
result = conn.query(
self.request.input.workspace_id,
self.request.input.lakehouse_id,
'select region, total from daily_totals',
)
self.response.payload = {'rows': result}
Under the hood, write_table uploads the rows as a CSV file to the lakehouse's Files section through OneLake, then tells the lakehouse to load that file into the table and waits until the load completes - the same upload-then-load steps you can run yourself with onelake_write and load_table.
Hot-deploy the service and invoke it - the response contains the rows the table now holds. The Tables page covers loading files, bulk loads and everything else around tables and queries.
Step 4 - Understand the API
There are three levels to the connection's API, and all of them share the same automatically managed Entra ID token:
Convenience methods - the operations most integrations need, one call each:
conn = self.microsoft.fabric['My Fabric']
workspaces = conn.list_workspaces()
items = conn.list_items('12345678-1234-1234-1234-123456789abc')
job_id = conn.run_job('12345678-1234-1234-1234-123456789abc', 'item-id', 'RunNotebook')
Generic HTTP methods - conn.get, conn.post, conn.patch and conn.delete reach any Fabric endpoint by its path:
conn = self.microsoft.fabric['My Fabric']
items = conn.get('/workspaces/12345678-1234-1234-1234-123456789abc/items')
The invoke method - conn.invoke(method, path, params, data) is what everything else builds on, for full control:
conn = self.microsoft.fabric['My Fabric']
result = conn.invoke('GET', '/workspaces', params={'roles': 'Admin'})
Tokens are acquired on first use, cached, refreshed before they expire, and re-acquired transparently if the API ever rejects one - your code never handles them. The OneLake data plane uses a second, storage-scoped token which is managed the same way.
See also
| Page | What it covers |
|---|---|
| Tables | Loading rows and files into lakehouse tables and querying them with SQL |
| Lakehouses | Lakehouse items, loading data, tables and files |
| OneLake | Shortcuts plus reading and writing files through the data plane |
| Workspaces | Listing, creating and managing workspaces |
| Notebooks | Running Spark notebooks on demand |
| Pipelines | Data Factory pipeline runs, monitoring and cancellation |
| Data science | ML models and experiments |
| Reports | Power BI reports and semantic models |