Metadata-Version: 2.4
Name: cfinterface
Version: 1.10.1
Summary: Interface for handling custom formatted files
Project-URL: Documentation, https://rjmalves.github.io/cfinterface/
Project-URL: Repository, https://github.com/rjmalves/cfinterface/
Author-email: Rogerio Alves <rogerioalves.ee@gmail.com>
License: MIT License
        
        Copyright (c) 2022 Rogerio Alves
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=2.0.0
Provides-Extra: dev
Requires-Dist: furo; extra == 'dev'
Requires-Dist: hypothesis; extra == 'dev'
Requires-Dist: matplotlib; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: numpydoc; extra == 'dev'
Requires-Dist: pandas-stubs; extra == 'dev'
Requires-Dist: pandas>=2.2.3; extra == 'dev'
Requires-Dist: plotly; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-benchmark; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: sphinx; extra == 'dev'
Requires-Dist: sphinx-gallery; extra == 'dev'
Provides-Extra: pandas
Requires-Dist: pandas>=2.2.3; extra == 'pandas'
Description-Content-Type: text/markdown

# cfinterface

[![tests](https://github.com/rjmalves/cfinterface/workflows/tests/badge.svg)](https://github.com/rjmalves/cfinterface/actions)
[![codecov](https://codecov.io/gh/rjmalves/cfinterface/branch/main/graph/badge.svg?token=86ZXJGB854)](https://codecov.io/gh/rjmalves/cfinterface)
[![PyPI version](https://img.shields.io/pypi/v/cfinterface.svg)](https://pypi.org/project/cfinterface/)
[![Python versions](https://img.shields.io/pypi/pyversions/cfinterface.svg)](https://pypi.org/project/cfinterface/)

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
- **Versioning** — `VERSIONS` dict with `resolve_version()` and `validate_version()` for files that evolve over time
- **Binary support** — `StorageType.TEXT` / `StorageType.BINARY` for seamless text or binary I/O
- **Batch reading** — `read_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`:

```python
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`:

```python
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](CHANGELOG.md) for release history.
