Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eevee/camel
Python serialization for adults
https://github.com/eevee/camel
Last synced: 14 days ago
JSON representation
Python serialization for adults
- Host: GitHub
- URL: https://github.com/eevee/camel
- Owner: eevee
- License: other
- Created: 2015-10-20T03:01:11.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-12T18:36:33.000Z (7 months ago)
- Last Synced: 2024-10-22T14:37:28.129Z (22 days ago)
- Language: Python
- Size: 54.7 KB
- Stars: 154
- Watchers: 7
- Forks: 7
- Open Issues: 7
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Camel
=====Camel is a library that lets you describe how to serialize your objects to
YAML — and refuses to serialize them if you don't.Quick example:
.. code-block:: python
from camel import Camel, CamelRegistry
class DieRoll(tuple):
def __new__(cls, a, b):
return tuple.__new__(cls, [a, b])def __repr__(self):
return "DieRoll(%s,%s)" % selfreg = CamelRegistry()
@reg.dumper(DieRoll, u'roll', version=None)
def _dump_dice(data):
return u"{}d{}".format(*data)@reg.loader(u'roll', version=None)
def _load_dice(data, version):
a, _, b = data.partition(u'd')
return DieRoll(int(a), int(b))value = DieRoll(3, 6)
camel = Camel([reg])
print(camel.dump(value))# !roll 3d6
# ...Docs: http://camel.readthedocs.org/en/latest/
GitHub: https://github.com/eevee/camel