Skip to main content

polars_readstat

Polars plugin for SAS (.sas7bdat), Stata (.dta), and SPSS (.sav/.zsav) files.

The Python package wraps the Rust core in polars_readstat_rs and exposes a Polars-first API. The project includes cross-library parity tests and roundtrip checks to reduce regressions.

Why use this?

  • In project benchmarks, polars_readstat is typically faster than pandas/pyreadstat (usually at least 4x faster), and can be much, much faster for loading subsets of rows or columns.
  • It returns a Polars LazyFrame, so many polars operations that reduce the number of columns or rows you need can be pushed into the reader — only the data you actually need is read from disk.
  • Lots of customization and options for reading metadata (quickly), handling formats and labels, special null encoding, etc. to flexibly handle many needs when converting stat software data into a polars dataframe
  • Fast and low memory streaming of files to parquet, if you just want to get the data out of the original format to something more efficient (see code below).

Install

uv add polars-readstat

or if you prefer pip:

pip install polars-readstat

Docs/Core API

View the docs at https://jrothbaum.github.io/polars_readstat/ for more information than below on the options you can pass to the scan and write functions.

1) Lazy scan

import polars as pl
from polars_readstat import scan_readstat

lf = scan_readstat("/path/file.sas7bdat")
#   do something
df = lf.collect()

df = (
    scan_readstat("/path/file.sas7bdat")
    .select(["SERIALNO", "AGEP"])   # column pushdown — only these columns are read
    .head(1_000)                    # row limit is pushed down too
    .filter(pl.col("AGEP") >= 18)   # filters applied to streamed batches to avoid loading full file into memory
    .collect()
)

Cloud paths

lf = scan_readstat("s3://my-bucket/path/file.sas7bdat")   # also gs:// and az://

Credentials come from the usual AWS_* / GOOGLE_* / AZURE_* environment variables, ~/.aws files, or storage_options, the same as for Polars. See Cloud storage.

2) Getting metadata

from polars_readstat import ScanReadstat

reader = ScanReadstat(path="/path/file.sav")
schema = reader.schema           # polars.Schema
metadata = reader.metadata       # dict with file info and per-column details
lf = reader.df                   # LazyFrame — same as calling scan_readstat(path)

metadata is a dict with a variables (SPSS/Stata) or columns (SAS) list. Each entry includes:

  • "name" — column name
  • "label" — variable label (description), if present
  • "value_labels" — dict mapping coded values to label strings, if present

Polars lazy evaluation

scan_readstat returns a LazyFrame, so Polars can push operations into the reader before any data is loaded:

Read only specific columns — column selection is pushed into the reader; unselected columns are never read from disk:

lf = scan_readstat("file.sav")
df = lf.select(["id", "age", "income"]).collect()

Read the first N rows — head() / limit() stops the reader after N rows, so you never load the full file:

df = scan_readstat("file.sas7bdat").head(1000).collect()

Filter rows — filters are applied in Polars after reading, but still benefit from column pushdown if combined with .select():

df = scan_readstat("file.dta").select(["id", "age"]).filter(pl.col("age") >= 18).collect()

The benchmark numbers below reflect these optimizations — the large "Subset: True" speedups come from column pushdown.

3) Write

Writing support is experimental and compatibility varies across tools. Stata roundtrip tests are included; SPSS roundtrip coverage is limited. Please report issues.

from polars_readstat import write_readstat, write_sas_csv_import

write_readstat(df, "/path/out.dta")
write_readstat(df, "/path/out.sav")
write_sas_csv_import(df, "/path/out/sas_bundle", dataset_name="my_data")

write_readstat supports Stata (dta) and SPSS (sav).
Use write_sas_csv_import for SAS-ingestible output (.csv, or .csv.gz with gzip=True, plus a .sas import script; see docs/write.md). Binary .sas7bdat writing is not currently supported.

4) You just want to get the data into parquet (or any other polars-supported file type):

Fast, Low-RAM Conversion

scan_readstat("/path/file.sas7bdat").sink_parquet("/path/file.parquet")

To give context, I converted a very tall sas file (over 8 billion rows) that was 500GB on disk to parquet and never exceeded 1GB of RAM.

Keep the Row Order

Row order isn't guaranteed by default. Add preserve_order=True to keep the file's order; it shouldn't cost much (if any) extra RAM or speed.

scan_readstat("/path/file.sas7bdat",preserve_order=True).sink_parquet("/path/file.parquet")

Benchmark

Benchmarks compare four scenarios: 1) load the full file, 2) load a subset of columns (Subset:True), 3) filter to a subset of rows (Filter: True), 4) load a subset of columns and filter to a subset of rows (Subset:True, Filter: True).

Benchmark context:

  • Machine: AMD Ryzen 7 8845HS (16 cores), 14 GiB RAM, Linux Mint 22
  • Storage: external SSD
  • Last run: November 30, 2026 — polars-readstat v0.27.1 (polars 2.2.0) vs pandas 3.1.2 and pyreadstat 1.3.8
  • Each time is the geometric mean of 3 runs, with the file already in the OS file cache (read once before timing)
  • pyreadstat needs about 8 GB of memory for the SAS file; see BENCHMARKS.md for how its SAS times were run
  • Method: wall-clock timings via Python time.time()

Compared to Pandas and Pyreadstat (using read_file_multiprocessing for parallel processing in Pyreadstat)

SAS

all times in seconds (speedup relative to pandas in parenthesis below each)

Library Full File Subset: True Filter: True Subset: True, Filter: True
polars_readstat 0.45
(4.5×)
0.07
(26.4×)
0.56
(5.4×)
0.05
(44.4×)
pandas 2.01 1.94 2.99 2.36
pyreadstat 5.91
(0.3×)
0.55
(3.5×)
6.94
(0.4×)
2.06
(1.1×)

Stata

all times in seconds (speedup relative to pandas in parenthesis below each)

Library Full File Subset: True Filter: True Subset: True, Filter: True
polars_readstat 0.18
(4.5×)
0.09
(8.2×)
0.20
(4.3×)
0.11
(7.1×)
pandas 0.79 0.73 0.86 0.75
pyreadstat 4.51
(0.2×)
1.65
(0.4×)
4.66
(0.2×)
1.67
(0.5×)

SPSS

all times in seconds (speedup relative to pandas in parenthesis below each)

Library Full File Subset: True Filter: True Subset: True, Filter: True
polars_readstat 1.12
(43.1×)
0.16
(3.7×)
0.89
(54.3×)
0.16
(3.8×)
pandas 48.22 0.59 48.23 0.59
pyreadstat 1.88
(25.6×)
0.31
(1.9×)
1.91
(25.3×)
0.31
(1.9×)

zsav

all times in seconds (speedup relative to pandas in parenthesis below each)

Library Full File Subset: True Filter: True Subset: True, Filter: True
polars_readstat 4.09
(4.2×)
0.91
(2.2×)
3.74
(4.6×)
0.92
(2.2×)
pandas 17.14 2.03 17.15 2.03

Detailed benchmark notes and dataset descriptions are in BENCHMARKS.md.

Tests run

Test coverage includes:

  • Cross-library comparisons on the pyreadstat and pandas test data, checking results against polars-readstat==0.11.1, pyreadstat, and pandas.
  • Stata/SPSS read/write roundtrip tests.
  • Large-file read/write benchmark runs on real-world data (results below).

If you want to run the same checks locally, helper scripts and tests are in scripts/ and tests/.

Metadata

Release files for polars-readstat 0.27.1

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

Built distributions (wheels)

Table of built distributions (wheels) for polars-readstat 0.27.1
File Actions
polars_readstat-0.27.1-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for polars_readstat-0.27.1-cp39-abi3-win_arm64.whl
polars_readstat-0.27.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for polars_readstat-0.27.1-cp39-abi3-win_amd64.whl
polars_readstat-0.27.1-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details for polars_readstat-0.27.1-cp39-abi3-manylinux_2_28_x86_64.whl
polars_readstat-0.27.1-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for polars_readstat-0.27.1-cp39-abi3-manylinux_2_28_aarch64.whl
polars_readstat-0.27.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for polars_readstat-0.27.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
polars_readstat-0.27.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for polars_readstat-0.27.1-cp39-abi3-macosx_11_0_arm64.whl
polars_readstat-0.27.1-cp39-abi3-macosx_10_15_x86_64.whl CPython 3.9 abi3 macOS 10.15+ x86-64 Details for polars_readstat-0.27.1-cp39-abi3-macosx_10_15_x86_64.whl

Total release size: 163.6 MB

Release files / polars_readstat-0.27.1-cp39-abi3-win_arm64.whl

Download URL polars_readstat-0.27.1-cp39-abi3-win_arm64.whl
Size 23.5 MB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
fd8b2520a5fb4dd83f0818aa5e84610beb28626f643d0f5805847f426a09d2bc
BLAKE2b-256 checksum
How to use checksums
ba3ea5e60a85d058bc70248cd24ee2723cfb3ffb8aee30d09839491d44e5dd71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / polars_readstat-0.27.1-cp39-abi3-win_amd64.whl

Download URL polars_readstat-0.27.1-cp39-abi3-win_amd64.whl
Size 25.6 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
130ba81906e4b0cfdbaba34750015e3c43bf7dc66a606de4e93ad1aeef4b518e
BLAKE2b-256 checksum
How to use checksums
f3e97b7e27d52f3f858e1171d815a253e2ec97d4175bdb7d8b33e0c646416c37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / polars_readstat-0.27.1-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL polars_readstat-0.27.1-cp39-abi3-manylinux_2_28_x86_64.whl
Size 24.1 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
4dd5614a60ac5821003cb992cdf93f51373947b865edc92d4425b7dd465ef71f
BLAKE2b-256 checksum
How to use checksums
20f7e17bd56bd5cb7b8743ef21bf178bde6d7c5f68821c2e7afa3a493428e1cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / polars_readstat-0.27.1-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL polars_readstat-0.27.1-cp39-abi3-manylinux_2_28_aarch64.whl
Size 22.2 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
5a393b757424e4211dc6d693699ae9bb14a89016f0930125af4c12f56e3d2254
BLAKE2b-256 checksum
How to use checksums
9adfe89085f92f6b80788fb4a6398b4e5b22636a4ce539031c2d68dbe15c12fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / polars_readstat-0.27.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL polars_readstat-0.27.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 24.1 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ffcef0bd006491a1d72adb0f9899c1ffc44ced95292886ff44e117546d7d3e96
BLAKE2b-256 checksum
How to use checksums
ba6a06fa6ed5d2400ab248c5743beb8141549bb44c083f4819768c9b0200075e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / polars_readstat-0.27.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL polars_readstat-0.27.1-cp39-abi3-macosx_11_0_arm64.whl
Size 20.9 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8f8982f7d856af0310c6396830ae3519b7fc3c23ea8b1bbf7b51fda18407ff29
BLAKE2b-256 checksum
How to use checksums
b95e8fddaff0cc90a3cdb80061f231cfaf9937cba764aa765a3b66b68ab38b9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / polars_readstat-0.27.1-cp39-abi3-macosx_10_15_x86_64.whl

Download URL polars_readstat-0.27.1-cp39-abi3-macosx_10_15_x86_64.whl
Size 23.2 MB
Tags CPython 3.9 abi3 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
b03266a3ddf6b5044659f7513c771d92d4ada72dbcb4f5574fc4eb96d3b5f9a1
BLAKE2b-256 checksum
How to use checksums
3f2aa901532c96282e36090a00c5416091b21025892e50c6958fb8db04da8456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for polars-readstat 0.27.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.27.1 This release

7 release files No provenance

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