Skip to content

lakehouse_files_writer

sqllocks_spindle.fabric.lakehouse_files_writer

Lakehouse Files landing-zone writer for Fabric.

Classes

LakehouseWriteResult dataclass

Result of a Lakehouse write_all() operation.

LakehouseFilesWriter

Write data files into Lakehouse Files landing zones.

This writer targets the Files/ area of a Fabric Lakehouse (flat files in landing zones), as opposed to :class:~sqllocks_spindle.output.DeltaWriter which writes Delta tables into the Tables/ area.

Uses :class:OneLakePaths for consistent path construction and works both inside a Fabric runtime and locally with a configurable base path.

Parameters:

Name Type Description Default
base_path str | Path | None

Root path for the Lakehouse Files area. Passed through to :class:OneLakePaths. If None, auto-detects Fabric or falls back to ./lakehouse_files.

None
default_format str

Default output format — "parquet", "csv", or "jsonl" (default "parquet").

'parquet'

Example::

from sqllocks_spindle.fabric import LakehouseFilesWriter, OneLakePaths

writer = LakehouseFilesWriter(base_path="./test_output")
paths = OneLakePaths(base_path="./test_output")
dest = paths.landing_zone_path("retail", "order", "2025-01-15", hour=10)

writer.write_partition(df, dest, format="parquet")
writer.write_done_flag(paths.done_flag_path("retail", "order", "2025-01-15"))
Attributes
paths property

Return the underlying :class:OneLakePaths instance.

Methods:
write_all(tables, format=None, **kwargs)

Write each table as a bulk file (Parquet/CSV/JSONL).

Conforms to the SpindleWriter protocol so LakehouseFilesWriter can be used with MultiWriter.

Parameters:

Name Type Description Default
tables dict[str, DataFrame]

Mapping of table_name -> DataFrame.

required
format str | None

Output format (defaults to writer's default_format).

None
**kwargs Any

Extra args passed to write_partition.

{}

Returns:

Type Description
LakehouseWriteResult

LakehouseWriteResult with per-table row counts and any errors.

write_partition(df, path, format=None, file_naming_template=None)

Write a DataFrame as a data file into a landing-zone partition.

Parameters:

Name Type Description Default
df DataFrame

DataFrame to write.

required
path str | Path

Target directory for the partition.

required
format str | None

Output format — "csv", "parquet", or "jsonl". Falls back to default_format if None.

None
file_naming_template str | None

Template for the output file name. Supports {format} placeholder. Defaults to "part-0001.{format}".

None

Returns:

Type Description
Path

Path to the written file.

Raises:

Type Description
ValueError

If format is unsupported.

write_manifest(manifest_dict, path)

Write a manifest JSON file to the control directory.

Parameters:

Name Type Description Default
manifest_dict dict[str, Any]

Manifest contents (serialised as JSON).

required
path str | Path

Full path to the manifest file.

required

Returns:

Type Description
Path

Path to the written manifest file.

write_done_flag(path)

Write an empty _SUCCESS sentinel file.

Parameters:

Name Type Description Default
path str | Path

Full path to the done-flag file.

required

Returns:

Type Description
Path

Path to the written sentinel file.