Structpack
A Python library for serializing and deserializing object trees to JSON-compatable values (dicts, lists, strings, ints, floats, bools)
Install / Use
/learn @Knio/StructpackREADME
structpack
A Python library for serializing and deserializing object trees to JSON-compatable values (dicts, lists, strings, ints, floats, bools).
Installation
The recommended way to install structpack is with pip:
pip install structpack
Examples
structpack is designed to be a base class (msg) that you inherit from and add properties to (bool, int, float, string, list, and dict).
The msg class adds methods pack and load which convert your object to and from native types, respectively.
The following is a trivial example of how to make a Point type using structpack
import structpack
class Point(structpack.msg):
x = structpack.float
y = structpack.float
z = structpack.float
>>> p1 = Point(1., 2., 3.)
>>> data = p1.pack()
>>> print data
(1.0, 2.0, 3.0)
>>> p2 = Point.load(data)
>>> print p2
<__main__.Point object at 0x0000000001EDA390>
>>> print p2.x, p2.y, p2.z
1.0 2.0 3.0
More
Please see the test suite for more examples until they are documented here.
TODO
- Docs / examples
- Type check values
- Benchmark & optimize


