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
Int64override, 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)orSAS7BDAT_SCAN_THREADS.POLARS_MAX_THREADSdoes 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_BACKENDsets the default.
Licence
MIT. See the repository.
Metadata
Release files for sas7bdat-polars 0.10.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| sas7bdat_polars-0.10.4-cp312-abi3-win_amd64.whl | CPython 3.12 | abi3 | Windows x86-64 | Details for sas7bdat_polars-0.10.4-cp312-abi3-win_amd64.whl |
| sas7bdat_polars-0.10.4-cp312-abi3-manylinux_2_28_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ x86-64 | Details for sas7bdat_polars-0.10.4-cp312-abi3-manylinux_2_28_x86_64.whl |
| sas7bdat_polars-0.10.4-cp312-abi3-manylinux_2_28_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ ARM64 | Details for sas7bdat_polars-0.10.4-cp312-abi3-manylinux_2_28_aarch64.whl |
| sas7bdat_polars-0.10.4-cp312-abi3-macosx_11_0_arm64.whl | CPython 3.12 | abi3 | macOS 11.0+ ARM64 | Details for sas7bdat_polars-0.10.4-cp312-abi3-macosx_11_0_arm64.whl |
Total release size: 3.2 MB
Release files / sas7bdat_polars-0.10.4-cp312-abi3-win_amd64.whl
| Download URL | sas7bdat_polars-0.10.4-cp312-abi3-win_amd64.whl |
|---|---|
| Size | 790.0 kB |
| Tags | CPython 3.12 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
5e462ba25dd95ebacfadf1fbaa57019aca0fd1b0ad4c80cdfa63b5cc08b46113
|
|
BLAKE2b-256 checksum How to use checksums |
a6237f6889d1e064fb89b10f5515014bb5edd11520204066fa9c792b78ead56c
|
| 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.4-cp312-abi3-manylinux_2_28_x86_64.whl
| Download URL | sas7bdat_polars-0.10.4-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 |
80c677f83d032f955a9aa7d53320c41ff2e7c523ba8d4160c98a35fa6eeddef8
|
|
BLAKE2b-256 checksum How to use checksums |
8dc10fc4ebe813efba55fd8b9094c389a6d2cbb0a51de65bba44db77b3717744
|
| 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.4-cp312-abi3-manylinux_2_28_aarch64.whl
| Download URL | sas7bdat_polars-0.10.4-cp312-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 800.3 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
fb48a444082fd068658fbb6763c347933b660422a770cf472f85e99bdcaecad2
|
|
BLAKE2b-256 checksum How to use checksums |
9a7e2d35af9dbbebb17f6dc6e86369b9616783e79eb04648dd299ec36f3fe191
|
| 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.4-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | sas7bdat_polars-0.10.4-cp312-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 761.5 kB |
| Tags | CPython 3.12 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b1d809520c33a07b189c941e56d6fb3c552f198dd124a29d05bdce0fbec05bbc
|
|
BLAKE2b-256 checksum How to use checksums |
f039f846b7f7656de340a8a81a251c2ff02fe4896ddf5085de22497ce9bd6a3f
|
| 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.4
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.