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

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

Real world app

This example shows how adaptix can be integrated into production code.

Here are five real-world scenarios:

  1. Config is loaded from env variables (file config.py)

  2. Storing cache in Redis-like storage (file user_gateway.py)

  3. Transformation SQLAlchemy model to Pydantic model (file routes.py)

  4. Serializing SQLAlchemy model directly (file routes.py)

  5. Storing JSON in DB with transparent parsing and dumping (file db_models.py)

Source Code