Skip to main content

An utility class for creating instances of dataclasses

Project description

Adaptix

PyPI version downloads versions license

An extremely flexible and configurable data model conversion library.

📑 Documentation

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 = 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, and attrs
  • Working with self-referenced data types (such as linked lists or trees).
  • Saving path where an exception is raised (including unexpected errors).
  • Easy integration with Sentry, Datadog, and other monitoring systems.
  • Machine-readable errors that could be dumped.
  • Support for user-defined generic models.
  • Automatic name style conversion (e.g. snake_case to camelCase).
  • 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


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.0a4.tar.gz (70.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adaptix-3.0.0a4-py3-none-any.whl (93.8 kB view details)

Uploaded Python 3

File details

Details for the file adaptix-3.0.0a4.tar.gz.

File metadata

  • Download URL: adaptix-3.0.0a4.tar.gz
  • Upload date:
  • Size: 70.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.1

File hashes

Hashes for adaptix-3.0.0a4.tar.gz
Algorithm Hash digest
SHA256 bdaeacbe24f3a712d80cad540fa70a5868d5079dd9d5cb9b91984b8bd656eee1
MD5 d5389cc6865fce52f6cf90a8d51e8d0f
BLAKE2b-256 d600dfda48d626d9532dbf488f9988fca3180fb997546bd0bc41ae86c746900b

See more details on using hashes here.

File details

Details for the file adaptix-3.0.0a4-py3-none-any.whl.

File metadata

  • Download URL: adaptix-3.0.0a4-py3-none-any.whl
  • Upload date:
  • Size: 93.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.1

File hashes

Hashes for adaptix-3.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 d46aeb99ef9b13b8b4ec272438dd77b201cc1541c6f1e9272b20add44fb4ebd8
MD5 0b4f34aa34f04649c96e091bc17f8c18
BLAKE2b-256 f50d5c8dc1ef0cc4b0853acfb19e112b0deb2cf77e5a91b5a44d942ecfc61f6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page