Skip to main content

binfootprint

PyPI version Build Status codecov

Description

This module intents to generate a binary representation of a python object where it is guaranteed that the same objects will result in the same binary representation.

By far not all python objects are supported. Here is the list of supported types

  • special build-in constants: True, False, None
  • integer
  • float (64bit)
  • complex (128bit)

as well as

  • tuples
  • lists
  • dictionaries
  • namedtuple

of the above.

Also

  • np.ndarray

are supported, however, as of changing details in the numpy implementation future version may of numpy may break backwards compatibility.

In the current version (0.2.x) of binfootprint, a numpy array is serialized using the (npy file format)[https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html#module-numpy.lib.format].

For any nested combination of these objects it is also guaranteed that the original objects can be restored without any extra information.

Additionally

  • 'getstate' (objects that implement `getstate and return a state that can be dumped as well)

can be dumped. To Restore these objects the load function needs a lookup given by the argument 'classes' which maps the objects class name (obj.__class__.__name__) to the actual class definition (the class object). Of course for these objects the __setstate__ method needs to be implemented.

Note: dumping older version is not supported anymore. If backwards compatibility is needed check out older code from git. If needed converters should/will be written.

Installation

pip

install the latest version using pip

pip install binfootprint

poetry

Using poetry allows you to include this package in your project as a dependency.

git

check out the code from github

git clone https://github.com/cimatosa/binfootprint.git

Examples

Generating the binary footprint and reconstruction is done as follows:

import binfootprint as bf

data = ['hallo', 42]
bin_key = bf.dump(data)

data_prime = bf.load(bin_key)
print(data_prime)

Further any class that implements __getstate__ may be used as a container as well. When reconstructing, the class needs to have the __setstate__ method implemented. Additionally the bf.load function required a mapping from the class name to the class object, like this:

import binfootprint as bf

class T(object):
    def __init__(self, a):
        self.a = a
    def __getstate__(self):
        return [self.a]
    def __setstate__(self, state):
        self.a = state[0]

ob = T(4)
bin_ob = bf.dump(ob)

# reconstruction
classes = {}
classes['T'] = T
ob_prime = bf.load(bin_ob, classes)

Note on numpy ndarrays

As it has not been clarified/tested yet whether the buffer of the numpy ndarray is really unique also on different machines and architectures is it not assured that the binary footprint serves as a valid key.

Download files

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

Source Distribution

binfootprint-0.2.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

binfootprint-0.2.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file binfootprint-0.2.1.tar.gz.

File metadata

  • Download URL: binfootprint-0.2.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.7 Linux/4.19.0-18-amd64

File hashes

Hashes for binfootprint-0.2.1.tar.gz
Algorithm Hash digest
SHA256 07ec38688a60090e7bad1d3d180cf44c4e3d65f9cc22956c4aa8f673a8d4944d
MD5 60daf33374ea96172169f89c95725fdc
BLAKE2b-256 3a69598f535369a8458312c068052b7fafc74ce8b618641ea50ee2a24d3d80e9

See more details on using hashes here.

File details

Details for the file binfootprint-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: binfootprint-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.7 Linux/4.19.0-18-amd64

File hashes

Hashes for binfootprint-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e4f828fe1635ad99bb2a399ff9e0d4ede6201a0658741943765ef8341cc8a0a3
MD5 70dcada873534aef0427adcae36a27a0
BLAKE2b-256 dae6c45341122bf3100dfa205129d883e592f4af3377f139b46f06230b5a105d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page