Python2 & 3 C Extension for serializing certain built-in Python types
kimchi
offers functionality very similar to the default pickle
module. Unlike pickle
though, kimchi
cannot serialize generic Python objects and classes. kimchi
can only serialize built in Python objects - in particular:
- Integers (only in Python2)
- Floats
- Longs
- Strings (Bytes in Python3)
- Unicodes (Strings in Python3)
- Lists
- Tuples
- Sets
- Frozensets
- Dictionaries
- None objects
- Booleans
However, for most objects kimchi
performs serialization faster than the built-in pickle
library, and more importantly, produces more compact objects.
kimchi has two single argument functions, loads
and dumps
. dumps
is used to create serializations of objects, and loads
is used to recreate the original object given its serialization.
$ git clone https://github.com/warrenspe/kimchi.git
$ cd kimchi
$ sudo python3 setup.py install
>>> import kimchi
>>> serialization = kimchi.dumps(123)
>>> serialization
'\x01\x81{'
>>> kimchi.loads(serialization)
123
>>> serialization = kimchi.dumps('123')
>>> serialization
'\x05\x83123'
>>> kimchi.loads(serialization)
'123'
>>> serialization = kimchi.dumps([1, 2, 3, ('4', '5', '6')])
>>> serialization
'\x08\x96\x84\x01\x81\x01\x01\x81\x02\x01\x81\x03\t\x8a\x83\x05\x814\x05\x815\x05\x816'
>>> kimchi.loads(serialization)
[1, 2, 3, ('4', '5', '6')]
Note that all tests were done in Python2, comparing to its cPickle module
Note: constant size, might be revisited later
Note that the final string was not included in the size comparison, as the size skews the axis of the graph. The serialized sizes are: kimchi: 1003, pickle: 1008
Note that the final unicode string was not included in the size comparison, as the size skews the axis of the graph. The serialized sizes are: kimchi: 1003, pickle: 1006
Note: Speed and size for the following types is largely influenced by the items within them, to give the best results they have been filled with the data type which gives the most similar serialization times and sizes between pickle and kimchi, string/bytes objects.