Python Microsoft Fabric API - Workspaces
list_workspaces, get_workspace, list_items and get_item, plus shortcuts and capacities.
A workspace is a folder that holds everything a team works on in Fabric, and everything in it - a lakehouse, a notebook, a pipeline, a report - is an item with an ID. These methods find workspaces and items, which is how a service gets an ID it was not given.
list_workspaces
Returns every workspace the app registration is a member of.
Returns a dict with value, a list of dicts each with id, displayName, description, type and capacityId.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ListWorkspaces(Service):
def handle(self):
conn = self.microsoft.fabric['My Fabric']
response = conn.list_workspaces()
workspaces = []
for workspace in response['value']:
workspace_summary = {'id': workspace['id'], 'name': workspace['displayName']}
workspaces.append(workspace_summary)
self.response.payload = {'workspaces': workspaces}
get_workspace
Returns one workspace.
| Parameter | Type | Meaning |
|---|---|---|
workspace_id | str | The workspace |
Returns a dict with the same fields as one entry of list_workspaces.
list_items
Returns the items of a workspace, all of them or one type.
| Parameter | Type | Meaning |
|---|---|---|
workspace_id | str | The workspace |
item_type | str | One of the types below, or empty for every item |
Returns a dict with value, a list of dicts each with id, displayName, description, type and workspaceId.
| Type | What it is |
|---|---|
Lakehouse | Tables and files |
Eventstream | Where events come in and go out |
Eventhouse | Where events are kept for querying |
KQLDatabase | A database inside an eventhouse |
Notebook | A page of Spark code |
DataPipeline | A sequence of steps that moves and reshapes data |
Report | A Power BI report |
SemanticModel | The data a report reads, the item DefaultSemanticModelRefresh runs on |
Warehouse | A SQL warehouse |
# -*- coding: utf-8 -*-
# stdlib
from http.client import NOT_FOUND
# Zato
from zato.server.service import Service
class FindLakehouse(Service):
def handle(self):
workspace_id = '11111111-2222-3333-4444-555555555555'
name = 'Operations'
conn = self.microsoft.fabric['My Fabric']
response = conn.list_items(workspace_id, 'Lakehouse')
# The ID of the lakehouse with the given name ..
for item in response['value']:
if item['displayName'] == name:
self.response.payload = {'lakehouse_id': item['id']}
break
# .. or an error if there is none.
else:
self.response.status_code = NOT_FOUND
self.response.payload = {'error': 'No such lakehouse'}
get_item
Returns one item.
| Parameter | Type | Meaning |
|---|---|---|
workspace_id | str | The workspace the item is in |
item_id | str | The item |
Returns a dict with the same fields as one entry of list_items.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class GetItem(Service):
def handle(self):
workspace_id = '11111111-2222-3333-4444-555555555555'
item_id = '66666666-7777-8888-9999-000000000000'
conn = self.microsoft.fabric['My Fabric']
item = conn.get_item(workspace_id, item_id)
self.response.payload = {'name': item['displayName'], 'type': item['type']}
Shortcuts
A shortcut makes data that lives in another workspace, or in storage outside Fabric, appear inside a lakehouse without copying it. Three methods manage them:
conn.list_shortcuts(workspace_id, item_id)
conn.create_shortcut(workspace_id, item_id, data)
conn.delete_shortcut(workspace_id, item_id, shortcut_path, shortcut_name)
list_shortcuts returns a dict with value, a list of shortcuts each with name, path and target. create_shortcut takes the shortcut as a dict in the shape the Fabric API expects and returns the created shortcut. delete_shortcut takes the folder the shortcut is in, Tables or Files, and its name.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class LinkInsurerTable(Service):
def handle(self):
workspace_id = '11111111-2222-3333-4444-555555555555'
lakehouse_id = '66666666-7777-8888-9999-000000000000'
source_workspace_id = '22222222-3333-4444-5555-666666666666'
source_lakehouse_id = '77777777-8888-9999-0000-111111111111'
conn = self.microsoft.fabric['My Fabric']
# The insurers table of another workspace's lakehouse, readable here as `insurers`.
shortcut = {
'name': 'insurers',
'path': 'Tables',
'target': {
'oneLake': {
'workspaceId': source_workspace_id,
'itemId': source_lakehouse_id,
'path': 'Tables/insurers',
}
}
}
conn.create_shortcut(workspace_id, lakehouse_id, shortcut)
Capacities
A capacity is the computing power a workspace runs on, which your organization pays for. conn.list_capacities() returns the ones the app registration can see, as a dict with value, a list of dicts each with id, displayName, sku, region and state. A workspace's capacityId from list_workspaces matches one of these IDs.
See also
| Page | What it covers |
|---|---|
| Connection | What makes a workspace visible to the connection |
| Jobs | What to do with a notebook or pipeline ID once found |
| Tables | What to do with a lakehouse ID once found |