# Fabric API - Files

onelake\_list, onelake\_read, onelake\_write and onelake\_delete, and the two forms a file path takes.

The four methods below read and write files in OneLake, the storage behind every lakehouse, and the `Files` section in the lakehouse explorer is the folder they work in.

## File paths {#file-paths}

Every path starts with the lakehouse and continues into it, and the lakehouse can be named in two ways:

| Form | Example |
| --- | --- |
| Name and type | `Operations.Lakehouse/Files/incoming/invoices-2026-08.csv` |
| Item ID | `73811955-064d-481a-a7e9-f9c563124f9e/Files/incoming/invoices-2026-08.csv` |

Both forms work in every method below. A lakehouse keeps files under `Files`, and the [table methods](https://zato.io/docs/dev/examples/cloud/fabric/api/tables.html) write to `Tables`, next to it.

## onelake\_list {#onelake_list}

```python
conn.onelake_list(workspace_id, directory='')
```

Lists the files and subfolders directly under a path.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `workspace_id` | str | The workspace whose storage to list |
| `directory` | str | The folder to list, e.g. `Operations.Lakehouse/Files/incoming`, or empty for the top of the workspace |

Returns a dict with `paths`, a list of dicts each with `name` (the full path), `isDirectory` (`true` or `false`), `contentLength` and `lastModified`.

```python
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ListFiles(Service):

    def handle(self):

        workspace_id = '262ddd3d-3d0d-4495-b80f-6dddda1e23a1'

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

        listing = conn.onelake_list(workspace_id, 'Operations.Lakehouse/Files/incoming')

        files = []
        for path in listing['paths']:
            file = {'name': path['name'], 'is_directory': path['isDirectory']}
            files.append(file)

        self.response.payload = {'files': files}
```

```json
{"files": [{"name": "Operations.Lakehouse/Files/incoming/invoices-2026-08.csv", "is_directory": false}]}
```

## onelake\_read {#onelake_read}

```python
conn.onelake_read(workspace_id, file_path)
```

Returns a file's contents as bytes.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `workspace_id` | str | The workspace the file is in |
| `file_path` | str | The file, in either path form |

```python
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ReadFile(Service):

    def handle(self):

        workspace_id = '262ddd3d-3d0d-4495-b80f-6dddda1e23a1'
        file_path = 'Operations.Lakehouse/Files/incoming/invoices-2026-08.csv'

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

        data = conn.onelake_read(workspace_id, file_path)
        text = data.decode('utf-8')

        size = len(data)
        lines = text.splitlines()
        first_line = lines[0]

        self.response.payload = {'size': size, 'first_line': first_line}
```

```json
{"size": 142, "first_line": "invoice_id,location,insurer,amount,status,sent_at"}
```

## onelake\_write {#onelake_write}

```python
conn.onelake_write(workspace_id, file_path, data)
```

Creates a file with these contents, or replaces it if it exists. Missing folders in the path are created.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `workspace_id` | str | The workspace to write to |
| `file_path` | str | The file, in either path form |
| `data` | bytes, str or list of dicts | The contents - bytes go as they are, text is written as UTF-8, a list of dicts becomes CSV with a header made of the first row's keys |

Returns nothing.

```python
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class WriteFile(Service):

    def handle(self):

        workspace_id = '262ddd3d-3d0d-4495-b80f-6dddda1e23a1'
        file_path = 'Operations.Lakehouse/Files/exports/invoices-2026-08.csv'

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

        rows = [
          {'location': 'Riverside',   'invoiced': 2895.50},
          {'location': 'Oak Hill',    'invoiced': 1840.00},
          {'location': 'Maple Grove', 'invoiced': 415.75},
        ]

        conn.onelake_write(workspace_id, file_path, rows)

        self.response.payload = {'rows': len(rows)}
```

## onelake\_delete {#onelake_delete}

```python
conn.onelake_delete(workspace_id, file_path, recursive=False)
```

Deletes a file, or a folder with everything in it.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `workspace_id` | str | The workspace the file is in |
| `file_path` | str | The file or folder, in either path form |
| `recursive` | bool | `True` to delete a folder along with its files and subfolders |

Returns nothing. Deleting a file that does not exist raises an exception, as does deleting a non-empty folder without `recursive`.

```python
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class DeleteFile(Service):

    def handle(self):

        workspace_id = '262ddd3d-3d0d-4495-b80f-6dddda1e23a1'
        file_path = 'Operations.Lakehouse/Files/incoming/invoices-2026-08.csv'

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

        conn.onelake_delete(workspace_id, file_path)
```

## See also {#see-also}

- [Fabric API - Tables](https://zato.io/docs/dev/examples/cloud/fabric/api/tables.html) - Importing a written file into a table with load\_table
- [Writing data to Fabric](https://zato.io/docs/dev/examples/cloud/fabric/writing-data.html) - Loading a file into a table and writing a monthly export
- [Fabric API - Connection](https://zato.io/docs/dev/examples/cloud/fabric/api/connection.html) - The storage token these methods use

## Learn more {#learn-more}

- [Development documentation](https://zato.io/docs/dev/) - The complete reference for writing services
- [Requests and responses](https://zato.io/docs/dev/request-response/) - What a service receives, what it returns and how both are structured
- [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
