Write dataclasses to delimited text formats and read them back again.
Features type-safe parsing, optional field support, and an intuitive API for working with structured data.
The package can be installed with pip
:
pip install typeline
>>> from dataclasses import dataclass
>>>
>>> @dataclass
... class MyData:
... field1: int
... field2: str
... field3: float | None
>>> from tempfile import NamedTemporaryFile
>>> from typeline import TsvRecordWriter
>>>
>>> temp_file = NamedTemporaryFile(mode="w+t", suffix=".txt")
>>>
>>> with TsvRecordWriter.from_path(temp_file.name, MyData) as writer:
... writer.write_header()
... writer.write(MyData(10, "test1", 0.2))
... writer.write(MyData(20, "test2", None))
>>> from typeline import TsvRecordReader
>>>
>>> with TsvRecordReader.from_path(temp_file.name, MyData) as reader:
... for record in reader:
... print(record)
MyData(field1=10, field2='test1', field3=0.2)
MyData(field1=20, field2='test2', field3=None)
See the contributing guide for more information.