No project description provided
Project description
Package to convert arbitrary python objects into DTOs ready
for serialization and validation.
Home-page: https://github.com/Songbee/beerializer
Author: Songbee Team
Author-email: hi@songbee.net
License: UNKNOWN
Description: Beerializer
===========
|Documentation Status|
A fork of awesome `R2DTO <https://github.com/nickswebsite/r2dto>`__ by
@nickswebsite.
Provides easy interface for transformation and validation of arbitrary
python objects into DTOs suitable for receiving from and delivering to
other services.
Quick Start
-----------
Let's start by creating a simple model class:
.. code:: python
class Simpson(object):
def __init__(self):
self.first_name = ""
self.last_name = ""
def __str__(self):
return self.first_name + " " + self.last_name
To create a serializer, we need to map attributes to fields of our DTO:
.. code:: python
class SimpsonSerializer(Serializer):
class Meta:
model = Simpson
first_name = fields.StringField(name="firstName")
last_name = fields.StringField(name="lastName")
When you get a payload that requires one of these serializers, call
``Serializer.load(data)``.
.. code:: pycon
>>> data = {
... "firstName": "Homer",
... "lastName": "Simpson",
... }
>>> s = SimpsonSerializer.load(data)
>>> s
<class '__main__.Simpson'>
>>> str(s)
'Homer Simpson'
To go the other way. Pass the object you want to transfer into the
``dump`` method:
.. code:: pycon
>>> homer = Simpson()
>>> homer.first_name = "Homer"
>>> homer.last_name = "Simpson"
>>> s = SimpsonSerializer.dump(homer)
>>> s
{'firstName': 'Homer', 'lastName': 'Simpson'}
.. |Documentation Status| image:: https://readthedocs.org/projects/beerializer/badge/?version=latest
:target: http://beerializer.readthedocs.io/en/latest/?badge=latest
Keywords: dto serializer serialize REST marshal JSON
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Public Domain
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
Classifier: Topic :: Software Development
for serialization and validation.
Home-page: https://github.com/Songbee/beerializer
Author: Songbee Team
Author-email: hi@songbee.net
License: UNKNOWN
Description: Beerializer
===========
|Documentation Status|
A fork of awesome `R2DTO <https://github.com/nickswebsite/r2dto>`__ by
@nickswebsite.
Provides easy interface for transformation and validation of arbitrary
python objects into DTOs suitable for receiving from and delivering to
other services.
Quick Start
-----------
Let's start by creating a simple model class:
.. code:: python
class Simpson(object):
def __init__(self):
self.first_name = ""
self.last_name = ""
def __str__(self):
return self.first_name + " " + self.last_name
To create a serializer, we need to map attributes to fields of our DTO:
.. code:: python
class SimpsonSerializer(Serializer):
class Meta:
model = Simpson
first_name = fields.StringField(name="firstName")
last_name = fields.StringField(name="lastName")
When you get a payload that requires one of these serializers, call
``Serializer.load(data)``.
.. code:: pycon
>>> data = {
... "firstName": "Homer",
... "lastName": "Simpson",
... }
>>> s = SimpsonSerializer.load(data)
>>> s
<class '__main__.Simpson'>
>>> str(s)
'Homer Simpson'
To go the other way. Pass the object you want to transfer into the
``dump`` method:
.. code:: pycon
>>> homer = Simpson()
>>> homer.first_name = "Homer"
>>> homer.last_name = "Simpson"
>>> s = SimpsonSerializer.dump(homer)
>>> s
{'firstName': 'Homer', 'lastName': 'Simpson'}
.. |Documentation Status| image:: https://readthedocs.org/projects/beerializer/badge/?version=latest
:target: http://beerializer.readthedocs.io/en/latest/?badge=latest
Keywords: dto serializer serialize REST marshal JSON
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Public Domain
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
Classifier: Topic :: Software Development
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
beerializer-0.1.2.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for beerializer-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cbfb8144d365a66433bffe995f5aeba1a6cdccdb0cfd6aac17377d8d66f64a5 |
|
MD5 | 3ebfce0230ede0e06fc7edad4e663711 |
|
BLAKE2b-256 | 7beac572e39302bbcc49a817c4a4c9719b0eab1f1f0a3b9684f90556bf3026ca |