dataclass-csv
Map CSV data into dataclasses
What it is and what it does
Dataclass CSV bridges Python's dataclasses and CSV file handling by reading CSV rows directly into typed dataclass instances instead of dictionaries. It performs automatic type conversion and validation based on dataclass field annotations, catching type mismatches and reporting the exact CSV line where errors occur. The library also provides a writer to serialize dataclass instances back to CSV.
The package is designed to reduce boilerplate: instead of manually looping through CSV rows, converting strings to the correct types, validating data, and applying defaults, you define a dataclass with type hints and let DataclassReader handle the rest. It supports field mapping for mismatched column names, default values, and datetime formatting via decorators.
Use it for:
- Load CSV data into typed objects for data processing pipelines where type safety and early error detection matter
- Validate CSV imports before storing in a database, with line-number feedback for fixing malformed rows
- Export application data to CSV by passing a list of dataclass instances to DataclassWriter
- Map CSV columns with non-standard names to dataclass fields without manual column indexing
- Parse datetime or numeric fields from CSV with automatic conversion and format control
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Reads and writes CSV files using Python dataclasses, with automatic type conversion, validation, and error reporting tied to specific CSV line numbers.
Yes. Zero runtime dependencies, active maintenance, permissive license, and no known vulnerabilities make it a low-risk choice. Install it if you work with CSV files and want type safety and cleaner code than dict-based approaches; skip it only if you need advanced CSV features (e.g., streaming very large files, complex nested structures) beyond the library's scope.
Install
dataclass-csv on PyPI
pip
pip install dataclass-csvuv
uv add dataclass-csvpoetry
poetry add dataclass-csvInstalling dataclass-csv
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with a recent release (194 days ago) and steady repository activity.
License in practice
Permissive license (BSD) allows use in commercial and proprietary projects with minimal restrictions.
Quickstart
from dataclasses import dataclass
from dataclass_csv import DataclassReader
@dataclass
class User:
firstname: str
email: str
age: int
with open('users.csv') as f:
reader = DataclassReader(f, User)
for row in reader:
print(row)
Verify before relying
- Whether custom type constructors beyond the documented set (str, int, float, complex, datetime, bool) are reliably supported
- Performance characteristics when processing large CSV files (row count or file size limits)
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 194 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 133,250/month — #11,524 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dataclass_csv-1.4.1-py3-none-any.whl
Keywords: csv, dataclass, dataclass-csv, dataclasses
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
typed-json-dataclassAdds JSON serialization and type validation to…
permissive · top 15,000 on PyPI
dataclassesProvides the PEP 557 dataclasses module for…
permissive · top 5,000 on PyPI
dataclass-wizardDataclass Wizard converts Python dataclasses to…
permissive · top 5,000 on PyPI
dataclasses-jsonConverts Python dataclasses to and from JSON…
permissive · top 1,000 on PyPI
daciteConverts dictionaries into dataclass instances…
permissive · top 1,000 on PyPI
dataclass-factoryConverts dataclasses to and from dictionaries…
permissive · top 15,000 on PyPI
clevercsvCleverCSV detects CSV file dialects…
permissive · top 15,000 on PyPI
djangorestframework-dataclassesAutomatically generates Django REST Framework…
permissive · top 5,000 on PyPI
recordclassRecordclass provides memory-efficient, mutable…
permissive · top 15,000 on PyPI
aiocsvProvides async-compatible CSV reading and…
permissive · top 5,000 on PyPI