Registry / database / dataclass-factory

dataclass-factory

JSON →
library2.16pypypi✓ verified 89d ago

A utility class for creating instances of dataclasses from plain data (dicts, lists, etc.). Current version 2.16, released monthly or on demand. Supports parsing, validation, and serialization of nested dataclasses.

pip install dataclass-factory
INSTALL
IMPORT
SIG · DATACLASS-FACTORY
D
dataclass-factory
databasepythonv2.16
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Factory
✓ from dataclass_factory import Factory

Basic usage: load a dataclass from a dict.

from dataclasses import dataclass from dataclass_factory import Factory @dataclass class User: name: str age: int factory = Factory() data = {"name": "Alice", "age": 30} user = factory.load(data, User) print(user)
Debug
Known issues
gotchaFactory uses caching; reusing the same factory instance for different schemas may cause memory leaks or stale schemas. Use separate factories for distinct data structures.
fix
Create a new Factory per set of related dataclasses or call factory.clear() to reset caches.
affects: all
gotchaThe library does not automatically handle field aliases (e.g., JSON snake_case vs Python camelCase). You must define a parser or use field(name=...) in dataclass.
fix
Use parser.Parser with aliases or rename dataclass fields to match input keys.
affects: all
deprecatedThe old import `from dataclass_factory import Factory, schemas` is deprecated; schemas module is now internal.
fix
Use `from dataclass_factory import Factory` and rely on default schema generation.
affects: >=2.0
Errors
Common errors & fixes
AttributeError: 'Factory' object has no attribute 'load'
Using version <2.0 where the method was named 'parse' instead of 'load'.
fix
Upgrade to >=2.0 or use factory.parse() in older versions.
TypeError: __init__() got an unexpected keyword argument 'name'
Passing field names as kwargs when the dataclass has __post_init__ that expects different arguments.
fix
Ensure your dataclass fields match the input keys exactly. Use field(init=False) for computed fields.
Upgrade
Version history
2.16latest on PyPI · released Jul 20, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Resources
dataclass-factory — pip install dataclass-factory · libregistry