Skip to main content

print and extract spss metadata

Project description

SPSS Metadata Printer ๐Ÿ“Š

Easy-to-use Python package for extracting, viewing, and exporting metadata from SPSS files with beautiful formatting.

โœจ Features

  • ๐Ÿ“‹ Pretty-print comprehensive SPSS metadata to console
  • ๐Ÿ’พ Export metadata summaries to text files automatically saved to Downloads
  • ๐Ÿ“„ Extract metadata dictionary to JSON for programmatic access and archival
  • ๐Ÿ“Š Detailed variable information including labels, types, and value mappings
  • ๐ŸŽจ Beautiful table formatting with configurable width and display options

๐Ÿš€ Quick Start

Installation

pip install metaprinter

Or using uv:

uv add metaprinter

Basic Usage

import pyreadstat
from metaprinter import print_metadata, export_metadata, extract_metadict

# Load your SPSS file
df, meta = pyreadstat.read_sav('data.sav')

# Display beautiful metadata summary inside a notebook
print_summary = print_metadata(df, meta)

# Export to Downloads/metadata_summary.txt
export_summary = export_metadata(df, meta)

# Extract metadata to JSON (Downloads/meta_dictionary.json)
extract_metadict(meta)

Output Preview:

============================================================
SPSS FILE METADATA
============================================================
File encoding   : 'UTF-8'
Number of cols  : 25
Number of rows  : 100
Table name      : 'Table'
File label      : 'Customer Satisfaction Survey'
Notes           : 'Notes'

VARIABLE METADATA
============================================================
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ column        โ”† dtype   โ”† column_n โ”† n_uniques โ”† n_categories โ”† column_label        โ”† value_labels        โ”‚
โ”‚ ---           โ”† ---     โ”† ---      โ”† ---       โ”† ---          โ”† ---                 โ”† ---                 โ”‚
โ”‚ str           โ”† str     โ”† i64      โ”† i64       โ”† i64          โ”† str                 โ”† str                 โ”‚
โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ก
โ”‚ respondent_id โ”† Int64   โ”† 1547     โ”† 1547      โ”† 0            โ”† Respondent ID       โ”†                     โ”‚
โ”‚ satisfaction  โ”† Int64   โ”† 1523     โ”† 5         โ”† 5            โ”† Satisfaction Level  โ”† {                   โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "1": "Very Low",  โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "2": "Low",       โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "3": "Neutral",   โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "4": "High",      โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "5": "Very High"  โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”† }                   โ”‚
โ”‚ age           โ”† Int64   โ”† 1534     โ”† 6         โ”† 6            โ”† Age Group Category  โ”† {                   โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "1": "18-25",     โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "2": "26-35",     โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "3": "36-45",     โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "4": "46-55",     โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "5": "56-65",     โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”†   "6": "65+"        โ”‚
โ”‚               โ”†         โ”†          โ”†           โ”†              โ”†                     โ”† }                   โ”‚
โ”‚ ...           โ”† ...     โ”† ...      โ”† ...       โ”† ...          โ”† ...                 โ”† ...                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“– API Reference

print_metadata(df, meta, show_all_columns=True, max_width=222, include_all=False)

Print a comprehensive metadata summary for SPSS data loaded with pyreadstat.

Parameters:

  • df: DataFrame containing the SPSS data (Pandas or Polars)
  • meta: Metadata object from pyreadstat.read_sav()
  • show_all_columns: Whether to show all columns without truncation (default: True, optional)
  • max_width: Maximum table width in characters (default: 222, optional)
  • include_all: Whether to include all available metadata fields (default: False, optional)

export_metadata(df, meta, filename=None, show_all_columns=True, max_width=222, include_all=False)

Export SPSS metadata summary to a text file in the Downloads folder.

Parameters:

  • df: DataFrame containing the SPSS data (Pandas or Polars)
  • meta: Metadata object from pyreadstat.read_sav()
  • filename: Custom filename without extension (default: "metadata_summary")
  • show_all_columns: Whether to show all columns without truncation (default: True, optional)
  • max_width: Maximum table width in characters (default: 222, optional)
  • include_all: Whether to include all available metadata fields (default: False, optional)

extract_metadict(meta, include_all=False, output_path=None)

Extract metadata dictionary from pyreadstat meta object and save as JSON.

Parameters:

  • meta: Metadata object from pyreadstat.read_sav()
  • include_all: Whether to include all metadata fields or just essential ones (default: False, optional)
  • output_path: Custom file path for JSON output (must end with .json). If None, saves to Downloads/meta_dictionary.json (default: None, optional)

Example JSON Output (basic):

{
    "General Information": {
        "Notes": "Survey conducted in 2024",
        "Creation Time": "2024-01-15 10:30:00",
        "File Encoding": "UTF-8",
        "Number of Columns": 25,
        "Number of Rows": 100,
        "Table Name": "Table",
        "File Label": "Customer Satisfaction Survey"
    },
    "Variable Information": {
        "Column Names to Labels": {
            "respondent_id": "Respondent ID",
            "satisfaction": "Satisfaction Level",
            "age": "Age Group Category"
        },
        "Variable Value Labels": {
            "satisfaction": {
                "1": "Very Low",
                "2": "Low",
                "3": "Neutral",
                "4": "High",
                "5": "Very High"
            }
        }
    }
}

๐Ÿ“‹ Requirements

  • Python >=3.11
  • pyreadstat >=1.3.0
  • polars >=1.3.0
  • pandas >=2.3.0

๐Ÿ“ License

MIT License - see LICENSE file for details

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

metaprinter-0.2.7.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

metaprinter-0.2.7-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file metaprinter-0.2.7.tar.gz.

File metadata

  • Download URL: metaprinter-0.2.7.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.9

File hashes

Hashes for metaprinter-0.2.7.tar.gz
Algorithm Hash digest
SHA256 0865e6dd2333ee296db4cf58701b2c98ce4eecd09c78875dae5f9d99b557b5ce
MD5 8c93189088bd1ff0d2bd2e24b51df762
BLAKE2b-256 c9b2e20e27021998ba214fb1b447841bde51304671099ce81cffcf8dd37d3251

See more details on using hashes here.

File details

Details for the file metaprinter-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for metaprinter-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ac1ddb469c38f5258bf06bb239728e14c258b991902c4a3728dc5653238e4fce
MD5 a7642280dd6fdfef0c56c286a91a7d93
BLAKE2b-256 23650f8cef9b9ffe28d38e554ad4234614c574b0c0c2706cb67e17b4f32f9737

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