Skip to main content

Dataclass IO

Project description

dataclass_io

CI Python Versions MyPy Checked Ruff

Dataclass IO.

Quickstart

Reading

from dataclasses import dataclass
from dataclass_io import DataclassReader


@dataclass
class MyData:
    foo: int
    bar: str


with open("test.tsv", "w") as testfile:
    testfile.write("foo\tbar\n")
    testfile.write("1\tabc\n")
    testfile.write("2\tdef\n")

with DataclassReader("test.tsv", MyData) as reader:
    for record in reader:
        print(record.foo)

Writing

from dataclasses import dataclass
from dataclass_io import DataclassWriter


@dataclass
class MyData:
    foo: int
    bar: str


with DataclassWriter("test.tsv", MyData) as writer:
    for i in range(3):
        record = MyData(foo=i, bar="something")
        writer.write(record)

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

dataclass_io-0.1.0.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

dataclass_io-0.1.0-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page