Skip to content

fixed-width-file/python-pyfwf

Repository files navigation

python-pyfwf

License Python FWF Compliance QA Coverage pre-commit

python-pyfwf is a fast, type-safe Python 3.9+ library for parsing, validating, and exporting Fixed Width Files (FWF).

It is part of the Fixed Width File Ecosystem and fully implements the fwf-compliance-tests v1.0.0 specification.


🌟 Key Features

  • Type-Safe Columns: CharColumn, RightCharColumn, PositiveIntegerColumn, PositiveDecimalColumn, DateColumn, TimeColumn, and DateTimeColumn.
  • Flexible Descriptors: Structured records with HeaderRowDescriptor, DetailRowDescriptor, and FooterRowDescriptor.
  • Multiple Output Renders: Export layout specifications to Markdown, ReStructuredText (RST), or HTML tables via RenderUtils.
  • Full Test Suite & Compliance: 100% compliant with fwf-compliance-tests v1.0.0.
  • Git Hooks Ready: Pre-configured pre-commit and pre-push hooks.

🚀 Installation

Install via pip:

pip install pyfwf

💡 Quickstart

from pyfwf.columns import CharColumn, PositiveIntegerColumn
from pyfwf.descriptors import DetailRowDescriptor, FileDescriptor
from pyfwf.readers import Reader

# 1. Define columns
name_col = CharColumn('name', 20, 'User Name')
age_col = PositiveIntegerColumn('age', 3, 'Age in years')

# 2. Define row and file descriptors
detail = DetailRowDescriptor([name_col, age_col])
file_descriptor = FileDescriptor([detail])

# 3. Read fixed-width file content
content = "KELSON MEDEIROS     045\nMARIA SILVA         030\n"
reader = Reader(content, file_descriptor, "\n")

for row in reader:
    print(f"Name: {row['name']} | Age: {row['age']}")

🧪 Testing & Compliance

Run all unit tests using pytest:

pytest

⚓ Pre-Commit & Pre-Push Setup

Set up pre-commit and pre-push hooks:

pre-commit install
pre-commit install --hook-type pre-push

Run checks manually:

pre-commit run --all-files

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A simple python library to read tabbed file as validated array

Topics

Resources

License

Security policy

Stars

1 star

Watchers

1 watching

Forks

Packages

 
 
 

Contributors