ESCODE binary serialization
Project description
Fast Serializing and Deserializing of Python types.
escode
is a Python C-Extension which quickly serializes and deserializes arbitrary base types into binary data.
The serialization has also been designed to be small. This is useful for storage and network applications. Finally,
the module provides index serialization for a tuple of data - where the serialization maintains sorting order against
all other tuples containing the same types in the same order (or prefixes).
import escode
data = {
"id": 1234,
"name":"Akhil",
"usernames": ["akhil", "awable"],
"location": {"lat": 28.7041, "lng":77.1025}
}
blob = escode.encode(data)
db.put(<id>,..., blob)
...
dbdata = escode.decode(db.get(<id>))
assert dbdata == data
Index encoding is useful for applications where a multi-attribute index must be maintained in a single binary field, while maintaining the sort order of the original tuples.
tuples = [
(1234, 'Akhil', 13.014492753623188),
(831, 'Rohit', 1.3086614173228346),
(844, 'Poornima', 1.2375366568914956),
(723, 'Mark', 2.0716332378223496),
(874, 'John', 4.065116279069767),
(94, 'Takkar', 0.09456740442655935)
]
tuple_encodings = [
(t, escode.encode_index(t))
for t in tuples]
# sorting by tuples is the same as sorting by the encodings
assert (sorted(tuple_encodings, key=lambda tup_enc: tup_enc[0]) ==
sorted(tuple_encodings, key=lambda tup_enc: tup_enc[1]))
A quick note on implementation: Index order of tuples can be tricky since one must maintain tuple
element boundaries which compare lower than any data. i.e. ('a','z') < ('aa', 'z')
but 'az' > 'aaz'
This is
accomplished in escode by using '\x00\x00'
as the boundary, and escaping \x00s
in the tuple elements themselves,
but compressing consecutive \x00s
to preserve space.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for escode-1.0.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d853369c2112f7ca64a221086ccda15535ce2ab90c6f2ab35503316db410b0 |
|
MD5 | 3aa47ebba4c9c870e7057d7dd49173ea |
|
BLAKE2b-256 | de73244dc8ad1d2776672ec1997fda239032973344c97073e07f0689e826b350 |
Hashes for escode-1.0.0-cp27-cp27m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45537a0b0766cf79eb05a29cafdf289905b45f3c1ac9b56baba4c4f342433bea |
|
MD5 | f3fdebd8beb675daf6f76687dad5fa76 |
|
BLAKE2b-256 | d37405fb1bea2e942c866b381bf0ea2791df4403721bd5c55e0db170e8bf300a |