Skip to main content

A declarative data mapper

Project description

data-mapper

A declarative data mapper

Description

Most projects work with different representations of the same data. The code that is written every time to morph data between its representations is mostly very repetitive. More over, it is always a deposit of bugs and issues which requires a developer or tester to unit-test it.

This package is an attempt to solve these problems... well, at least the most common ones.

And to make a developer job easier it is primarily designed to be used in declarative fashion: describe what you want and get it right after.

Use Cases and Features

Here are examples of the most common use-cases and features:

Different Naming Schemes

This mapper looks for properties first_name and last_name in the data. For property first_name it tries to resolve it by the first key 'first_name', if not found it tries the second key 'name'. The similar process goes for property last_name.

from data_mapper.mappers import Mapper
from data_mapper.properties import Property

class PersonMapper(Mapper):
    first_name = Property('first_name', 'name')
    last_name = Property('last_name', 'surname')

mapper = PersonMapper()

assert mapper.get({
    'first_name': 'Ivan', 
    'surname': 'Bogush',
}) == {
    'first_name': 'Ivan', 
    'last_name': 'Bogush',
}

assert mapper.get({
    'name': 'Ivan', 
    'surname': 'Bogush',
}) == {
    'first_name': 'Ivan', 
    'last_name': 'Bogush',
}

This use-case has a story :)

It was the first issue I wanted to solve in my other project. I had different naming schemes in different data sources, and in my databases. All of them used different names for product categories: 'categories', 'category', 'categoryId'. I found it very boring to write repeatable code to convert the same data.

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

data-mapper-0.0.2.tar.gz (7.8 kB view hashes)

Uploaded Source

Built Distribution

data_mapper-0.0.2-py3-none-any.whl (15.9 kB view hashes)

Uploaded Python 3

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