Skip to main content

polars-checkpoint

Materialise Polars LazyFrames to parquet files and scan them back lazily. Defaults to the streaming engine for sink/scan. Useful for managing & reducing memory pressure due to expensive intermediate results in complex multi-step transforms.

Installation

Requires polars and Python 3.10+.

Quick Start

import polars as pl
from polars_checkpoint import checkpoint

lf = pl.LazyFrame({"x": range(1_000_000)}).with_columns(y=pl.col("x") * 2)

# Materialises to a temp parquet file; returns a lazy re-scan
lf = checkpoint(lf)

lf.filter(pl.col("y") > 100).collect()

A process-wide default session manages the temp directory and cleans it up at exit.

Session API

For explicit control over storage location and lifecycle, use CheckpointSession:

from polars_checkpoint import CheckpointSession

# As a context manager — cleans up on exit from the block
with CheckpointSession(root_dir="./my_checkpoints") as sess:
    lf = pl.scan_csv("big.csv")
    lf = sess.checkpoint(lf, name="after-parse")
    lf = lf.filter(pl.col("status") == "active")
    lf = sess.checkpoint(lf, name="filtered")
# Without a context manager — cleans up at GC or interpreter shutdown,
# or when you call close() explicitly
sess = CheckpointSession(root_dir="./my_checkpoints")
lf = sess.checkpoint(pl.scan_csv("big.csv"), name="raw")
reloaded = sess["raw"]
print(sess.summary())

sess.close()  # optional; triggers early cleanup

CheckpointSession constructor

Parameter Default Description
root_dir None (auto temp dir) Parent directory for checkpoint folders.
cleanup True Delete checkpoint files on close / GC / interpreter exit.
default_sink_kwargs {"compression": "zstd"} Defaults passed to sink_parquet / write_parquet.
default_scan_kwargs {} Defaults passed to scan_parquet.

Key methods & features

  • checkpoint(lf, *, name=None, streaming=True, ...) — Materialise a LazyFrame to parquet. Auto-generates a name if none given. Falls back to collect().write_parquet() when streaming=False.
  • session[name] — Retrieve a checkpoint as a LazyFrame.
  • name in session — Check existence.
  • len(session) / iter(session) — Count / list checkpoints.
  • summary() — Returns a Polars DataFrame with name, size (MB), and path of each checkpoint.
  • close(timeout=None) — Waits for in-flight writes, then cleans up. Also usable as a context manager.

Thread Safety

Sessions are internally locked. Concurrent checkpoint() calls from multiple threads are safe; close() waits for all in-flight materialisations before removing files.

Cleanup Behaviour

Scenario cleanup=True (default) cleanup=False
close() / __exit__ Files deleted Files retained
GC / interpreter shutdown Files deleted (via weakref.finalize) Files retained

When root_dir is auto-generated, the entire temp directory is removed. When user-supplied, only the individual checkpoint subdirectories created by the session are removed.

Release files for polars-checkpoint 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars-checkpoint 0.1.5
File Size Uploaded
polars_checkpoint-0.1.5.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for polars-checkpoint 0.1.5
File Interpreter ABI Platform
polars_checkpoint-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / polars_checkpoint-0.1.5.tar.gz

Download URL polars_checkpoint-0.1.5.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b6b6bc356af6ab5ce2436ea577b753334c86c714b931622d983ce444146ec275
BLAKE2b-256 checksum
How to use checksums
a65e038eda1513426fa310ad8e023c29e33b820fc7f536c8c67a3d0623b6baa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / polars_checkpoint-0.1.5-py3-none-any.whl

Download URL polars_checkpoint-0.1.5-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83e9e95cfca64465a0303e258369c9f227d8437c0083ef5a41acf60c75a4695b
BLAKE2b-256 checksum
How to use checksums
9115436f0fe3dc227275a24367c348368153d7983c1f59dd7a60bab174b85c8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page