Skip to content

Commit

Permalink
update readme and overview
Browse files Browse the repository at this point in the history
  • Loading branch information
zhPavel committed Feb 10, 2024
1 parent f61b8ea commit 1034b10
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Install
pip install adaptix==3.0.0b1
```

Use
Use for model loading and dumping.

```python
from dataclasses import dataclass

Expand All @@ -55,13 +56,45 @@ assert book == Book(title="Fahrenheit 451", price=100)
assert retort.dump(book) == data
```

Use for converting one model to another.

```python
from dataclasses import dataclass

from adaptix.conversion import get_converter


@dataclass
class Book:
title: str
price: int
author: str = "Unknown author"


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


convert_book_to_dto = get_converter(Book, BookDTO)

assert (
convert_book_to_dto(Book(title="Fahrenheit 451", price=100))
==
BookDTO(title="Fahrenheit 451", price=100, author="Unknown author")
)
```

## 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 in cache storage.
* Persisting entities at cache storage.
* Implementing fast and primitive ORM.

## Advantages
Expand Down
2 changes: 2 additions & 0 deletions docs/conversion/tutorial.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _conversion-tutorial:

***********
Tutorial
***********
Expand Down
2 changes: 2 additions & 0 deletions docs/loading-and-dumping/tutorial.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _loading-and-dumping-tutorial:

***********
Tutorial
***********
Expand Down
10 changes: 9 additions & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Example

.. literalinclude:: /examples/loading-and-dumping/tutorial/tldr.py
:lines: 2-
:caption: Model loading and dumping
:name: loading-and-dumping-example

.. literalinclude:: /examples/conversion/tutorial/tldr.py
:caption: Conversion one model to another
:name: conversion-example

Requirements
==================
Expand All @@ -35,6 +41,7 @@ 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.
Expand All @@ -52,4 +59,5 @@ Advantages
Further reading
==================

See :ref:`Tutorial` for details about library usage.
See :ref:`loading and dumping tutorial <loading-and-dumping-tutorial>`
and :ref:`conversion tutorial <conversion-tutorial>` for details about library usage.

0 comments on commit 1034b10

Please sign in to comment.