Quipu is a binary encoding format similar to BSON for nested hierarchies of primitive types. It is intended as an alternative wire format to JSON, more suitable for interoperability between high level and low level languages. It prioritises simplicity for easy handling.
Quipu supports the following types:
- Quad integers
- Double-precision floats
- Byte arrays
- Strings
- Lists
- Tuples
Lists and tuples pair well with Python's pattern matching syntax.
>>> import quipu
>>> b = quipu.encode((10, 20.0, b'30', '40', ['50', '60']))
>>> b
b'\x00\x13\x003\x00\x05\x01\x00\x00\x00\x00\x00\x00\x00\n\x02@4\x00\x00\x00\x00\x00\x00\x10\x00\x02\x00\x0230\x11\x00\x02\x00\x0240\x12\x00\x0e\x00\x02\x11\x00\x02\x00\x0250\x11\x00\x02\x00\x0260'
>>> quipu.decode(b)
(10, 20.0, b'30', '40', ['50', '60'])
>>>
Dictionaries encode for ease-of-use, but are represented as lists of two-tuple key/value pairs and must be reconstructed if desired:
>>> quipu.decode(quipu.encode({'hello': 'world', 'this': 'is', 'a': 'test'}))
[('hello', 'world'), ('this', 'is'), ('a', 'test')]
Install directly from the repo, it's not in PyPi:
python -m pip install git+ssh://github.com/hauntedsand/quipu.git