Giter Club home page Giter Club logo

multihash's Introduction

MultiHash v2.0.1

CI Coverage Documentation Status Updates Code style: black

Wraps hashlib.hash instances for easily computing multiple hashes at the same time.

See the full documentation at https://bnb-MultiHash.readthedocs.io

A convenience class for computing multiple hashes at the same time from a single source.

This class optimizes disk reads per computation, but does not implement threading or multiprocessing.

Provides the same interface as hashlib.hash classes with properties returning dictionaries of results using the hash's name as the key, excluding .name, which returns a MultiHash specific name.

The class provides an additional_hashers set where other classes conforming the hashlib.hash interface, or classes which override existing hashlib.hash classes functionalities may be placed in order for instances of MultiHash to utilize them.

Usage

Computing the hash(es) of some data in RAM

>>> from multihash import MultiHash
>>> MultiHash(b"This is a test", hashers=['md5', 'sha256']).hexdigest()
{'sha256': 'c7be1ed902fb8dd4d48997c6452f5d7e509fbcdbe2808b16bcf4edce4c07d14e', 'md5': 'ce114e4501d2f4e2dcea3e17b546f339'}

Utilizing the .update() method

>>> from multihash import MultiHash
>>> x = MultiHash(hashers=['md5', 'sha256'])
>>> x.update(b"this is some data")
>>> x.update(b"and this is some more")
>>> x.hexdigest()
{'md5': '8dcdbfc187e97b7f8817b7fe857c7635', 'sha256': 'a88897eb17993ace17bdb55f60bce7afc37156a939c3b217d4cb31fd2ade5848'}

Computing the hash(es) of a file

>>> from multihash import MultiHash
>>> with open('test_file', 'wb') as f:
...     f.write(b"blahblahblahblahblahblahblah")
>>> MultiHash.from_filepath('test_file', hashers=['md5', 'sha256']).hexdigest()
{'md5': '4ca3f52a8a3c1643708cce5e9a919b43', 'sha256': 'a2c56fb21bee151494b5d3bb40ed3e3d357b2014c82bb937f0d181dd43124fea'}

Computing the hash(es) of a stream/file like object/thing that implements .read()

>>> from os import urandom
>>> from io import BytesIO
>>> MultiHash.from_Stream(BytesIO(urandom(256)), hashers=['md5', 'sha256']).hexdigest()
{'md5': 'bd5c3a82f88ed4d903f4c30a21b827b6', 'sha256': 'a799b79935c54af47704d3b8421c83989b0cbc4078dd5a94aa8036a4912ae27e'}

Installation

  • $ git clone https://github.com/bnbalsamo/MultiHash.git
  • $ cd MultiHash
    • If you would like to install the pinned dependencies, run pip install -r requirements.txt
  • $ python -m pip install .

Development

Quickstart

To quickly install + configure a development environment...

Install pyenv, pyenv-virtualenv, and xxenv-latest and copy the following into your terminal while in the repository root.

[[ `type -t pyenv` ]] && \
[ -s "$PYENV_ROOT/plugins/pyenv-virtualenv" ] && \
[ -s "$PYENV_ROOT/plugins/xxenv-latest" ] && \
pyenv latest install -s 3.8 && \
PYENV_LATEST_38=$(pyenv latest -p 3.8) && \
pyenv latest install -s 3.7 && \
PYENV_LATEST_37=$(pyenv latest -p 3.7) && \
pyenv latest install -s 3.6 && \
PYENV_LATEST_36=$(pyenv latest -p 3.6) && \
pyenv virtualenv "$PYENV_LATEST_38" "MultiHash" && \
pyenv local "MultiHash" "$PYENV_LATEST_38" "$PYENV_LATEST_37" "$PYENV_LATEST_36" && \
pip install -e .[dev,tests,docs]

Manual Configuration

If you choose not to use the quickstart script you will need to...

  • Create a virtual environment
  • Install the development dependencies
    • pip install -e .[dev,tests,docs]
  • Configure tox so that it can access all relevant python interpreters

Running Tests

$ inv run.tests

Running autoformatters

$ inv run.autoformatters

Pinning Dependencies

$ inv pindeps

Author

Brian Balsamo [email protected]

Created using bnbalsamo/cookiecutter-pypackage v0.38.0

multihash's People

Contributors

bnbalsamo avatar

Watchers

James Cloos avatar  avatar

multihash's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.