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.5

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

Total release size: 3.2 MB

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

Download URL sas7bdat_polars-0.10.5-cp312-abi3-win_amd64.whl
Size 789.7 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
798c7dbddab5bdf5d2ad338c26c9c3b1b592010754b5ef10c2ef6cc67953709b
BLAKE2b-256 checksum
How to use checksums
efd5a34c33b1521c2b4bcf86bc7b2de0cd16e7f02f437bafc2d565a4804ac51d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","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.5-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL sas7bdat_polars-0.10.5-cp312-abi3-manylinux_2_28_x86_64.whl
Size 850.8 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
adbbb0769bced6fc9c7f0c5cc78fa3108db97db673380bc619a5ee2a322ebb13
BLAKE2b-256 checksum
How to use checksums
f7f1b9fffe463066e9871565bad38735d35d33dc76951392317aa2eb5c9f5e44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","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.5-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL sas7bdat_polars-0.10.5-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
061094675bbad353f3ee2bb866083208f7e0bee13af6020a6a26212aeba991f0
BLAKE2b-256 checksum
How to use checksums
8af40a564e745cdb14a7f71869a912a43739d4418284318499b4547b7813a96a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","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.5-cp312-abi3-macosx_11_0_arm64.whl

Download URL sas7bdat_polars-0.10.5-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
91d8d23bd098e718ca4bf3f18a1568f311727bd96dda8b66bc98144a75132840
BLAKE2b-256 checksum
How to use checksums
f40b6364a08a21ea31b39af218d850b2686044d7a3f969e6f418d2dc09e9ddb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","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.5

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