Skip to main content

Encode tuples of primitive types into bytestrings preserving the lexicographic order

Project description

title: Lexicographic Encoding

Lexicographic Encoding

Easily encode tuples of primitive types to bytestrings preserving lexicographic encoding. This means that you can later order the resulting bytestring and you will maintain the order of tuples.

Use Cases

Typically key-value stores only allow to use bytestrings as keys, which are a little awkward to work with if one needs a bit of structure on them. For example LevelDB offers a custom comparator to deal with such a situation, but many other storages do not.

This package allows you to free from such constraint, using an encoding that maintains the inherent ordering.


The project is to be considered beta. The provided API won't change, but it has not been tested in real-world yet (it has a big automated test suite though).

Any feedback will be appreciated. For any question or bug report please open an issue.

Quick Example

from lexicographic_encoding import lexpackb, lexunpackb, is_prefix_of

# Then pack everything preserving lexicographic order
# The following are all True
lexpackb(-1) > lexpackb(-2)
lexpackb(102) > lexpackb(20)
lexpackb(("Tom", 109)) > lexpackb(("Tom", 18))


Documentation of the project can be found here.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lexicographic-encoding, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size lexicographic-encoding-0.1.1.tar.gz (17.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page