Skip to main content

A simple blockchain package.

Project description


Install and update using pip:

$ pip install tinyblock


dict({'previous_hash'(str): '...',
      'timestamp'(int): '...',
      'data'(any): '...',
      'nonce'(int): '...',
      'next_hash'(str): '...'})


  • Define a simple blockchain:

    from tinyblock import tinyblock
    #The initial variable should be a list of blocks. If not set it, the default chain would be an empty list.
    my_blockchain = tinyblock()
  • Add a block to the chain:

    #The parameter is the data of this block
    my_blockchain.add('This is a block.')
  • Find a block with statement:

    #Find the blocks with features below. The return elements will content the index in origin chain list.
    #Completely match: previous_hash, nonce, next_hash.
    #Partly match: data. (Currently support str, int, float, list, dict, bool and tuple)
    #Range match: timestamp.(Could be an int, list or tuple)
    my_blockchain.find(previous_hash='', timestamp='', data='', nonce='', next_hash='')
  • Pop the last block of the chain:

  • Check wether the blockchain is anything correct:

  • Fix the blockchain(with start and stop index):

    my_blockchain.chainFix(start=0, stop=4)
  • Get the block list:

  • Customise the rule for mining new block:

    #The default rule is hash start with '0000'.
    #To change the rule, you can override the mineRule function.
    def newRule(hash):
        if hash[0:5] == '0'*5:
            return True
        return False
    my_blockchain.mineRule = newRule

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 tinyblock, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size tinyblock-0.2.0-py2.py3-none-any.whl (6.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size tinyblock-0.2.0.tar.gz (4.0 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 Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page