$ show dfurtado/dataclass-csv
Dataclass CSV is a Python library that maps CSV rows to dataclass instances, providing type-safe reading and writing of CSV files. It leverages Python's standard `csv` module and dataclasses to automatically convert and validate fields based on type annotations. The library supports common types (int, str, float, bool, datetime, date), custom user-defined types, optional fields with defaults, field mapping for mismatched column names, and decorators for date format and whitespace handling. It includes both a `DataclassReader` (iterable over dataclass instances) and a `DataclassWriter` (writes dataclass lists to CSV). The codebase is small, well-structured, and has no external dependencies beyond the Python standard library. It is primarily a library for application developers who need to integrate CSV data with Python dataclasses in a clean, validated manner.
The LLM identified 2 files worth highlighting for reuse:
Implements a fluent mapping API (`FieldMapper`) that allows users to chain `.map(csv_field).to(dataclass_field)` calls. The class stores a callback and exposes a `to` method that invokes it, enabling clean DSL-like configuration for CSV-to-dataclass field mapping. This pattern is self-contained and could be extracted for any similar mapping scenario.
Mirror of `FieldMapper` for the writer side, providing a fluent API to map dataclass property names to custom CSV header names. Uses the same callback pattern, making it reusable for any object-to-header mapping task.