Skip to main content

An extremely flexible and configurable data model conversion library

Project description

adaptix logo

PyPI version downloads versions license

An extremely flexible and configurable data model conversion library.

[!IMPORTANT] Adaptix is ready for production! The beta version only means there may be some backward incompatible changes, so you need to pin a specific version.

📚 Documentation

TL;DR

Install

pip install adaptix==3.0.0b11

Use for model loading and dumping.

from dataclasses import dataclass

from adaptix import Retort


@dataclass
class Book:
    title: str
    price: int


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 for converting one model to another.

from dataclasses import dataclass

from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

from adaptix.conversion import get_converter


class Base(DeclarativeBase):
    pass


class Book(Base):
    __tablename__ = 'books'

    id: Mapped[int] = mapped_column(primary_key=True)
    title: Mapped[str]
    price: Mapped[int]


@dataclass
class BookDTO:
    id: int
    title: str
    price: int


convert_book_to_dto = get_converter(Book, BookDTO)

assert (
    convert_book_to_dto(Book(id=183, title="Fahrenheit 451", price=100))
    ==
    BookDTO(id=183, title="Fahrenheit 451", price=100)
)

Use cases

  • Validation and transformation of received data for your API.
  • Conversion between data models and DTOs.
  • 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, attrs, sqlalchemy, pydantic and msgspec.
  • 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 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.0b11.tar.gz (134.0 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.0b11-py3-none-any.whl (179.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: adaptix-3.0.0b11.tar.gz
  • Upload date:
  • Size: 134.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for adaptix-3.0.0b11.tar.gz
Algorithm Hash digest
SHA256 3d3d660d97d9e1a85d133b181fdac8a200ff3185422fdf686601bc9ed0017162
MD5 1dd0ec0cf80aee7aaa71d6923f1b2554
BLAKE2b-256 58eaf55d4de521cb237b1dd9c4a21c6ae3885d21b4f90130d15fd88020d6d1ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: adaptix-3.0.0b11-py3-none-any.whl
  • Upload date:
  • Size: 179.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for adaptix-3.0.0b11-py3-none-any.whl
Algorithm Hash digest
SHA256 5afa7197d1a084fc93da852bf58194de4a1c506caa3f5889c9953a27ce515bda
MD5 2c4f6f8489d1509bf6e373d144566944
BLAKE2b-256 7670b087e09db584c2718cfff4a354c98dfac1844e7e7d0c75dc38685823eec1

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