Skip to main content

Interface for handling custom formatted files

Project description

cfinterface

tests codecov PyPI version Python versions

Python framework for modeling custom file formats with declarative reading, formatting, and writing.

Key Features

  • Fields — typed value containers (LiteralField, IntegerField, FloatField, DatetimeField) with positional formatting for both text and binary files
  • Line — ordered collection of fields that models a single line or record
  • Register / RegisterFile — single-line blocks identified by a beginning pattern, ideal for files with many line types
  • Block / BlockFile — multi-line blocks with beginning/ending patterns, for complex structured files
  • Section / SectionFile — ordered, non-overlapping divisions of file content
  • TabularParser — schema-driven tabular parsing with fixed-width or delimiter-separated layouts
  • VersioningVERSIONS dict with resolve_version() and validate_version() for files that evolve over time
  • Binary supportStorageType.TEXT / StorageType.BINARY for seamless text or binary I/O
  • Batch readingread_many() for reading multiple files in one call

Install

cfinterface requires Python >= 3.10:

pip install cfinterface

Optional Dependencies

For pandas DataFrame integration (TabularParser.to_dataframe()):

pip install cfinterface[pandas]

Quick Start

Model a line-based file with Register and RegisterFile:

from datetime import datetime
from cfinterface import (
    DatetimeField, FloatField, LiteralField, Line, Register, RegisterFile,
)

class DataHigh(Register):
    IDENTIFIER = "DATA_HIGH"
    IDENTIFIER_DIGITS = 9
    LINE = Line(
        [
            LiteralField(size=6, starting_position=11),
            LiteralField(size=9, starting_position=19),
            DatetimeField(size=10, starting_position=30, format="%m/%d/%Y"),
            FloatField(size=6, starting_position=42, decimal_digits=2),
        ]
    )

class MyFile(RegisterFile):
    REGISTERS = [DataHigh]

file = MyFile.read("data.txt")
for reg in file.data.get_registers_of_type(DataHigh):
    print(reg.data)

Parse tabular data with TabularParser:

from cfinterface import IntegerField, FloatField, LiteralField
from cfinterface.components.tabular import ColumnDef, TabularParser

columns = [
    ColumnDef(name="City", field=LiteralField(size=12, starting_position=0)),
    ColumnDef(name="Pop", field=IntegerField(size=10, starting_position=12)),
    ColumnDef(name="Area", field=FloatField(size=8, starting_position=22, decimal_digits=1)),
]

parser = TabularParser(columns)
data = parser.parse_lines(["Springfield  1200000    115.4\n"])
# {"City": ["Springfield"], "Pop": [1200000], "Area": [115.4]}

Documentation

Guides, tutorials, and API reference: https://rjmalves.github.io/cfinterface

Changelog

See CHANGELOG.md for release history.

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

cfinterface-1.9.0.tar.gz (253.3 kB view details)

Uploaded Source

Built Distribution

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

cfinterface-1.9.0-py3-none-any.whl (42.0 kB view details)

Uploaded Python 3

File details

Details for the file cfinterface-1.9.0.tar.gz.

File metadata

  • Download URL: cfinterface-1.9.0.tar.gz
  • Upload date:
  • Size: 253.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cfinterface-1.9.0.tar.gz
Algorithm Hash digest
SHA256 02c1a0e8eeed276b975ee7cdb87baddffae98484dfc84f9f43c33676bfa6caee
MD5 06d3124f641080a302d7115ebdbdd4f1
BLAKE2b-256 70d85288f82f99c0b0ca0a13ff8b6282234fa113ad451d35dd150156806a4de4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfinterface-1.9.0.tar.gz:

Publisher: publish.yml on rjmalves/cfinterface

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cfinterface-1.9.0-py3-none-any.whl.

File metadata

  • Download URL: cfinterface-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 42.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cfinterface-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f56c6bb78d98e818042257c3ebc103d6e57301efa9bc58dacffee497d243a863
MD5 bf3da31ca00690dafe666cb9dc96267c
BLAKE2b-256 9ac2307a0750d8ab3e7a946121735ce15e5275eb44ad203d2a0a0dd19eba5260

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfinterface-1.9.0-py3-none-any.whl:

Publisher: publish.yml on rjmalves/cfinterface

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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