A modular, production-ready blockchain engine built from scratch.
Project description
📦 pybc-engine
A production-ready, modular blockchain engine built entirely from scratch in Python.
pybc-engine focuses on clean architecture, pluggable storage layers, and strict type safety. It serves as an excellent foundation for understanding distributed ledger technology, building local simulations, or extending into custom decentralized applications.
✨ Features
- Modular Architecture: Complete separation of concerns between Blocks, Transactions, Consensus, and Storage.
- Pluggable Storage System: Drop-in support for different databases. Includes both volatile (
MemoryStorage) and persistent (SQLiteStorage) out of the box. - Proof-of-Work Consensus: Implements a difficulty-based, deterministic mining algorithm.
- Cryptographic Integrity: Built-in validation utilities to guarantee the mathematical validity of the chain and prevent data tampering.
- Production Quality: 100% strictly type-hinted and highly optimized.
🚀 Installation
Install pybc-engine directly from PyPI using pip:
pip install pybc-engine
Requires Python 3.9 or higher.
💻 Quick Start
Building and mining your first local blockchain requires only a few lines of code:
from pybc import Blockchain, ProofOfWork
from pybc.storage.memory import MemoryStorage
# 1. Initialize your pluggable components
storage = MemoryStorage()
consensus = ProofOfWork(difficulty=4)
# 2. Start the engine
engine = Blockchain(storage=storage, consensus=consensus)
# 3. Add transactions to the mempool
engine.add_transaction(sender="Alice", receiver="Bob", amount=150.50)
# 4. Mine the block
new_block = engine.mine_new_block()
if new_block:
print(f"Mined Block #{new_block.index} with hash: {new_block.compute_hash()}")
print(f"Transactions recorded: {len(new_block.transactions)}")
🛠️ Advanced Usage: Persistent Storage
If you want your blockchain to persist across sessions, simply swap out the MemoryStorage for the SQLiteStorage backend. The engine handles the rest.
from pybc.storage.sqlite import SQLiteStorage
# This will automatically create and manage 'blockchain.db'
persistent_storage = SQLiteStorage(db_path="blockchain.db")
engine = Blockchain(storage=persistent_storage, consensus=consensus)
🤝 Contributing
Contributions are welcome! If you want to run the engine locally for development:
-
Clone the repository.
-
Install with development dependencies: pip install -e ".[dev]"
-
Run the test suite: pytest -v
-
Run type checking: mypy pybc
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybc_engine-0.1.0.tar.gz.
File metadata
- Download URL: pybc_engine-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d99a62cd183496ec0d67237b3b9e84961f43197da6d8d8c732dce72bc51c6da
|
|
| MD5 |
be8b83154842b9a2d75f675ddb8e5b35
|
|
| BLAKE2b-256 |
a6a6d8916f547b3c6a66a7a13a7bbd006b131919cf0164f15933e7a535607f48
|
File details
Details for the file pybc_engine-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pybc_engine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b939e3bd17aec80d1727af7a1dcd7fb2099b49b09cc068cd747eaf8337b27cb
|
|
| MD5 |
a1920c245f1c123f0500260a700ad798
|
|
| BLAKE2b-256 |
3734bde53619655fedc1d55c2ea109fe1b05ff3fd2803c4d4c502d7bd4740c7e
|