Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clarkduvall/serpy
ridiculously fast object serialization
https://github.com/clarkduvall/serpy
Last synced: 3 days ago
JSON representation
ridiculously fast object serialization
- Host: GitHub
- URL: https://github.com/clarkduvall/serpy
- Owner: clarkduvall
- License: mit
- Created: 2015-03-30T07:29:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-08-18T04:39:32.000Z (about 4 years ago)
- Last Synced: 2024-10-28T23:54:59.424Z (6 days ago)
- Language: Python
- Homepage: http://serpy.readthedocs.org/en/latest/
- Size: 131 KB
- Stars: 957
- Watchers: 20
- Forks: 62
- Open Issues: 24
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-django-performance - serpy - A super simple object serialization framework built for speed. (Serialization / Tools)
- starred-awesome - serpy - ridiculously fast object serialization (Python)
README
*********************************************
serpy: ridiculously fast object serialization
*********************************************.. container:: badges
.. image:: https://travis-ci.org/clarkduvall/serpy.svg?branch=master
:target: https://travis-ci.org/clarkduvall/serpy?branch=master
:alt: Travis-CI.. image:: https://coveralls.io/repos/clarkduvall/serpy/badge.svg?branch=master
:target: https://coveralls.io/r/clarkduvall/serpy?branch=master
:alt: Coveralls.. image:: https://readthedocs.org/projects/serpy/badge/?version=latest
:target: https://readthedocs.org/projects/serpy/?badge=latest
:alt: Documentation Status.. image:: https://pypip.in/download/serpy/badge.svg
:target: https://pypi.python.org/pypi/serpy/
:alt: Downloads**serpy** is a super simple object serialization framework built for speed.
**serpy** serializes complex datatypes (Django Models, custom classes, ...) to
simple native types (dicts, lists, strings, ...). The native types can easily
be converted to JSON or any other format needed.The goal of **serpy** is to be able to do this *simply*, *reliably*, and
*quickly*. Since serializers are class based, they can be combined, extended
and customized with very little code duplication. 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/serpyIf you want a feature, send a pull request!
Documentation
=============
Full documentation at: http://serpy.readthedocs.org/en/latest/Installation
============
.. code-block:: bash$ pip install serpy
Examples
========Simple Example
--------------
.. code-block:: pythonimport serpy
class Foo(object):
"""The object to be serialized."""
y = 'hello'
z = 9.5def __init__(self, x):
self.x = xclass 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
--------------
.. code-block:: pythonimport 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
---------------
.. code-block:: pythonimport serpy
class Foo(object):
y = 1
z = 2
super_long_thing = 10def x(self):
return 5class 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.zf = Foo()
FooSerializer(f).data
# {'w': 10, 'x': 5, 'plus': 3}Inheritance Example
-------------------
.. code-block:: pythonimport serpy
class Foo(object):
a = 1
b = 2class ASerializer(serpy.Serializer):
a = serpy.Field()class ABSerializer(ASerializer):
"""ABSerializer inherits the 'a' field from ASerializer.This also works with multiple inheritance and mixins.
"""
b = serpy.Field()f = Foo()
ASerializer(f).data
# {'a': 1}
ABSerializer(f).data
# {'a': 1, 'b': 2}License
=======
serpy is free software distributed under the terms of the MIT license. See the
`LICENSE `_ file.