Skip to main content

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 .sas7bdat and .xpt; write .xpt
  • SPSS: read .sav, .zsav, .por; write .sav (incl. .zsav via compress="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 support coerce_temporals=True.
  • For large files, consider cols_skip=[...] and/or n_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

Metadata

Release files for svy-io 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for svy-io 0.4.0
File Size Uploaded
svy_io-0.4.0.tar.gz 305.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for svy-io 0.4.0
File
svy_io-0.4.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
svy_io-0.4.0-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details
svy_io-0.4.0-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details
svy_io-0.4.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
svy_io-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 7.9 MB

Release files / svy_io-0.4.0.tar.gz

Download URL svy_io-0.4.0.tar.gz
Size 305.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d83acef88cf1d7d1c1bc0b12c3669f7ac769866625b3ce75ec899ce3c04b5ab7
BLAKE2b-256 checksum
How to use checksums
5ecb2d10922588825a2ca125c57419120f5cf3f053e9c51658c521da62288dc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / svy_io-0.4.0-cp311-abi3-win_amd64.whl

Download URL svy_io-0.4.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
0990d5368ae593f7f8897bc3483d79cd2554a53000476f37fd219b10e7586e99
BLAKE2b-256 checksum
How to use checksums
b70ad456f9a25276f51f34898c4fe204a4abd1d7e7e0a91695b83fe7903174be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / svy_io-0.4.0-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL svy_io-0.4.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
2d900d39fd32fa8159b298818ea8116a4ac01f0383e60e8ca0701c08b723b3c9
BLAKE2b-256 checksum
How to use checksums
f8a256118e3e09f0444084c88f9c8356ec017822dbf652291b516711e533b943
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / svy_io-0.4.0-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL svy_io-0.4.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
8ecd40f32433b41fc9e227d3344dabc356a09ce0d1f6cc3eccc68ea800d7fca8
BLAKE2b-256 checksum
How to use checksums
eb6e8e96643e2479cd736ff63dfe696f358f6e6dd61785186f838a978d23b48e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / svy_io-0.4.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL svy_io-0.4.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
b65e3f961303ee5970838a0f6e4b3885ccab6581383ededb2be39f4623c41104
BLAKE2b-256 checksum
How to use checksums
8e4ba9cf1f59eb05b0a64a2e305f5a98c8f39355b0bf760b80963d256cb20715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / svy_io-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL svy_io-0.4.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
923da986065ff37ed564e998e7bd1ae36fd11470e8a6a4345d907e5c01d83391
BLAKE2b-256 checksum
How to use checksums
adff058896a0b8ed296f532e4abd558d24d71d8753e64eca8903de2df23a8cbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0
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