Skip to main content

A mapping tool from model to dictionary.

Project description

A mapping tool from model to dictionary.

>>> from bpmappers import Mapper, RawField
>>> class SpamMapper(Mapper):
...     spam = RawField('foo')
...     egg = RawField('bar')
...
>>>
>>> SpamMapper(dict(foo=123, bar='abc')).as_dict()
{'egg': 'abc', 'spam': 123}
>>>
>>> class FooModel(object):
...     def __init__(self, foo, bar):
...         self.foo = foo
...         self.bar = bar
...
>>> SpamMapper(FooModel(foo=123, bar='abc')).as_dict()
{'egg': 'abc', 'spam': 123}
>>>
>>> class HogeMapper(Mapper):
...     hoge = RawField('hoge.piyo.fuga')
...
>>> HogeMapper({'hoge': {'piyo': {'fuga': 123}}}).as_dict()
{'hoge': 123}

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

bpmappers-0.8.tar.gz (15.7 MB view hashes)

Uploaded Source

Built Distribution

bpmappers-0.8-py2.py3-none-any.whl (11.1 kB view hashes)

Uploaded Python 2 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