Interface for handling custom formatted files
Project description
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 —
VERSIONSdict withresolve_version()andvalidate_version()for files that evolve over time - Binary support —
StorageType.TEXT/StorageType.BINARYfor 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:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfinterface-1.10.1.tar.gz.
File metadata
- Download URL: cfinterface-1.10.1.tar.gz
- Upload date:
- Size: 82.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18cbefd0e3cde531a76040cc8aae99584a03bfccb066bec489d55a18e0a09944
|
|
| MD5 |
28127d12ab85fb7984c488f706738763
|
|
| BLAKE2b-256 |
fbb9425e3eb6bf06778e55771a057db1f6f696ea53cae826ad1851062cc96c19
|
Provenance
The following attestation bundles were made for cfinterface-1.10.1.tar.gz:
Publisher:
publish.yml on rjmalves/cfinterface
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cfinterface-1.10.1.tar.gz -
Subject digest:
18cbefd0e3cde531a76040cc8aae99584a03bfccb066bec489d55a18e0a09944 - Sigstore transparency entry: 1284972165
- Sigstore integration time:
-
Permalink:
rjmalves/cfinterface@aafe855e40a4a1e3c11e900efa9dfb15ad62f933 -
Branch / Tag:
refs/tags/v1.10.1 - Owner: https://github.com/rjmalves
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aafe855e40a4a1e3c11e900efa9dfb15ad62f933 -
Trigger Event:
release
-
Statement type:
File details
Details for the file cfinterface-1.10.1-py3-none-any.whl.
File metadata
- Download URL: cfinterface-1.10.1-py3-none-any.whl
- Upload date:
- Size: 42.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9de23ac94ac2f8ba56d215d773df32ce429ad2db2260894356913e961cc7ef82
|
|
| MD5 |
34112d97cfb98ac89ea967bb74d57042
|
|
| BLAKE2b-256 |
084170bd41267a4bc8f26bd96faea977f853f3f7b72776a44503042a412e7943
|
Provenance
The following attestation bundles were made for cfinterface-1.10.1-py3-none-any.whl:
Publisher:
publish.yml on rjmalves/cfinterface
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cfinterface-1.10.1-py3-none-any.whl -
Subject digest:
9de23ac94ac2f8ba56d215d773df32ce429ad2db2260894356913e961cc7ef82 - Sigstore transparency entry: 1284972286
- Sigstore integration time:
-
Permalink:
rjmalves/cfinterface@aafe855e40a4a1e3c11e900efa9dfb15ad62f933 -
Branch / Tag:
refs/tags/v1.10.1 - Owner: https://github.com/rjmalves
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aafe855e40a4a1e3c11e900efa9dfb15ad62f933 -
Trigger Event:
release
-
Statement type: