Dataclass IO
Project description
dataclass_io
Read and write dataclasses.
dataclass_io
provides similar functionality to the standard library's csv.DictReader
and csv.DictWriter
, and adds type safety.
Installation
dataclass_io
may be installed via pip
:
pip install 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.open("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.open("test.tsv", MyData) as writer:
for i in range(3):
record = MyData(foo=i, bar="something")
writer.write(record)
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
dataclass_io-0.2.0.tar.gz
(8.7 kB
view details)
Built Distribution
File details
Details for the file dataclass_io-0.2.0.tar.gz
.
File metadata
- Download URL: dataclass_io-0.2.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.8 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5430cca5fb087920e66fd27fcf0027a65260046e0208ba92fb631917ac288a6 |
|
MD5 | a9fb8bde0fd30b6edd3d99bef3058313 |
|
BLAKE2b-256 | 4286cc3823eb06c110dd68d56b9e10300a922ec850bfdfb881a9c18b67724e70 |
File details
Details for the file dataclass_io-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: dataclass_io-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.8 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19e0778d12b41ccd7996c3e5dc054895824a1cdcbf30e23aefb32e6c8068682d |
|
MD5 | 9be53393b5e2b3ccf4d27f29cf5770c9 |
|
BLAKE2b-256 | 151bd7494c4a8bb1a75ac7ceecaea544488b64dc503fdbb30d5869fefcd184bd |