YAAB aims to provide a flexible base for Adapter Design Pattern implementations based on dataclasses.
Project description
Yet Another Adapter Base
YAAB aims to provide a flexible base for Adapter Design Pattern implementations based on dataclasses.
Free software: MIT license
Documentation: https://yaab.readthedocs.io.
Example Usage
Let’s assume that you are interfacing an API that returns a JSON object with the following structure:
{
"weird_name": "My name",
"oid": "3"
}
And you would like to transform it into a schema that fits the rest of your API, let’s assume:
{
"name": "My name",
"id": 3
}
Then you would define and use your model in the following way:
>>> from dataclasses import asdict, dataclass, field
>>>
>>> from yaab.adapter import BaseAdapter
>>>
>>> @dataclass
... class MyModel(BaseAdapter):
... id: int = field(metadata={"transformations": ("oid", int)})
... name: str = field(metadata={"transformations": ("weird_name", )})
...
>>> m = MyModel.from_dict({"weird_name": "My name", "oid": "3"})
>>> print(m)
MyModel(id=3, name='My name')
>>> asdict(m)
{'id': 3, 'name': 'My name'}
Features
TODO
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.2.2 (2020-05-03)
Introduce type conversion & convenience Mixins
0.2.1 (2020-02-18)
Bugfix: from_env now utilizes default values.
0.2.0 (2020-02-18)
Add dataclass nesting support.
0.1.0 (2020-01-21)
First release on PyPI.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yaab-0.2.2.tar.gz.
File metadata
- Download URL: yaab-0.2.2.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7876bff852eaf99af93b6a08b979b686c16f62b16e1fe9abf6d03f6450d057d4
|
|
| MD5 |
61b69862910eb97350f0ee00f01cc67f
|
|
| BLAKE2b-256 |
824a06dae6e18f2f01710759f9b27105618036261dab5ab98741540aae16f08d
|
File details
Details for the file yaab-0.2.2-py2.py3-none-any.whl.
File metadata
- Download URL: yaab-0.2.2-py2.py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98317df95e55c4da5fa43238ba43529d192244d451e9aa8aa28ca1178ed0b1c2
|
|
| MD5 |
6d246df2913a98b4645af75b8f5edbee
|
|
| BLAKE2b-256 |
6709d609cfd0825b0d8b4b81236da0a9ce3be0cea8546c4c1e156dc543b46956
|