Python Microsoft Fabric API - Files

onelake_list, onelake_read, onelake_write and onelake_delete, and the two forms a file path takes.

A connection has four methods for files. They read and write OneLake, the storage behind every lakehouse, directly - the Files section in the lakehouse explorer is the folder they work in. They use a second token, for storage rather than for the Fabric API, which the connection obtains and refreshes on its own alongside the first.

File paths

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

FormExample
Name and typeOperations.Lakehouse/Files/incoming/payments-2026-03.csv
Item ID66666666-7777-8888-9999-000000000000/Files/incoming/payments-2026-03.csv

Both forms work in every method below. Files is where a lakehouse keeps files, and Tables next to it is where its tables are stored, which the table methods manage.

onelake_list

conn.onelake_list(workspace_id, directory='')

Lists what is directly under a path - files and subfolders, without going into the subfolders.

ParameterTypeMeaning
workspace_idstrThe workspace whose storage to list
directorystrThe 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.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ListFiles(Service):

    def handle(self):

        workspace_id = '11111111-2222-3333-4444-555555555555'

        conn = self.microsoft.fabric['My 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}
{"files": [{"name": "Operations.Lakehouse/Files/incoming/payments-2026-03.csv", "is_directory": false}]}

onelake_read

conn.onelake_read(workspace_id, file_path)

Returns a file's contents as bytes.

ParameterTypeMeaning
workspace_idstrThe workspace the file is in
file_pathstrThe file, in either path form
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ReadFile(Service):

    def handle(self):

        workspace_id = '11111111-2222-3333-4444-555555555555'
        file_path = 'Operations.Lakehouse/Files/incoming/payments-2026-03.csv'

        conn = self.microsoft.fabric['My 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}
{"size": 142, "first_line": "invoice_id,location,insurer,amount,status,sent_at"}

onelake_write

conn.onelake_write(workspace_id, file_path, data)

Creates a file with the given bytes, or replaces it if it exists. Folders on the way are created as needed.

ParameterTypeMeaning
workspace_idstrThe workspace to write to
file_pathstrThe file, in either path form
databytesThe contents

Returns nothing.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class WriteFile(Service):

    def handle(self):

        workspace_id = '11111111-2222-3333-4444-555555555555'
        file_path = 'Operations.Lakehouse/Files/exports/invoices-2026-03.csv'

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

        text = 'location,invoiced\nRiverside,2895.50\nOak Hill,1840.00\nMaple Grove,415.75\n'
        data = text.encode('utf-8')

        conn.onelake_write(workspace_id, file_path, data)

        self.response.payload = {'bytes': len(data)}

onelake_delete

conn.onelake_delete(workspace_id, file_path)

Deletes a file.

ParameterTypeMeaning
workspace_idstrThe workspace the file is in
file_pathstrThe file, in either path form

Returns nothing. Deleting a file that does not exist raises an exception.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class DeleteFile(Service):

    def handle(self):

        workspace_id = '11111111-2222-3333-4444-555555555555'
        file_path = 'Operations.Lakehouse/Files/incoming/payments-2026-03.csv'

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

        conn.onelake_delete(workspace_id, file_path)

See also

PageWhat it covers
TablesTurning a written file into a table with load_table
Sending and receiving filesThese methods at work on an incoming file and a monthly export
ConnectionThe storage token these methods use

Learn more