Skip to main content

SAS/SPSS/Stata I/O with Polars, powered by ReadStat + PyO3

Project description

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

Project details


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.0.tar.gz (69.9 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.0-cp311-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11+Windows x86-64

svy_io-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl (1.3 MB view details)

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

svy_io-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

svy_io-0.1.0-cp311-abi3-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for svy_io-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2c1986eeb32e2de2e820b2f899c5cbec12e437b54d9f454ed4c3abed7d36a1af
MD5 5532e1171674c2df459a00bbddc14108
BLAKE2b-256 dc85dca7723948b82339caea55a07cf50f0f2ae00d8ff2ce34a5e860721f92e2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for svy_io-0.1.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 124550398b7a3c3ede8d9a2b70bbd31de1aa7fe222c0ae4b5ae72f94272d8185
MD5 e30a9c049fbae9e89146abd052b98b59
BLAKE2b-256 90b9b490eab8d3018874abb8c915487cb2d45ccf0c6d82a132385b23db58561c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for svy_io-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 40c7d2eb515d006366bf9c572b169440743f55e03a2fd3e3756008d98b90ffcc
MD5 ecfc5e77881160b9d0777271238fc616
BLAKE2b-256 6c8b66a6959423012288dd6647a22942ff58133dafbf9f0824645b4149c652f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for svy_io-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9555b57ffc7a39c400da91030bdea49b90c67b6152bbd66f287681b19099fa15
MD5 f84d4bff0cf8d120af67b070326b50f8
BLAKE2b-256 503ca2576f3810a2f01b43e09e857c7670ef48e65df4b2e114798b2e16b5f76b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for svy_io-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 568c48458c0d36ca6d982dbf0cbbb005a7ed7dd87962e21a9581935d0f32682e
MD5 2fd9e7f0cd9c13c777706bf5357e644e
BLAKE2b-256 0966ad0762db3a0629b70d5d755f9ad741c8c2eb0046ec27e8f08b65a15c1336

See more details on using hashes here.

Supported by

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