Skip to main content

Hash-chain log implementation

Project description


Coverage Status


  • Records are immutable
  • Records are ordered
  • It must be possible to check hash(Xi) for any i
  • hash(Xi) can be sent to anyone as a proof
  • hash(Xi) == hash(X, hash(Xi-1))
  • You do not need X to perform the check


$ pip install hlog


Getting started

# create a chain
c = Chain()

# send some messages
c.append(message="Alice gives 10.36 euros to Bob", amount=10.36, currency="EUR")
c.append(message="Bob gives 2 dollars to Alice", amount=2, currency="USD")

# you can loop through the chain records
used_currencies = set(r.fields["currency"] for r in c.records)

# call verify() to ensure records have not been modified

Raising an exception during validation


Verify will raise a ModifiedRecordException. It has 3 interesting attributes:

  • index: the index in the chain where validation starts to fail
  • message: a user-friendly message to indicate the error
  • record: the Record object itself


c = Chain()

rows = c.dump()

rows is a tuple of bytes, each item being one record of the chain.

Restoring from a dump

If you want to reconstruct your chain based on a file or database records, you can use Chain.from_dump()

c = Chain()

d = c.dump()

c2 = Chain.from_dump(d)


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 hlog, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size hlog-1.0.1.tar.gz (5.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page