All Projects → Tishka17 → Dataclass_factory

Tishka17 / Dataclass_factory

Licence: apache-2.0
Modern way to convert python dataclasses or other objects to and from more common types like dicts or json-like structures

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Dataclass factory

Noproto
Flexible, Fast & Compact Serialization with RPC
Stars: ✭ 138 (+18.97%)
Mutual labels:  json, schemas, serialization, deserialization
Dart Json Mapper
Serialize / Deserialize Dart Objects to / from JSON
Stars: ✭ 206 (+77.59%)
Mutual labels:  json, serialization, deserialization
Aspjson
A fast classic ASP JSON parser and encoder for easy JSON manipulation to work with the new JavaScript MV* libraries and frameworks.
Stars: ✭ 165 (+42.24%)
Mutual labels:  json, serialization, deserialization
Java
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
Stars: ✭ 1,308 (+1027.59%)
Mutual labels:  json, serialization, deserialization
Pyjson tricks
Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable.
Stars: ✭ 131 (+12.93%)
Mutual labels:  json, serialization, deserialization
Orjson
Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
Stars: ✭ 2,595 (+2137.07%)
Mutual labels:  json, serialization, deserialization
Go
A high-performance 100% compatible drop-in replacement of "encoding/json"
Stars: ✭ 10,248 (+8734.48%)
Mutual labels:  json, serialization, deserialization
Handyjson
A handy swift json-object serialization/deserialization library
Stars: ✭ 3,913 (+3273.28%)
Mutual labels:  json, serialization, deserialization
Bebop
An extremely simple, fast, efficient, cross-platform serialization format
Stars: ✭ 305 (+162.93%)
Mutual labels:  json, serialization, deserialization
Jsonapi Rails
Rails gem for fast jsonapi-compliant APIs.
Stars: ✭ 242 (+108.62%)
Mutual labels:  json, serialization, deserialization
Borer
Efficient CBOR and JSON (de)serialization in Scala
Stars: ✭ 131 (+12.93%)
Mutual labels:  json, serialization, deserialization
Jackson Module Kotlin
Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Stars: ✭ 830 (+615.52%)
Mutual labels:  json, serialization, deserialization
Yyjson
The fastest JSON library in C
Stars: ✭ 1,894 (+1532.76%)
Mutual labels:  json, serialization, deserialization
Mashumaro
Fast and well tested serialization framework on top of dataclasses
Stars: ✭ 208 (+79.31%)
Mutual labels:  json, serialization, deserialization
Jsonapi Rb
Efficiently produce and consume JSON API documents.
Stars: ✭ 219 (+88.79%)
Mutual labels:  json, serialization, deserialization
Fastjson
A fast JSON parser/generator for Java.
Stars: ✭ 23,997 (+20587.07%)
Mutual labels:  json, serialization, deserialization
Typical
Typical: Fast, simple, & correct data-validation using Python 3 typing.
Stars: ✭ 111 (-4.31%)
Mutual labels:  serialization, deserialization, typing
Json Mobx
Simple undo/redo and persistence for MobX
Stars: ✭ 78 (-32.76%)
Mutual labels:  json, serialization
Ducky
Duck-Typed Value Handling for JavaScript
Stars: ✭ 71 (-38.79%)
Mutual labels:  json, typing
Dartson
Dartson is a Dart library that can be used to convert Dart objects into a JSON string.
Stars: ✭ 78 (-32.76%)
Mutual labels:  json, serialization

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].