Examples#

The source code repository contains various examples of library usage. The behavior of each example is illustrated via included tests.

Simple API processing#

Example of loading and dumping data for some JSON API. It shows how to achieve the desired result using minimal retort configuration.

Models represent simplified data of current and forecast weather request to OpenWeather

Source Code

SQLAlchemy JSON#

This example shows how to use Adaptix with SQLAlchemy to store JSON in a relational database.

Adaptix transparently converts JSON to desired dataclass and vice versa, your SQLAlchemy models contain already transmuted data.

Be careful persisting JSON in relational databases. There are a few appropriate use cases for this.

Source Code

API division#

An example illustrates how to implement different representations of a single model. The first representation is outer (outer_receipt_retort), it has a lot of validations and is used to load data from untrusted sources, e.g. API users. The second is inner (inner_receipt_retort) which contains less validation that speeds up loading data. It can be used to load and dump data for internal API to communicate between services.

Also, this example shows some other advanced concepts like adding support for custom types (PhoneNumber and Money) and provider chaining.

Another important concept behind this example is that there are no general retort objects. You can define a retort configured to work with a specific type and then include this retort to another responsible for the entire API endpoints.

For simplicity, inner_receipt_retort and outer_receipt_retort are contained in one module, but in a production code, most likely, they should be placed in their Interface Adapters layer

Source Code