An extremely flexible and configurable data model conversion library
Reason this release was yanked:
An obscure bug at model dumper was found, that occurred if the field name was the same as the internal variable. Use 3.0.0a7 which contains only bugfix
Project description
Adaptix
An extremely flexible and configurable data model conversion library.
TL;DR
Install
pip install adaptix
Use
from dataclasses import dataclass
from adaptix import Retort
@dataclass
class Book:
title: str
price: int
author: str = "Unknown author"
data = {
"title": "Fahrenheit 451",
"price": 100,
}
# Retort is meant to be global constant or just one-time created
retort = Retort()
book = retort.load(data, Book)
assert book == Book(title="Fahrenheit 451", price=100)
assert retort.dump(book) == data
Use cases
- Validation and transformation of received data for your API.
- Config loading/dumping via codec that produces/takes dict.
- Storing JSON in a database and representing it as a model inside the application code.
- Creating API clients that convert a model to JSON sending to the server.
- Persisting entities at cache storage.
- Implementing fast and primitive ORM.
Advantages
- Sane defaults for JSON processing, no configuration is needed for simple cases.
- Separated model definition and rules of conversion that allow preserving SRP and have different representations for one model.
- Speed. It is one of the fastest data parsing and serialization libraries.
- There is no forced model representation, adaptix can adjust to your needs.
- Support dozens of types,
including different model kinds:
@dataclass
,TypedDict
,NamedTuple
, andattrs
- Working with self-referenced data types (such as linked lists or trees).
- Saving path where an exception is raised (including unexpected errors).
- Machine-readable errors that could be dumped.
- Support for user-defined generic models.
- Automatic name style conversion (e.g.
snake_case
tocamelCase
). - Predicate system that allows to concisely and precisely override some behavior.
- Disabling additional checks to speed up data loading from trusted sources.
- No auto casting by default. The loader does not try to guess value from plenty of input formats.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
adaptix-3.0.0a6.tar.gz
(76.7 kB
view hashes)
Built Distribution
adaptix-3.0.0a6-py3-none-any.whl
(97.4 kB
view hashes)
Close
Hashes for adaptix-3.0.0a6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14ea63062f49068802a561e9815b18bfa78b5defe68bfca29ba7aa02d21f1c0f |
|
MD5 | 803aa38d5e114037befe1f620fbb6f0e |
|
BLAKE2b-256 | 0d3b54dbf452c4deb7be88dbebe98a593e7b374d2038228726bbba92d3b0d2f9 |