Skip to main content

Model to dictionary mapping for Python

Project description

Model to dictionary mapping for Python.

>>> 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):
... = foo
... = 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.5.tar.gz (7.9 kB view hashes)

Uploaded Source

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