Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Module

.sink_parquet

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.

How it works

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.

Syntax

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

Parameters

NameTypeDescription
pathstr | Path | IO[bytes] | PartitionByDestination for the Parquet output; accepts a string, Path, byte stream, or PartitionBy.
compressionParquetCompressionParquet compression codec.
compression_levelint | NoneOptional compression-level setting.
statisticsbool | str | dict[str, bool]Whether and how to write Parquet statistics.
row_group_sizeint | NoneOptional number of rows per row group.
data_page_sizeint | NoneOptional data-page size.
maintain_orderboolWhether to maintain output order.
storage_optionsStorageOptionsDict | NoneOptional cloud or object-storage configuration.

Returns

DataFrame

Key points

  • It combines lazy-query execution with Parquet output in a streaming sink.
  • The path identifies where the generated Parquet data is stored.
  • Compression defaults to zstd unless another supported Parquet compression setting is selected.
  • Parquet statistics can be enabled, disabled, or configured with a string or per-column dictionary.
  • The row-group size is configurable when tuning the layout of the written Parquet data.
  • Output ordering is controlled by maintain_order, which defaults to preserving order.

Common mistakes

  • The method executes the lazy query as a sink, so it is not merely configuring an output; it evaluates the query and writes the result.

Example: Stream a lazy query to Parquet

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.

When to use it

Large-data export

Process a large lazy input and persist the result without requiring the complete result in memory.

Pipeline materialization

Create Parquet output from a transformed LazyFrame for downstream analytics.

Object-storage output

Write results to cloud-backed storage using storage configuration.

Partitioned datasets

Generate partitioned or size-limited Parquet files with a PartitionBy destination.

Interview questions

QWhat does LazyFrame.sink_parquet do?

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.

QWhat does the path parameter accept?

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.

QWhich output controls are available?

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.LazyFrame
  • polars.PartitionBy
  • polars.scan_csv
  • polars.scan_parquet

Source: polars.LazyFrame.sink_parquet — Polars documentation. Checked 2026-10-15.