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.2.0.tar.gz (299.3 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.2.0-cp311-abi3-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11+Windows x86-64

svy_io-0.2.0-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.2.0-cp311-abi3-manylinux_2_28_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.11+macOS 11.0+ ARM64

svy_io-0.2.0-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.2.0.tar.gz.

File metadata

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

File hashes

Hashes for svy_io-0.2.0.tar.gz
Algorithm Hash digest
SHA256 828092e5c38cb9acad197c7fc1bc8017fdc08471b409c37e76ecd4f2c1f6c423
MD5 db7fb60e3fc0c88da14d94923d8cdb2e
BLAKE2b-256 a277e955428c88e0aa0f36b1fccae563c5e4991dede8670bef4bbd026f4cfda9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: svy_io-0.2.0-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.5 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.2.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e7363b9832051f2740cb7309ff6af28a09170675dcf583030627c8d604b6e3a4
MD5 07f8ea29c9104b2a80de2187f7768407
BLAKE2b-256 12b72c8e8ba7594679185f7dc50f80f03c08649f48ebf0d64c3512c30485e249

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for svy_io-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5aae3976e8a64307847d1003af3a555db3df1aff592e39a87f271fc6491927b4
MD5 4717b8d5836a710a1021d5c8c940bc5b
BLAKE2b-256 94209b3b5f844e1e40b62edf658fa70fcc1631b63a861bb0f80bf8d0dbecbb51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for svy_io-0.2.0-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 445cce235b152a967884961c47b5e24a4e402a55158f546e8292dd9ab14fc283
MD5 2dfd8fbfc5eb1cc1af46248f6197b674
BLAKE2b-256 ccee9dea7cfa8b2ad05a0fb64dafa1aaac7017981be7481f5c4dd0e713536067

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for svy_io-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 930c203231b4b3bfc802003f922bcaeaf9a186fc38fe700d4296ff73b4962db3
MD5 2c4cae2f71d2c3c57d680591268cb420
BLAKE2b-256 8a8a2901b6c99d695bacbfeadedfebd8cb639ddfda8112e0426dbf8d8a797324

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for svy_io-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8d8572799f4594464129a18b1856e6482cc1ebdeb08c059860c00d439157f2ac
MD5 3b0011f1818a4af5846294bfc218dda3
BLAKE2b-256 b4cedc0eb95b0100d703ce7f37d362e9e2c2d35e9366ce01fbed327a016bdf94

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

6 files

0.1.1

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