# 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 list workspaces and items, so a service can look up an ID by name.

## list\_workspaces {#list_workspaces}

```python
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`.

```python
# -*- 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}
```

```json
{"workspaces": [{"id": "11111111-2222-3333-4444-555555555555", "name": "Analytics"}]}
```

## get\_workspace {#get_workspace}

```python
conn.get_workspace(workspace_id)
```

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 {#list_items}

```python
conn.list_items(workspace_id, item_type='')
```

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 |

```python
# -*- 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 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'}
```

```json
{"lakehouse_id": "66666666-7777-8888-9999-000000000000"}
```

## get\_item {#get_item}

```python
conn.get_item(workspace_id, item_id)
```

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`.

```python
# -*- 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 {#shortcuts}

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

```python
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.

```python
# -*- 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 {#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 {#see-also}

- [Connection](https://zato.io/docs/dev/examples/cloud/fabric/api/connection.html) - What makes a workspace visible to the connection
- [Jobs](https://zato.io/docs/dev/examples/cloud/fabric/api/jobs.html) - What to do with a notebook or pipeline ID once found
- [Tables](https://zato.io/docs/dev/examples/cloud/fabric/api/tables.html) - What to do with a lakehouse ID once found

## Learn more {#learn-more}

- [Development documentation](https://zato.io/docs/dev/) - Everything about writing services, in one place
- [Requests and responses](https://zato.io/docs/dev/request-response/) - What a service receives, what it returns and how to shape both
- [Integration examples](https://zato.io/docs/dev/examples/) - Ready-made code for the systems you are likely to connect to
- [IDE and debugging](https://zato.io/docs/dev/ide/) - Write services in the Dashboard or in your own editor
- [Data models](https://zato.io/docs/dev/model/) - Declare inputs and outputs and have them validated for you
- [In-depth API tutorial](https://zato.io/tutorials/main/01.html) - The full platform tutorial, from installation to production patterns
