Skip to main content

Python implementation and building blocks for blockchain

Project description

Pyzantium

Report Bug · Request Feature


🔗 Python implementation and building blocks for blockchain

Pyzantium is a python module that let you implement blockchain whit various capabilityies in your project.

The Module provide both high-level(Blockchain) and low-level(Block,Consensus, ...) classes in order to be highly customizable.


1. Installation

The package is pip installable:

pip install pybchain

Or, you can download it and use setuptools to build it by hand:

git clone http://github.com/rezamahdi/pybchain
cd pybchain
python setup.py install

2. Usage

To initialize a blockchain, you must specify some info as agreement:

  • Hash algorithm to use in blockchain.
  • Wath type of data you want to store. Blockchain is capable of storing anythin not only transactions.
  • An authentication scheme. Common way to do this is using ECC. this part is optional.
  • Endpoint to connect to other nodes. Common option is a HTTP api or json-rpc.

Whit having these options specified, you can initialize the node as this:

from pyzantium import Chain, Block
from pyzantium.storage import Disk
from hashlib import sha_256

chain = Chain(
  hash=sha_256,
  storage=Disk(
    "path/to/storage",
    create=True
  )
)

Next, in order to mine genesis block do this:

genesis = Block(chain)
genesis.add_part(b'000000000000000000000000000')  # or any other type of data.
# add more data parts...
genesis.finalize()  # we don't use `mine` because it is named `forge` in PoS.

result = endpoint.broadcast_new_block(genesis)

if result.is_ok():
  chain.append(genesis)

see documentation for more info

3. License

Copyright (c) Reza Mahdi 2022 This project is licensed under terms of MIT License (see LICENSE)

Project details


Download files

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

Source Distribution

pyzantium-0.0.2.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

pyzantium-0.0.2-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

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