jsonable 0.3.1


pip install jsonable

  Latest version

Released: Oct 01, 2015

Project Links

Meta
Author: Aaron Halfaker

Classifiers

Development Status
  • 4 - Beta

Programming Language
  • Python
  • Python :: 3

Environment
  • Other Environment

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • OS Independent

Topic
  • Software Development :: Libraries :: Python Modules

This library provides and abstract base class JSONable which enables easy definition of trivially JSON-able python objects.

  • Installation: pip install jsonable

Example:
>>> import jsonable
>>>
>>>
>>> class Fruit(jsonable.Type):
...     __slots__ = ('type', 'weight')
...
...     def initialize(self, type, weight):
...         self.type   = str(type)
...         self.weight = float(weight)
...
>>> class Pie(jsonable.Type):
...     __slots__ = ('fruit',)
...
...     def initialize(self, fruit):
...         self.fruit = [Fruit(f) for f in fruit]
...
...
>>> pie = Pie([Fruit('apple', 10.3), Fruit('cherry', 2)])
>>>
>>> doc = pie.to_json()
>>> doc
{'fruit': [{'weight': 10.3, 'type': 'apple'}, {'weight': 2.0, 'type': 'cherry'}]}
>>>
>>> pie == Pie(doc)
True

Wheel compatibility matrix

Platform Python 2 Python 3
any

Files in release

No dependencies