ridiculously fast object serialization
Project description
serpy is a super simple object serialization framework built for speed. Compared to other popular Python serialization frameworks like marshmallow or Django Rest Framework Serializers serpy is at least an order of magnitude faster.
Source
Source at: https://github.com/clarkduvall/serpy
If you want a feature, send a pull request!
Documentation
Full documentation at: http://serpy.readthedocs.org/en/latest/
Installation
$ pip install serpy
Examples
Simple Example
import serpy
class Foo(object):
"""The object to be serialized."""
y = 'hello'
z = 9.5
def __init__(self, x):
self.x = x
class FooSerializer(serpy.Serializer):
"""The serializer schema definition."""
# Use a Field subclass like IntField if you need more validation.
x = serpy.IntField()
y = serpy.Field()
z = serpy.Field()
f = Foo(1)
FooSerializer(f).data
# {'x': 1, 'y': 'hello', 'z': 9.5}
fs = [Foo(i) for i in range(100)]
FooSerializer(fs, many=True).data
# [{'x': 0, 'y': 'hello', 'z': 9.5}, {'x': 1, 'y': 'hello', 'z': 9.5}, ...]
Nested Example
import serpy
class Nestee(object):
"""An object nested inside another object."""
n = 'hi'
class Foo(object):
x = 1
nested = Nestee()
class NesteeSerializer(serpy.Serializer):
n = serpy.Field()
class FooSerializer(serpy.Serializer):
x = serpy.Field()
# Use another serializer as a field.
nested = NesteeSerializer()
f = Foo()
FooSerializer(f).data
# {'x': 1, 'nested': {'n': 'hi'}}
Complex Example
import serpy
class Foo(object):
y = 1
z = 2
super_long_thing = 10
def x(self):
return 5
class FooSerializer(serpy.Serializer):
w = serpy.Field(attr='super_long_thing')
x = serpy.Field(call=True)
plus = serpy.MethodField()
def get_plus(self, obj):
return obj.y + obj.z
f = Foo()
FooSerializer(f).data
# {'w': 10, 'x': 5, 'plus': 3}
License
serpy is free software distributed under the terms of the MIT license. See the LICENSE file.
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
serpy-0.0.2.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for serpy-0.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7e7973cb5724fc9580245265b8851687789205ac1574f32f53ef40aa9ad8dae |
|
MD5 | cb463dcbc5baec4a28b73ad46185cbea |
|
BLAKE2b-256 | 3c1bb4935f0fac37dc282e4686d199ef1b26751b3f09dfe9eb5db997388037c5 |