Skip to main content

A utility for validating and processing flat files

Project description

FlatForge

FlatForge is a Python library for processing and validating flat files (fixed-length or delimited) with a focus on flexibility and ease of use.

Features

  • Support for fixed-length and delimited file formats
  • Configurable validation rules for individual fields
  • Global validation rules across multiple records
  • Detailed error reporting
  • YAML and string-based configuration options

Installation

pip install flatforge

Quick Start

from flatforge.config_parser import StringConfigParser
from flatforge.processor import Processor

# Create a configuration
config = """
[parameters]
delimiter = ,
section_separator = \n\n
record_separator = \n

[section_metadata]
0 = fl{10,5,15}|0:required,numeric|1:length(5)|2:regex([A-Z]{2,})
"""

# Parse the configuration
parser = StringConfigParser()
file_props = parser.parse(config)

# Create a processor
processor = Processor(file_props)

# Process a file
file_content = "1234567890ABCDE               \n0987654321FGHIJ               "
results = processor.process_file(file_content)

# Check for errors
for section_index, section_results in results.items():
    for result in section_results:
        if not result.is_valid:
            print(f"Error in section {section_index}, column {result.message.column_index}: {result.message.text}")

Core Concepts

FileProperties

The FileProperties class represents the structure and validation rules for a flat file. It contains:

  • Parameters: General settings like delimiters and separators
  • Sections: Different parts of the file, each with its own format and rules
  • Global Rules: Rules that apply across multiple records

Rule

A Rule defines a validation check for a specific field. Rules can be:

  • Basic Rules: Apply to individual fields (e.g., required, length, regex)
  • Global Rules: Apply across multiple records (e.g., uniqueness, sums)

Processor

The Processor applies the rules defined in a FileProperties object to validate file content.

Configuration

FlatForge supports both string-based and YAML-based configuration.

String Configuration

[parameters]
delimiter = ,
section_separator = \n\n
record_separator = \n

[section_metadata]
0 = fl{10,5,15}|0:required,numeric|1:length(5)|2:regex([A-Z]{2,})

YAML Configuration

parameters:
  delimiter: ','
  section_separator: '\n\n'
  record_separator: '\n'

sections:
  '0':
    format: 'fl{10,5,15}'
    columns:
      '0':
        - name: 'required'
        - name: 'numeric'
      '1':
        - name: 'length'
          parameters: ['5']
      '2':
        - name: 'regex'
          parameters: ['[A-Z]{2,}']

License

MIT

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

flatforge-0.1.0.tar.gz (36.9 kB view details)

Uploaded Source

Built Distribution

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

flatforge-0.1.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flatforge-0.1.0.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for flatforge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4028c1c446559f95b7f9ea91dddfc57b11b9b00c1d264fc7f53737f945a80e66
MD5 c4a5ef5c4fe0031e41920d4380f04a4b
BLAKE2b-256 c3d52990705049b20dcd2fcf1eb71098a64855cf56d8cd8e95dd6c4646922d07

See more details on using hashes here.

File details

Details for the file flatforge-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flatforge-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for flatforge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a83221e5610d3392fe8cae73c191a12297a6b4c6247f575420f541bdaca42056
MD5 9784276c134e41148774a93c61b9eda4
BLAKE2b-256 b0da9f4f49db0bdccab0581142e7bec68fdc33df2c13299ac8bcd101b4a1a1b2

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