Python Microsoft Fabric - Workspaces
Fabric workspaces - listing, inspecting, creating and deleting them, plus capacity assignments.
Workspaces are the top-level containers in Fabric - everything else, from lakehouses to reports, lives inside one. You create a Fabric connection in the Dashboard, and every workspace the connection's principal has access to is available to your services.
Listing workspaces
conn.list_workspaces returns all the workspaces the connection can see, each with its ID, display name and capacity assignment.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ListAllWorkspaces(Service):
def handle(self):
# Get the connection by its Dashboard name
conn = self.microsoft.fabric['My Fabric']
# List all the workspaces
response = conn.list_workspaces()
# Summarize each workspace
workspaces = []
for workspace in response['value']:
workspaces.append({
'id': workspace['id'],
'name': workspace['displayName'],
})
self.response.payload = {'workspaces': workspaces}
Inspecting a single workspace
conn.get_workspace returns full details of one workspace, including its description and capacity.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class GetWorkspaceDetails(Service):
input = 'workspace_id'
def handle(self):
conn = self.microsoft.fabric['My Fabric']
workspace = conn.get_workspace(self.request.input.workspace_id)
self.response.payload = {
'name': workspace['displayName'],
'description': workspace['description'],
}
Creating a workspace
conn.create_workspace creates a new workspace - for instance, one workspace per customer or per project, provisioned on demand.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ProvisionCustomerWorkspace(Service):
input = 'customer_name'
def handle(self):
conn = self.microsoft.fabric['My Fabric']
# Create a workspace named after the customer
name = 'Customer - {}'.format(self.request.input.customer_name)
workspace = conn.create_workspace(name, description='Provisioned automatically')
self.response.payload = {'workspace_id': workspace['id']}
Deleting a workspace
Deleting a workspace removes it together with all its items - the standard teardown step when a project or customer is offboarded.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class OffboardCustomerWorkspace(Service):
input = 'workspace_id'
def handle(self):
conn = self.microsoft.fabric['My Fabric']
conn.delete_workspace(self.request.input.workspace_id)
self.response.payload = {'status': 'deleted'}
Listing capacities
Workspaces run on capacities - the compute resources your organization licenses. conn.list_capacities returns the ones the principal can see, which is useful when assigning workspaces programmatically.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ListFabricCapacities(Service):
def handle(self):
conn = self.microsoft.fabric['My Fabric']
response = conn.list_capacities()
capacities = []
for capacity in response['value']:
capacities.append({
'id': capacity['id'],
'sku': capacity['sku'],
'state': capacity['state'],
})
self.response.payload = {'capacities': capacities}