skillfed

dataclass-factory

An utility class for creating instances of dataclasses

dataclass-factory v2.16 90.6K downloads/30d#13,579 on PyPI612
Permissive license Apache2 Active released

What it is and what it does

dataclass_factory is a utility for bidirectional conversion between dataclass instances and dictionaries or other common types. It handles the boilerplate of parsing nested structures, enums, unions, and optional fields without requiring schema definitions. The factory pattern lets you load a dict into a typed dataclass instance with a single call, and dump instances back to dicts just as easily.

It's designed for scenarios where you need to deserialize external data (from APIs, configuration files, or databases) into strongly-typed Python objects, or serialize those objects back to plain data structures. The package supports cyclic references, generic dataclasses, and custom validators, making it suitable for complex domain models and data pipelines.

Use it for:

  • Parse API responses into dataclass instances with automatic type validation and nested object handling.
  • Load configuration files (JSON, YAML) into typed dataclass structures for application settings.
  • Serialize dataclass instances back to dictionaries for database storage or API responses.
  • Validate and transform user input by loading it into a dataclass with custom validators.
  • Handle linked-list or tree structures where objects reference other instances of the same type.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts dataclasses to and from dictionaries and other common types with minimal configuration, supporting nested structures, enums, unions, and custom validation.

Yes. Low install friction, active maintenance, no security issues, and permissive licensing make it a safe choice. Use it when you need to convert between dataclasses and dictionaries without schema boilerplate—particularly for API clients, config loaders, or data pipelines where type safety matters.

Install

dataclass-factory on PyPI

pip

pip install dataclass-factory

uv

uv add dataclass-factory

poetry

poetry add dataclass-factory

Installing dataclass-factory

Before you install

Low friction: pure Python wheel with only the standard library dataclasses module as a runtime dependency. Actively maintained with recent commits and no known vulnerabilities.

License in practice

Apache 2.0 permissive license allows commercial and private use with minimal restrictions; you may use, modify, and distribute the package freely provided you include a copy of the license.

Quickstart

pip install dataclass_factory

from dataclasses import dataclass
import dataclass_factory

@dataclass
class Book:
    title: str
    price: int

factory = dataclass_factory.Factory()
book = factory.load({"title": "Example", "price": 100}, Book)
data = factory.dump(book)

Verify before relying

  • Whether the claimed 10x speed advantage over marshmallow and dataclasses.asdict holds in your specific use case.
  • Whether automatic name style conversion (snake_case to CamelCase) is enabled by default or requires explicit configuration.

Package facts

License Apache2 (permissive)
Python support supports the current Python release (>=3.6)
Install friction low — pure-Python wheel
Runtime dependencies 1 — dataclasses
Maintenance actively maintained — 1,486 days since the last release
Last repo commit
First released
Downloads 90,552/month — #13,579 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: dataclass_factory-2.16-py3-none-any.whl

Intended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

dataclass serialization deserializationconvert dataclass to dictdataclass json loadingdataclass factory patternparse dict into dataclassdataclass validation conversiontyped data loading
serializationdataclass-utilitiestype-conversion

More Application Frameworks packages