Skip to main content

dataclass_factory

PyPI version Build Status downloads license

dataclass_factory is a modern way to convert dataclasses or other objects to and from more common types like dicts

Help

See documentation for more details.

TL;DR

Install

pip install dataclass_factory

Use

from dataclasses import dataclass
import dataclass_factory


@dataclass
class Book:
    title: str
    price: int
    author: str = "Unknown author"


data = {
    "title": "Fahrenheit 451",
    "price": 100,
}

factory = dataclass_factory.Factory()
book: Book = factory.load(data, Book)  # Same as Book(title="Fahrenheit 451", price=100)
serialized = factory.dump(book) 

Requirements

  • python >= 3.6

You can use dataclass_factory with python 3.6 and dataclass library installed from pip.

On python 3.7 it has no external dependencies outside of the Python standard library.

Advantages

  • No schemas or configuration needed for simple cases. Just create Factory and call load/dump methods
  • Speed. It is up to 10 times faster than marshmallow and dataclasses.asdict (see benchmarks)
  • Automatic name style conversion (e.g. snake_case to CamelCase)
  • Automatic skipping of "internal use" fields (with leading underscore)
  • Enums, typed dicts, tuples and lists are supported out of the box
  • Unions and Optionals are supported without need to define them in schema
  • Generic dataclasses can be automatically parsed as well
  • Cyclic-referenced structures (such as linked-lists or trees) also can be converted
  • Validators, custom parser steps are supported.
  • Multiple schemas for single type can be provided to support different ways of parsing of the same type

Release files for dataclass-factory 2.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for dataclass-factory 2.16
File Interpreter ABI Platform
dataclass_factory-2.16-py3-none-any.whl Python 3 none any Details

Release files / dataclass_factory-2.16-py3-none-any.whl

Download URL dataclass_factory-2.16-py3-none-any.whl
Size 29.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d01e73d40b8f74051df822f21d8dc8bbf2754b11670cd1c477357e8b21323ed
BLAKE2b-256 checksum
How to use checksums
f16650b9f5d8a0e9fbe5469c5b8a7f198511fff9959347fc2443531d651b21d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.10

Release history Release notifications | RSS feed

This release

2.16 This release

1 release file

2.15

1 release file

2.14

1 release file

2.13

1 release file

2.12

1 release file

2.11

2 release files

2.10.2

1 release file

2.10.1

1 release file

2.10

1 release file

2.9

1 release file

2.8.3

1 release file

2.8.2

1 release file

2.8.1

1 release file

2.7

1 release file

2.6

1 release file

2.5

1 release file

2.4.2

1 release file

2.4.1

1 release file

2.4

1 release file

2.3

1 release file

2.2

1 release file

2.1

1 release file

2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page