Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Overview

pyspssio is a python package for reading and writing SPSS (.sav and .zsav) files to/from pandas dataframes.

This package uses the I/O Module for SPSS Statistics v29 available at https://www.ibm.com/.

WARNING: This is an early release with limited testing. Use with caution.

pyspssio

SPSS I/O Modules

Motivation

Main reason for creating this package is to fill gaps by other similar packages.

savReaderWriter

  • doesn't support python > 3.5
  • not particularly user friendly

pyreadstat

pyspssio supports recent versions of python and can read/write most SPSS file metadata properties. The usecols argument when reading files also accepts a callable for more flexible variable selection.

Installation

Install from PyPI:

python -m pip install pyspssio

Supported platforms currently include:

  • Windows 64-bit (win_amd64)
  • Linux x86_64 (manylinux, x86_64)
  • macOS (macosx, x86_64)

Note: On Apple Silicon (ARM), use an x86_64 Python installation under Rosetta 2.

Source distribution

As of v0.6.0, the source distribution does not include the native SPSS I/O libraries. Installing from the source distribution requires separately obtaining and configuring the appropriate SPSS I/O modules. These are available in the above IBM links or GitHub.

Configure the I/O module before using.

import pyspssio

pyspssio.config.spssio_module

Basic Usage

Import

import pyspssio

Reading

Read data and metadata

df, meta = pyspssio.read_sav("spss_file.sav")

Read metadata only

meta = pyspssio.read_metadata("spss_file.sav")

Read data in chunks of chunksize (number of rows/records)

for df in pyspssio.read_sav("spss_file.sav", chunksize=1000):
#   do something

Note: metadata is not returned when reading in chunks

Writing

Write dataframe to file.

pyspssio.write_sav("spss_file.sav", df)

Appending

Append existing SPSS file with new records.

pyspssio.write_sav("spss_file.sav", df)

Note: Cannot modify metadata when appending new records. Be careful with strings that might be longer than the already defined width as they may be automatically truncated without warning.

Other Notes

Date/Time Variables

Date and datetime variables - These are converted to/from full datetime objects, even for formats like DATE, QYR, and WKYR which don't display a time component. Users can opt to use Pandas' .dt accessor to extract specific components or force a specific accuracy (e.g., minute, day, hour) after reading the data (ex. .dt.floor). The var_formats and/or var_formats_tuple metadata attributes can be used to see the original SPSS formats.

Time variables - These are converted to/from timestamp objects.

Python/Pandas stores datetimes in nanseconds while SPSS stores them in seconds. Due to conversions that must take place, there may be some small (ms) discrepancies between an original dataframe used to write an SPSS file and a dataframe read back from the same SPSS file.

I/O Module Procedures

List of available I/O module procedures and class for which they fall under. See official documentation for details on each one.

Some of these procedures are implemented as hidden methods referenced within a more generalized function/property. For example, instead of calling spssSetVarLabel manually for each variable, users should assign all variable labels at once by setting self.var_labels = {var1: label1, var2: label2, ...}.

All I/O module procedures can be accessed directly with self.spssio.[procedure].

SPSSFile

spssOpenRead

spssCloseRead

spssOpenWrite

spssCloseWrite

spssOpenAppend

spssCloseAppend

spssHostSysmisVal

spssLowHighVal

spssSetLocale

spssGetInterfaceEncoding

spssSetInterfaceEncoding

spssGetFileEncoding

spssIsCompatibleEncoding

spssGetCompression

spssSetCompression

spssGetReleaseInfo

spssGetNumberofCases

spssGetNumberofVariables

Header

spssGetFileAttributes

spssSetFileAttributes

spssGetVarNames

spssSetVarName

spssGetVarHandle

spssGetVarPrintFormat

spssSetVarPrintFormat

spssSetVarWriteFormat

spssGetVarMeasureLevel

spssSetVarMeasureLevel

spssGetVarAlignment

spssSetVarAlignment

spssGetVarColumnWidth

spssSetVarColumnWidth

spssGetVarLabelLong

spssSetVarLabel

spssGetVarRole

spssSetVarRole

spssGetVarCValueLabels

spssSetVarCValueLabel

spssGetVarNValueLabels

spssSetVarNValueLabel

spssGetVarCMissingValues

spssSetVarCMissingValues

spssGetVarNMissingValues

spssSetVarNMissingValues

spssGetMultRespCount

spssGetMultRespDefs

spssGetMultRespDefsEx - replaces spssGetMultRespDefs

spssSetMultRespDefs

spssAddMultRespDefExt

spssGetCaseSize

spssGetCaseWeightVar

spssSetCaseWeightVar

spssGetVarAttributes

spssSetVarAttributes

spssGetVarCompatName

spssGetVariableSets

spssSetVariableSets

spssCommitHeader

Reader

spssSeekNextCase

spssWholeCaseIn

Writer

spssWholeCaseOut

spssSetValueChar

spssSetValueNumeric

spssCommitCaseRecord

Not Implemented (yet)

spssAddMultRespDefC

spssAddMultRespDefN

spssGetMultRespDefByIndex

spssConvertDate - manual conversion instead

spssConvertSPSSDate - manual conversion instead

spssConvertSPSSTime - manual conversion instead

spssConvertTime - manual conversion instead

spssCopyDocuments

spssGetDEWFirst

spssGetDEWGUID

spssGetDewInfo

spssGetDEWNext

spssSetDEWFirst

spssSetDEWGUID

spssSetDEWNext

spssGetDateVariables

spssGetEstimatedNofCases

spssGetFileAttribute - uses spssGetFileAttributes instead

spssGetFileCodePage

spssGetIdString

spssGetSystemString

spssGetTextInfo

spssGetTimeStamp

spssGetValueChar - uses spssWholeCaseIn instead

spssGetValueNumeric - uses spssWholeCaseIn instead

spssAddVarAttribute - uses spssSetVarAttributes instead

spssGetVarCValueLabel - uses spssGetVarCValueLabels instead

spssGetVarCValueLabelLong - uses spssGetVarCValueLabels instead

spssGetVarInfo

spssGetVarLabel - uses spssGetVarLabelLong instead

spssGetVarNValueLabel - uses spssGetVarNValueLabels instead

spssGetVarNValueLabelLong - uses spssGetVarNValueLabels instead

spssGetVarWriteFormat - uses spssGetVarPrintFormat instead (print/write formats tied together)

spssOpenAppendEx

spssOpenReadEx

spssOpenWriteCopy

spssOpenWriteCopyEx

spssOpenWriteCopyExDict

spssOpenWriteCopyExFile

spssOpenWriteEx

spssQueryType7

spssReadCaseRecord - uses spssWholeCaseIn instead

spssSetDateVariables

spssSetIdString

spssSetTempDir

spssSetTextInfo

spssSetVarCValueLabels - uses spssSetVarCValueLabel instead

spssSetVarNValueLabels - uses spssSetVarNValueLabel instead

spssSysmisVal - uses spssHostSysmisVal instead

spssValidateVarname

Metadata

Release files for pyspssio 0.6.0b3

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

Source distribution (sdist)

Source distribution for pyspssio 0.6.0b3
File Size Uploaded
pyspssio-0.6.0b3.tar.gz 59.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyspssio 0.6.0b3
File
pyspssio-0.6.0b3-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
pyspssio-0.6.0b3-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details
pyspssio-0.6.0b3-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
pyspssio-0.6.0b3-py3-none-macosx_10_15_x86_64.whl Python 3 none macOS 10.15+ x86-64 Details

Total release size: 90.5 MB

Release files / pyspssio-0.6.0b3.tar.gz

Download URL pyspssio-0.6.0b3.tar.gz
Size 59.8 kB
Tags Source
SHA-256 checksum
How to use checksums
132e3379eaa8f1f0c45f390b420d80579c22c1b645f3286e5c9dc0b8d2f1831c
BLAKE2b-256 checksum
How to use checksums
9442e9906630290cd79592d5cf125f8dee8123ccd4c4cb5649a684c8c3160430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyspssio-0.6.0b3-py3-none-win_amd64.whl

Download URL pyspssio-0.6.0b3-py3-none-win_amd64.whl
Size 17.8 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
76ad4b3f5b5d8b11355b274490502e739c86fc3ead429cb3e3e19f2faffac0be
BLAKE2b-256 checksum
How to use checksums
e253bc2ebeab96b8596a4f423b7e49f8bfedd9f67f3e067b0faca481728914cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyspssio-0.6.0b3-py3-none-musllinux_1_2_x86_64.whl

Download URL pyspssio-0.6.0b3-py3-none-musllinux_1_2_x86_64.whl
Size 28.6 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
89c18b2274981152291fb7480624c047464953a578e5e30350cdc83275f8a6e1
BLAKE2b-256 checksum
How to use checksums
54e2c1bea0acf2688fac44338f207df40344325a6d5b82be3886dcb9b586e9d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyspssio-0.6.0b3-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL pyspssio-0.6.0b3-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 28.6 MB
Tags Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
7ed06b1e28864ea2f471f44277b5cbaae88a44883456cf558e2c6a01d434e68f
BLAKE2b-256 checksum
How to use checksums
db497fa9b69a90dc69f7dcdb99d656724294822e3a88d8446cb4111f46f11633
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyspssio-0.6.0b3-py3-none-macosx_10_15_x86_64.whl

Download URL pyspssio-0.6.0b3-py3-none-macosx_10_15_x86_64.whl
Size 15.5 MB
Tags Python 3 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
42cd7d4711560bf415025edbad8bc94840cc02f504153fba20bc40dc84c8c0a8
BLAKE2b-256 checksum
How to use checksums
be11d059ee97de921d2a475de7366d052df02584fdba47941bf8fd2c7f4c2e4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.6.0

4 release files

This release

0.6.0b3 This release

5 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

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