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+
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.2

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

Total release size: 3.2 MB

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

Download URL sas7bdat_polars-0.10.2-cp312-abi3-win_amd64.whl
Size 789.3 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b78370cfd0c7055aae9cb0201e3d7e73615667d3baafd04f8b56024429719f97
BLAKE2b-256 checksum
How to use checksums
25f319c9065bbeaa3b54735f700fbf747c80e8380dd1f19aa47c78e323f13e03
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":"24.04","id":"noble","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.2-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL sas7bdat_polars-0.10.2-cp312-abi3-manylinux_2_28_x86_64.whl
Size 851.0 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
12db6200f7be3e82d8d1da8ec8afced1c5b823998c2fcd22960f6bb051099920
BLAKE2b-256 checksum
How to use checksums
281c03b2e30ceb68158be0ffba6933a227e6a2ea1513566383d26967ec855986
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":"24.04","id":"noble","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.2-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL sas7bdat_polars-0.10.2-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
c42d748b8db6adf6db098d11f5e3b95927b40921dae161e3ca47b419a2822ff8
BLAKE2b-256 checksum
How to use checksums
0fcec051c2642e2d051852daf20385683afc159740fb19b792d51664afc75f6e
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":"24.04","id":"noble","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.2-cp312-abi3-macosx_11_0_arm64.whl

Download URL sas7bdat_polars-0.10.2-cp312-abi3-macosx_11_0_arm64.whl
Size 761.6 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5a0924187c27c2b1e0f0eeb9a79bde32dcbf1336f02fdfc1385252a1f433e99b
BLAKE2b-256 checksum
How to use checksums
2121dc7141d388c108c6e3159e80509c383bb5bbcd50cdcc8073d9a026511e83
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":"24.04","id":"noble","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.2

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