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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

svy_io-0.1.1.tar.gz (298.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

svy_io-0.1.1-cp311-abi3-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11+Windows x86-64

svy_io-0.1.1-cp311-abi3-manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

svy_io-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

svy_io-0.1.1-cp311-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

svy_io-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file svy_io-0.1.1.tar.gz.

File metadata

  • Download URL: svy_io-0.1.1.tar.gz
  • Upload date:
  • Size: 298.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for svy_io-0.1.1.tar.gz
Algorithm Hash digest
SHA256 24a396c6019b3dfb34299e0f9336c623fc10e7f551514919e8ff8e49e4947df5
MD5 189fb5586e646eeeb26b604933ea06c6
BLAKE2b-256 6e679e9be379054f871015a242625f6c683a9314f9b88f2dd1ae5223b4a5fe51

See more details on using hashes here.

File details

Details for the file svy_io-0.1.1-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: svy_io-0.1.1-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for svy_io-0.1.1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cef5d80e619bb06777106f5b582b2cfa93a924cc734b906f054534d5be39a7c2
MD5 a57bc3ed28416fa94e63139343086b89
BLAKE2b-256 6b35c92b1fa3e0fcbc8f16c8885a004cc412ec1d23cbb75591c65f97a6caffd2

See more details on using hashes here.

File details

Details for the file svy_io-0.1.1-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for svy_io-0.1.1-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 051449e52f0215120715c25f430817b90335d4036c335b07463fd9972b2353e2
MD5 75ecc36cef7beee90e1f49964c9c594a
BLAKE2b-256 f8ce3c4c1f3f629be5c49694f64da622d83023acabe4fd2de9bfead9eb5d44e8

See more details on using hashes here.

File details

Details for the file svy_io-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for svy_io-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9e76d37de8cf2019fe15effde37bd772512cc0c89de76bd4f41f866ae8ea3a7a
MD5 12c2b6fb28dd29c94c82a1c08193a7af
BLAKE2b-256 f3c1577c070655b1e94662eabd6928bf7b6f4d371ab66cfc4ba12a82c4f3fe50

See more details on using hashes here.

File details

Details for the file svy_io-0.1.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for svy_io-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97945d6eb9049d2192bd9c7eae5cec4ff8cee33ce60ec6f905c48db8c6d8dd2c
MD5 f95c359041327048dfd1b4cf101827d2
BLAKE2b-256 53aac627cf652b6dbd09031daa890b8188a4d20c90ba2fe2ad55f95740e1dda4

See more details on using hashes here.

File details

Details for the file svy_io-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for svy_io-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f179d01e7dcf2e605f4e375a4765c86604be0c94d5141ff781c5b725d23adda5
MD5 0b16d4f9552721b7c52fbecf4703252c
BLAKE2b-256 cd369da6055be14fdb4a544db49296353d830aa8b1c50752d629c881473d7e01

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

6 files

This release

0.1.1 This release

6 files

0.1.0

5 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page