Skip to main content

sas7bdat-polars

Read SAS7BDAT files into Polars, using the sas7bdat Rust reader. Batches reach Python as Arrow C streams, so pyarrow, pandas and DuckDB can read them too.

pip install sas7bdat-polars           # needs Python 3.12+ and polars 1.41.1+
pip install "sas7bdat-polars[cli]"    # also the `sas7bdat` command-line tool

Wheels are built for Linux (x86-64 and ARM64), Windows (x86-64) and macOS (Apple Silicon). On x86-64 they need a CPU with AVX2: Intel Haswell (2013) or AMD Excavator (2015) and later.

Usage

import polars as pl
import sas7bdat_polars as sp

# Eager read. Name the columns you need: SAS7BDAT stores rows, so projection
# is the largest saving on wide files.
df = sp.read_sas("data.sas7bdat", columns=["id", "age"])
df = sp.read_sas("data.sas7bdat", columns=["age"], n_rows=1_000_000)
df = sp.read_sas("data.sas7bdat", row_offset=1_000_000, n_rows=1_000_000)  # rows 1M to 2M

# Lazy scan. Projection and a row limit reach the decoder; filters run per batch.
lf = sp.scan_sas("data.sas7bdat", columns=["id", "age"])
df = lf.filter(pl.col("age") > 30).collect()

# Metadata and schema without decoding rows: counts, encoding, table name, and
# each column's label and SAS format.
info = sp.sas_info("data.sas7bdat")
columns = sp.column_info("data.sas7bdat")   # name, label, format, type, width
schema = sp.schema_for_file("data.sas7bdat")

# Value labels from a companion catalog: labelled columns come back as labels,
# or as their codes with apply_labels=False; value_labels gives the mapping.
lf = sp.scan_sas("data.sas7bdat", catalog_path="formats.sas7bcat")
codes = sp.SasDataset("data.sas7bdat", "formats.sas7bcat", apply_labels=False).read()
labels = sp.value_labels("data.sas7bdat", "formats.sas7bcat")  # {column: {code: label}}

# A header that names the wrong encoding, and failing on bytes that do not decode.
df = sp.read_sas("data.sas7bdat", encoding="utf-8", strict=True)

# Several files with the same columns, by list or pattern, with each row's file.
df = sp.read_sas("lmdb_*.sas7bdat", include_file_paths="source")

# SAS special missing values (.A to .Z, ._): a Q1_missing column with each tag.
df = sp.read_sas("survey.sas7bdat", missing_tags=["Q1", "Q2"])

# Dates, datetimes and times as SAS's numbers (days or seconds from 1960-01-01).
df = sp.read_sas("data.sas7bdat", temporal_as_numbers=True)

# SAS stores every number as a float. Declare integer-coded columns to get Int64.
lf = sp.scan_sas("data.sas7bdat", schema_overrides={"region": pl.Int64})

# Return string columns as Categorical, for codes and labels.
lf = sp.scan_sas("data.sas7bdat", categorical=["diagnosis"])

Without polars:

import pyarrow as pa

table = pa.table(sp.SasDataset("data.sas7bdat"))

Behaviour worth knowing

  • Deleted rows are excluded. SAS marks a deleted row instead of removing it. This reader drops those rows. The ReadStat 1.1.9 release that pyreadstat ships returns them, so on such files pyreadstat reports more rows.
  • Schema overrides fail loudly. A value that does not fit an Int64 override, such as 2.5, stops the scan with an error naming the column, row and value. Override names missing from a file are ignored, so one map can be used for a whole set of files. Supported types: Int64, Float64, Date, Datetime, Time, String, Binary.
  • Categorical columns are dictionary-encoded by the reader. They suit codes and labels, not identifiers, where the dictionary is as large as the data.
  • Threads. The reader decodes on all cores. Set a limit with sp.set_scan_threads(n) or SAS7BDAT_SCAN_THREADS. POLARS_MAX_THREADS does not affect the decoder.
  • Memory. By default a local file is memory-mapped. On files much larger than the result, io_backend="buffered" keeps memory bounded, at some cost to small reads. SAS7BDAT_IO_BACKEND sets the default.

Licence

MIT. See the repository.

Metadata

Release files for sas7bdat-polars 0.10.3

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 sas7bdat-polars 0.10.3
File Actions
sas7bdat_polars-0.10.3-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for sas7bdat_polars-0.10.3-cp312-abi3-win_amd64.whl
sas7bdat_polars-0.10.3-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details for sas7bdat_polars-0.10.3-cp312-abi3-manylinux_2_28_x86_64.whl
sas7bdat_polars-0.10.3-cp312-abi3-manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64 Details for sas7bdat_polars-0.10.3-cp312-abi3-manylinux_2_28_aarch64.whl
sas7bdat_polars-0.10.3-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for sas7bdat_polars-0.10.3-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 3.2 MB

Release files / sas7bdat_polars-0.10.3-cp312-abi3-win_amd64.whl

Download URL sas7bdat_polars-0.10.3-cp312-abi3-win_amd64.whl
Size 789.3 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8b945f570588308f78581419f7a21dc42b646c8c14b0f9696ada3140edd2d501
BLAKE2b-256 checksum
How to use checksums
0f094dde94e489ff6ab4f2123751df88599536fe57965d5ce89aafc0aa09f1a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sas7bdat_polars-0.10.3-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL sas7bdat_polars-0.10.3-cp312-abi3-manylinux_2_28_x86_64.whl
Size 850.6 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
bef0d9b7f078d74476e753df1688ed076e3c8661696a03569583ca0b5fd17d24
BLAKE2b-256 checksum
How to use checksums
0565462f0baf6ccc6fefd548b2c60eaae2a15b2b6d4b20f56f8c13c12fa5a8e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sas7bdat_polars-0.10.3-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL sas7bdat_polars-0.10.3-cp312-abi3-manylinux_2_28_aarch64.whl
Size 800.1 kB
Tags CPython 3.12 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
e26c1e767edeb1c3146f542f64168d8bffbf30e66e279f4877933abc568df455
BLAKE2b-256 checksum
How to use checksums
77804528981b5e0a476d0bc06ccf2dc126c6063d3c762f7b7e26325b26f0e170
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sas7bdat_polars-0.10.3-cp312-abi3-macosx_11_0_arm64.whl

Download URL sas7bdat_polars-0.10.3-cp312-abi3-macosx_11_0_arm64.whl
Size 762.0 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a80a82fb41c796832cd1cff8df447e4758d752b77062bcd9ffdebd57dfd81208
BLAKE2b-256 checksum
How to use checksums
2c2119c1f774640dc227fdc98f4abfb11fa4e9ae14ebf54a7c555c5d1c71827a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for sas7bdat-polars 0.10.3

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.

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