Skip to main content

YAAB aims to provide a flexible base for Adapter Design Pattern implementations based on dataclasses.

Project description

Yet Another Adapter Base

https://img.shields.io/pypi/v/yaab.svg https://img.shields.io/travis/panagiks/yaab.svg Documentation Status

YAAB aims to provide a flexible base for Adapter Design Pattern implementations based on dataclasses.

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

yaab-0.2.2.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

yaab-0.2.2-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2 Python 3

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

Hashes for yaab-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7876bff852eaf99af93b6a08b979b686c16f62b16e1fe9abf6d03f6450d057d4
MD5 61b69862910eb97350f0ee00f01cc67f
BLAKE2b-256 824a06dae6e18f2f01710759f9b27105618036261dab5ab98741540aae16f08d

See more details on using hashes here.

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

Hashes for yaab-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 98317df95e55c4da5fa43238ba43529d192244d451e9aa8aa28ca1178ed0b1c2
MD5 6d246df2913a98b4645af75b8f5edbee
BLAKE2b-256 6709d609cfd0825b0d8b4b81236da0a9ce3be0cea8546c4c1e156dc543b46956

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page