Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/msabramo/python-anyserializer
Uniform interface to various serializers (e.g.: pickle, json, yaml, phpserialize, etc.)
https://github.com/msabramo/python-anyserializer
Last synced: 28 days ago
JSON representation
Uniform interface to various serializers (e.g.: pickle, json, yaml, phpserialize, etc.)
- Host: GitHub
- URL: https://github.com/msabramo/python-anyserializer
- Owner: msabramo
- Created: 2011-11-21T16:26:25.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2012-05-31T20:20:01.000Z (over 12 years ago)
- Last Synced: 2024-05-09T20:39:36.036Z (8 months ago)
- Language: Python
- Homepage:
- Size: 273 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
python-anyserializer
=========================.. image:: https://secure.travis-ci.org/msabramo/python-anyserializer.png?branch=master
:target: http://travis-ci.org/msabramo/python-anyserializerA uniform interface to a bunch of different ways to serialize data in Python.
There are a plethora of ways to serialize data in Python, but they often have
annoyingly different interfaces.For example:
- json_ and pickle_ - use ``dumps``
- yaml (PyYAML_) - uses ``dump``
- plistlib_ and biplist_ - use ``writePlistToString``
- etc.This makes it a bit annoying when you're writing software and want to be able
to let the user specify different serialization formats.Some frameworks have developed useful abstractions for serialization. For
example, `Django's serialization framework
`_. But this is
unnecessarily tied to the Django framework and the Django ORM. Serialization is
a general problem that is not specific to any framework.Things shouldn't be this way.
::
>>> anyserializer.serialize('json', {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}})
'{"a": 1, "c": {"e": 4, "d": 3}, "b": 2}'
>>> anyserializer.serialize('yaml', {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}})
'a: 1\nb: 2\nc: {d: 3, e: 4}\n'
>>> anyserializer.serialize('pickle', {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}})
"(dp1\nS'a'\nI1\nsS'c'\n(dp2\nS'e'\nI4\nsS'd'\nI3\nssS'b'\nI2\ns."
>>> anyserializer.serialize('phpserialize', {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}})
'a:3:{s:1:"a";i:1;s:1:"c";a:2:{s:1:"e";i:4;s:1:"d";i:3;}s:1:"b";i:2;}'
>>> anyserializer.serialize('plist', {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}})
'\n\n\n\n\ta\n\t1\n\tb\n\t2\n\tc\n\t\n\t\td\n\t\t3\n\t\te\n\t\t4\n\t\n\n\n'
>>> anyserializer.serialize('biplist', {'a': 1, 'b': 2, 'c': {'d': 3, 'e': 4}})
'bplist00bybiplist1.0\x00\xd3\x01\x02\x03\x04\x05\x06QaQcQb\x10\x01\xd2\x07\x08\t\nQeQd\x10\x04\x10\x03\x10\x02\x15\x1c\x1e "$1)+-/\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x003'.. _PyYAML: http://pyyaml.org/
.. _pickle: http://docs.python.org/library/pickle.html
.. _json: http://docs.python.org/library/json.html
.. _plistlib: http://docs.python.org/library/plistlib.html
.. _biplist: http://pypi.python.org/pypi/biplist/