Python Microsoft Fabric API - Tables

write_table, load_table, list_tables and wait_for_operation, with every parameter.

A connection has four methods for lakehouse tables. Every one takes the workspace ID and the lakehouse ID first.

write_table

conn.write_table(workspace_id, lakehouse_id, table_name, rows, mode='Overwrite')

Writes a list of dicts to a table and returns once the data is in it. The rows are written as CSV files to Files/zato/<table_name>/<timestamp>/ in the lakehouse, 100,000 rows per file, then loaded into the table in one operation that the call waits for.

ParameterTypeMeaning
workspace_idstrThe workspace the lakehouse is in
lakehouse_idstrThe lakehouse the table is in
table_namestrThe table to write to, created if it does not exist
rowslist of dictThe rows, all with the keys of the first one, which become the columns
modestrOverwrite replaces the table with the rows, Append adds them to what is there

Returns the completed operation as a dict, with status set to Succeeded. A load that fails raises an exception with the operation's details.

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

# Zato
from zato.server.service import Service

class WriteTable(Service):

    def handle(self):

        workspace_id = '11111111-2222-3333-4444-555555555555'
        lakehouse_id = '66666666-7777-8888-9999-000000000000'

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

        rows = [
            {'insurer_id': 'INS-01', 'name': 'Cascade Health Plan'},
            {'insurer_id': 'INS-02', 'name': 'Pacific Mutual'},
            {'insurer_id': 'INS-03', 'name': 'Evergreen Assurance'},
        ]

        operation = conn.write_table(workspace_id, lakehouse_id, 'insurers', rows)

        self.response.payload = {'status': operation['status']}

load_table

conn.load_table(workspace_id, lakehouse_id, table_name, relative_path, mode='Overwrite',
    file_format='Csv', header=True, delimiter=',', path_type='File', recursive=False)

Starts loading a file or a folder that is already in the lakehouse's Files section into a table and returns right away, without waiting.

ParameterTypeMeaning
workspace_idstrThe workspace the lakehouse is in
lakehouse_idstrThe lakehouse the table and the file are in
table_namestrThe table to load into, created if it does not exist
relative_pathstrThe file or folder, relative to the lakehouse, e.g. Files/incoming/admissions.csv
modestrOverwrite or Append, as in write_table
file_formatstrCsv or Parquet
headerboolCSV only - whether the first line holds the column names
delimiterstrCSV only - the character between values
path_typestrFile when relative_path is one file, Folder when it is a folder of files
recursiveboolFolders only - whether to include files in subfolders

Returns the address of the operation's status endpoint as a string, for wait_for_operation.

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

# Zato
from zato.server.service import Service

class LoadTable(Service):

    def handle(self):

        workspace_id = '11111111-2222-3333-4444-555555555555'
        lakehouse_id = '66666666-7777-8888-9999-000000000000'

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

        location = conn.load_table(
            workspace_id,
            lakehouse_id,
            'admissions',
            'Files/incoming/admissions',
            mode='Append',
            file_format='Parquet',
            path_type='Folder',
            recursive=True,
        )

        self.response.payload = {'location': location}

wait_for_operation

conn.wait_for_operation(location, timeout=600, interval=2.0)

Waits until a long-running operation ends and returns its final state. load_table is the method that returns such a location, and write_table calls this one on your behalf.

ParameterTypeMeaning
locationstrThe address load_table returned
timeoutintSeconds to wait before giving up
intervalfloatSeconds between checks

Returns the operation as a dict with status set to Succeeded. An operation that fails raises an exception with its details, one that does not end within timeout raises an exception naming the location.

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

# Zato
from zato.server.service import Service

class LoadAndWait(Service):

    def handle(self):

        workspace_id = '11111111-2222-3333-4444-555555555555'
        lakehouse_id = '66666666-7777-8888-9999-000000000000'

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

        location = conn.load_table(
            workspace_id,
            lakehouse_id,
            'invoices',
            'Files/incoming/payments-2026-03.csv',
            mode='Append',
        )

        operation = conn.wait_for_operation(location, timeout=300)

        self.response.payload = {'status': operation['status']}

list_tables

conn.list_tables(workspace_id, lakehouse_id)

Returns every table of a lakehouse as a list of dicts, following Fabric's paging until there are no more.

ParameterTypeMeaning
workspace_idstrThe workspace the lakehouse is in
lakehouse_idstrThe lakehouse to list

Each dict has name, type, location and format.

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

# Zato
from zato.server.service import Service

class ListTables(Service):

    def handle(self):

        workspace_id = '11111111-2222-3333-4444-555555555555'
        lakehouse_id = '66666666-7777-8888-9999-000000000000'

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

        tables = conn.list_tables(workspace_id, lakehouse_id)

        names = []
        for table in tables:
            names.append(table['name'])

        self.response.payload = {'tables': names}
{"tables": ["admissions", "appointments", "insurers", "inventory", "invoices", "locations", "occupancy", "staff"]}

See also

PageWhat it covers
QueriesReading the tables back with SQL
FilesPutting the files load_table reads into the lakehouse
Loading data into tablesThese methods at work in the nightly load

Learn more