Large-data export
Process a large lazy input and persist the result without requiring the complete result in memory.
Polars · Module
Evaluates a LazyFrame query in streaming mode and writes its result to Parquet. It supports local paths, byte streams, partitioned destinations, compression, statistics, row groups, and storage options.
Call this on a LazyFrame to execute its query in streaming mode and persist the resulting data as Parquet. The destination may be a path, byte stream, or partitioning configuration, while compression, statistics, row groups, ordering, and storage access can be configured with keyword arguments.
LazyFrame.sink_parquet(path: str | Path | IO[bytes] | PartitionBy, *, compression: ParquetCompression = 'zstd', compression_level: int | None = None, statistics: bool | str | dict[str, bool] = True, row_group_size: int | None = None, data_page_size: int | None = None, maintain_order: bool = True, storage_options: StorageOptionsDict | None = None) → DataFrame| Name | Type | Description |
|---|---|---|
path | str | Path | IO[bytes] | PartitionBy | Destination for the Parquet output; accepts a string, Path, byte stream, or PartitionBy. |
compression | ParquetCompression | Parquet compression codec. |
compression_level | int | None | Optional compression-level setting. |
statistics | bool | str | dict[str, bool] | Whether and how to write Parquet statistics. |
row_group_size | int | None | Optional number of rows per row group. |
data_page_size | int | None | Optional data-page size. |
maintain_order | bool | Whether to maintain output order. |
storage_options | StorageOptionsDict | None | Optional cloud or object-storage configuration. |
DataFrame
import polars as pl
lf = pl.scan_csv("input.csv")
result = lf.filter(pl.col("value") > 0).sink_parquet("output.parquet")
print(result)This lazily scans a CSV, filters rows, streams the query result, and writes it to a Parquet file.
Process a large lazy input and persist the result without requiring the complete result in memory.
Create Parquet output from a transformed LazyFrame for downstream analytics.
Write results to cloud-backed storage using storage configuration.
Generate partitioned or size-limited Parquet files with a PartitionBy destination.
It evaluates a LazyFrame query in streaming mode and writes the result to Parquet. This is useful for processing data that may exceed available RAM.
Follow-up: How can the output be split into multiple files? Pass a PartitionBy destination and configure its partitioning or file-size limits.
The required path argument identifies the output destination and accepts a string, Path, byte-oriented IO object, or PartitionBy value. Other controls, such as compression and row-group sizing, are keyword-only.
Follow-up: How would you write the result without creating a filesystem path? Supply a BytesIO-like IO[bytes] object as the destination.
The default compression is zstd. The method also exposes options for compression level, statistics, row-group size, data-page size, output ordering, and storage options.
Follow-up: What is the effect of maintain_order? It controls whether the sink preserves the input order, with true as the documented default.
polars.LazyFramepolars.PartitionBypolars.scan_csvpolars.scan_parquet