Fabric API - Workspaces

list_workspaces, get_workspace, list_items and get_item, plus shortcuts and capacities.

In Fabric nomenclature, a workspace holds items, e.g. a lakehouse, a notebook, a pipeline or a report, each with an ID. The methods below list workspaces and items, so a service can look up an ID by name.

list_workspaces

conn.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['Zato 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}
{"workspaces": [{"id": "262ddd3d-3d0d-4495-b80f-6dddda1e23a1", "name": "Clinic Analytics"}]}

get_workspace

conn.get_workspace(workspace_id)

Returns one workspace.

ParameterTypeMeaning
workspace_idstrThe workspace

Returns a dict with the same fields as one entry of list_workspaces.

list_items

conn.list_items(workspace_id, item_type='')

Returns the items of a workspace, all of them or one type.

ParameterTypeMeaning
workspace_idstrThe workspace
item_typestrOne 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.

TypeWhat it is
LakehouseTables and files
EventstreamWhere events are received and routed onward
EventhouseWhere events are kept for querying
KQLDatabaseA database inside an eventhouse
NotebookA page of Spark code
DataPipelineA sequence of steps that moves and reshapes data
ReportA Power BI report
SemanticModelThe data a report reads, the item DefaultSemanticModelRefresh runs on
WarehouseA 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 = '262ddd3d-3d0d-4495-b80f-6dddda1e23a1'
        name = 'Operations'

        conn = self.microsoft.fabric['Zato Fabric']

        response = conn.list_items(workspace_id, 'Lakehouse')

        # The ID of the lakehouse with this 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'}
{"lakehouse_id": "73811955-064d-481a-a7e9-f9c563124f9e"}

get_item

conn.get_item(workspace_id, item_id)

Returns one item.

ParameterTypeMeaning
workspace_idstrThe workspace the item is in
item_idstrThe 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 = '262ddd3d-3d0d-4495-b80f-6dddda1e23a1'
        item_id = '73811955-064d-481a-a7e9-f9c563124f9e'

        conn = self.microsoft.fabric['Zato Fabric']

        item = conn.get_item(workspace_id, item_id)

        self.response.payload = {'name': item['displayName'], 'type': item['type']}

Shortcuts

A shortcut makes data from another workspace, or from storage outside Fabric, appear inside a lakehouse without copying it. There are three methods for shortcuts:

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 format 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 = '262ddd3d-3d0d-4495-b80f-6dddda1e23a1'
        lakehouse_id = '73811955-064d-481a-a7e9-f9c563124f9e'

        source_workspace_id = '22222222-3333-4444-5555-666666666666'
        source_lakehouse_id = '77777777-8888-9999-0000-111111111111'

        conn = self.microsoft.fabric['Zato 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. 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

PageWhat it covers
Fabric API - ConnectionWhat makes a workspace visible to the connection
Fabric API - JobsWhat to do with a notebook or pipeline ID once found
Fabric API - TablesWhat to do with a lakehouse ID once found

Learn more