svy-io
Lightweight, Pythonic file I/O for SAS, SPSS, and Stata powered by the ReadStat C library. Returns Polars DataFrames and preserves useful metadata — with a tiny, consistent API.
Installation
pip install svy-io
Requires: Python, Polars, and pyarrow (installed automatically as a dependency).
What you get
- SAS: read
.sas7bdatand.xpt; write.xpt - SPSS: read
.sav,.zsav,.por; write.sav(incl..zsavviacompress="zsav") - Stata: read & write
.dta(v8–15) - Polars-first: fast DataFrames; each
read_*returns(df, meta)
Usage
Below are the only things you need: read_* and write_*.
SAS
# Read
from svy_io.sas import read_sas, read_xpt
df, meta = read_sas("data.sas7bdat") # optional: catalog_path="formats.sas7bcat"
df_xpt, meta_xpt = read_xpt("transport.xpt")
# Write (XPT v8 recommended)
from svy_io.sas import write_xpt
import polars as pl
df_out = pl.DataFrame({"id": [1, 2, 3], "score": [10.5, 9.3, 8.8]})
write_xpt(df_out, "output.xpt", version=8, label="Study Data")
SPSS
# Read
from svy_io.spss import read_sav, read_por, read_spss
df_sav, meta_sav = read_sav("survey.sav") # .zsav handled automatically
df_por, meta_por = read_por("legacy.por")
df_auto, meta_auto = read_spss("data.sav") # auto by extension
# Write
from svy_io.spss import write_sav
import polars as pl
df = pl.DataFrame({"subject_id": [1, 2, 3], "age": [25, 30, 35], "gender": [1, 2, 1]})
write_sav(
df,
"out.sav", # or "out.zsav" with compress="zsav"
compress="byte",
var_labels={"age": "Age (years)", "gender": "Gender"},
value_labels=[{"col": "gender", "labels": {"1": "Male", "2": "Female"}}],
user_missing=[{"col": "age", "values": [-99]}]
)
Stata
# Read
from svy_io.stata import read_dta
df, meta = read_dta("data.dta")
# Write
from svy_io.stata import write_dta
import polars as pl
df_out = pl.DataFrame({"id": [1, 2, 3], "income": [50000, 62000, 58000]})
write_dta(
df_out,
"output.dta",
version=15, # 8–15 supported
file_label="Survey Data 2024",
var_labels={"income": "Annual income (USD)"}
)
Notes & tips
- All readers return a tuple:
(df: polars.DataFrame, meta: dict). - If you work with dates, many
read_*functions supportcoerce_temporals=True. - For large files, consider
cols_skip=[...]and/orn_max=...while exploring. - Stata limits strings to 2045 bytes; SAS XPT v5 has stricter name/length limits — prefer XPT v8 unless you need legacy compatibility.
Help & links
- Source & issues: https://github.com/samplics-org/svy-io
- ReadStat (upstream): https://github.com/WizardMac/ReadStat
- Polars docs: https://pola-rs.github.io/polars/
Metadata
Release files for svy-io 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| svy_io-0.3.0.tar.gz | 301.5 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| svy_io-0.3.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| svy_io-0.3.0-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| svy_io-0.3.0-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| svy_io-0.3.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| svy_io-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 7.8 MB
Release files / svy_io-0.3.0.tar.gz
| Download URL | svy_io-0.3.0.tar.gz |
|---|---|
| Size | 301.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e38467ac717c9f605e78850151d0d3d2e182e07e7e5cff8dd21c43a78f7ee1d5
|
|
BLAKE2b-256 checksum How to use checksums |
ae338a70aeef99cdb8181d0f133b8a4540580f748ca93e3bbb44bbafcd5b3ec0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / svy_io-0.3.0-cp311-abi3-win_amd64.whl
| Download URL | svy_io-0.3.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
efe823021b8ecd77d809481e2b78e071d3cef622d879939f10dca442921f52a8
|
|
BLAKE2b-256 checksum How to use checksums |
36c66e72278b0273308c89c34dfb920335ab60a4ca5c816362e9cf24e83a18d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / svy_io-0.3.0-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | svy_io-0.3.0-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
05c03ac9cfa1ac1bce4e17294af9b1581f7b0dec152d350c791bec0f1f83f52e
|
|
BLAKE2b-256 checksum How to use checksums |
1caadb16af4d503bdb784e1af6b48829b57f7bf26e818fa4a0f3b4c1f35a33a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / svy_io-0.3.0-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | svy_io-0.3.0-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
93e68a31f8720a5f7b36a724d011ed89b7994ae51dc59df0740858a1dbb8c58d
|
|
BLAKE2b-256 checksum How to use checksums |
71c3b76f2e9c49578dd49bf6a23efcf4d22d049de7773e6381eae704056522ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / svy_io-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | svy_io-0.3.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9f199dbdcbc29cb8310fcbe51eb5ddbd378a622d14e97141915439404fd2c1bf
|
|
BLAKE2b-256 checksum How to use checksums |
a9be2f149ec22e8dbdde9d88466ce00eacab7acb70c426014721055a8bd92675
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / svy_io-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | svy_io-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
dd3f5545bcd264e918ac5f9fc9d7b534a0dcec627b179e8475fb203004ca745c
|
|
BLAKE2b-256 checksum How to use checksums |
48ebf07a73a0ebacfd27f58f79e2e8fef15606c7400306c55de674a2b6dcdeb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|