skillfed

dataclass-csv

Map CSV data into dataclasses

dataclass-csv v1.4.1 133.2K downloads/30d#11,524 on PyPI196
Permissive license Active released

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-csv

uv

uv add dataclass-csv

poetry

poetry add dataclass-csv

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseNatural Language :: EnglishOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXOperating System :: UnixProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

csv to dataclass mappingtype-safe csv parsingdataclass csv reader writercsv validation with typesstructured csv data loading
csv-parsingdataclass-mappingtype-validation

More Text Processing packages