A comprehensive, typed Python wrapper for Evrmore blockchain with ZMQ and WebSockets support
Project description
evrmore-rpc
A comprehensive, typed Python wrapper for Evrmore blockchain with ZMQ and WebSockets support.
Overview
evrmore-rpc is a powerful Python library that provides a clean, typed interface to interact with the Evrmore blockchain. It offers both synchronous and asynchronous APIs, ZMQ support for real-time notifications, and WebSockets for building responsive applications.
Features
- โจ Fully Typed API: Complete type hints for all Evrmore commands with IDE autocomplete support
- ๐ Multiple APIs: Choose between synchronous, asynchronous, or WebSockets interfaces
- ๐ก Real-time Updates: ZMQ support for instant blockchain notifications
- ๐ Comprehensive Models: Pydantic models for all blockchain data structures
- ๐ฅ๏ธ CLI Tools: Command-line interface for quick blockchain interactions
- ๐จ Rich Output: Beautiful terminal output with the Rich library
- ๐ Extensive Documentation: Detailed guides, API references, and examples
- ๐งช Well-Tested: Comprehensive test suite ensuring reliability
Requirements
- Python 3.8 or higher
- evrmore-cli installed and accessible in your PATH
- ZMQ support in your Evrmore node (optional, for real-time notifications)
Installation
# Basic installation
pip install evrmore-rpc
# With development tools
pip install evrmore-rpc[dev]
# With WebSockets support
pip install evrmore-rpc[websockets]
# Full installation with all features
pip install evrmore-rpc[full]
Quick Start
from evrmore_rpc import EvrmoreRPCClient
# Initialize client
client = EvrmoreRPCClient()
# Get blockchain info
info = client.getblockchaininfo()
print(f"Current block height: {info.blocks}")
print(f"Current difficulty: {info.difficulty}")
# List assets
assets = client.listassets()
print(f"Found {len(assets)} assets")
# Get a specific asset
asset_info = client.getassetdata("EVRMORE")
print(f"Asset details: {asset_info}")
Usage Examples
Synchronous API
from evrmore_rpc import EvrmoreRPCClient
# Initialize with custom settings
client = EvrmoreRPCClient(
datadir="~/.evrmore",
rpcuser="myuser",
rpcpassword="mypass",
rpcport=8819,
testnet=False
)
# Get block by hash
block = client.getblock(
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
)
print(f"Block timestamp: {block.time}")
print(f"Block transactions: {len(block.tx)}")
# Issue an asset
result = client.issue(
"MYASSET",
1000,
"EVRxxxxxxxxxxxxxxxxxxxxx",
"EVRxxxxxxxxxxxxxxxxxxxxx"
)
print(f"Asset created with txid: {result}")
Asynchronous API
import asyncio
from evrmore_rpc import EvrmoreAsyncRPCClient
async def main():
# Initialize the async client
async with EvrmoreAsyncRPCClient() as client:
# Get blockchain info
info = await client.getblockchaininfo()
print(f"Current block height: {info.blocks}")
# Run multiple commands concurrently
block_hash = await client.getblockhash(1)
block, assets = await asyncio.gather(
client.getblock(block_hash),
client.listassets()
)
print(f"Block timestamp: {block.time}")
print(f"Found {len(assets)} assets")
# Run the async function
asyncio.run(main())
ZMQ Real-time Notifications
import asyncio
from evrmore_rpc.zmq.client import EvrmoreZMQClient
async def main():
# Create ZMQ client
client = EvrmoreZMQClient()
# Register transaction handler
@client.on_transaction
async def handle_transaction(notification):
print(f"New transaction: {notification.hex}")
# Register block handler
@client.on_block
async def handle_block(notification):
print(f"New block: {notification.hex}")
# Start client
await client.start()
# Run the async function
asyncio.run(main())
WebSockets API
import asyncio
from evrmore_rpc.websockets import EvrmoreWebSocketClient
async def main():
# Connect to WebSocket server
async with EvrmoreWebSocketClient("ws://localhost:8820") as client:
# Subscribe to new blocks
await client.subscribe("blocks")
# Handle incoming messages
async for message in client:
if message.type == "block":
print(f"New block: {message.data.hash}")
elif message.type == "transaction":
print(f"New transaction: {message.data.txid}")
# Run the async function
asyncio.run(main())
Command Line Interface
# Get blockchain info
evrmore-rpc getblockchaininfo
# Get block by hash
evrmore-rpc getblock "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
# Get JSON output
evrmore-rpc --json getblockcount
# Start interactive mode
evrmore-rpc --interactive
Example Applications
The package includes several example applications:
- balance_tracker: Track balances, transactions, and orders with a database backend
- blockchain_explorer: Real-time block and transaction viewer
- asset_monitor: Monitor asset issuance and transfers
- wallet_tracker: Track wallet balances and transactions
- reward_distributor: Distribute rewards to multiple addresses
- network_monitor: Monitor network statistics and peers
Configuration
Evrmore Node Configuration
To use ZMQ features, add these lines to your evrmore.conf:
# ZMQ configuration
zmqpubhashtx=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28332
zmqpubhashblock=tcp://127.0.0.1:28332
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubsequence=tcp://127.0.0.1:28332
Library Configuration
Configure through command line:
evrmore-rpc --datadir ~/.evrmore --rpcuser myuser --rpcpassword mypass getinfo
Or in Python:
# Synchronous client
client = EvrmoreRPCClient(
datadir="~/.evrmore",
rpcuser="myuser",
rpcpassword="mypass",
rpcport=8819
)
# Async client
async_client = EvrmoreAsyncRPCClient(
datadir="~/.evrmore",
rpcuser="myuser",
rpcpassword="mypass",
rpcport=8819
)
Project Structure
evrmore-rpc/
โโโ evrmore_rpc/ # Main package
โ โโโ __init__.py # Package exports
โ โโโ client.py # Synchronous RPC client
โ โโโ async_client.py # Asynchronous RPC client
โ โโโ cli.py # Command-line interface
โ โโโ interactive.py # Interactive console
โ โโโ utils.py # Utility functions
โ โโโ commands/ # RPC command wrappers
โ โ โโโ __init__.py
โ โ โโโ blockchain.py # Blockchain commands
โ โ โโโ assets.py # Asset commands
โ โ โโโ ...
โ โโโ models/ # Data models
โ โ โโโ __init__.py
โ โ โโโ base.py # Base models
โ โ โโโ ...
โ โโโ zmq/ # ZMQ support
โ โ โโโ __init__.py
โ โ โโโ client.py # ZMQ client
โ โ โโโ models.py # ZMQ data models
โ โ โโโ utils.py # ZMQ utilities
โ โโโ websockets/ # WebSockets support
โ โโโ __init__.py
โ โโโ client.py # WebSocket client
โ โโโ server.py # WebSocket server
โ โโโ models.py # WebSocket data models
โโโ examples/ # Example applications
โ โโโ balance_tracker/ # Balance tracking example
โ โโโ blockchain_explorer/ # Blockchain explorer example
โ โโโ ...
โโโ tests/ # Test suite
โ โโโ unit/ # Unit tests
โ โโโ integration/ # Integration tests
โ โโโ functional/ # Functional tests
โโโ docs/ # Documentation
โ โโโ api/ # API reference
โ โโโ examples/ # Example documentation
โ โโโ tutorials/ # Tutorials
โโโ setup.py # Package setup
โโโ pyproject.toml # Project configuration
โโโ requirements.txt # Dependencies
โโโ README.md # This file
Documentation
Full documentation is available at https://evrmore-rpc.readthedocs.io/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- The Evrmore development team for creating the blockchain
- All contributors to this project
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 evrmore_rpc-1.2.1.tar.gz.
File metadata
- Download URL: evrmore_rpc-1.2.1.tar.gz
- Upload date:
- Size: 44.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
494eedda98b105fad13f4c4c587b6256fd9d8136cfa989f6da172b600b49a6da
|
|
| MD5 |
73c759c34abbe0b012773b520fcfa3a8
|
|
| BLAKE2b-256 |
d3d011c7a5e4d8f3760f03f7a761fb8549887d7ac873c144abc97b5cbc408e02
|
File details
Details for the file evrmore_rpc-1.2.1-py3-none-any.whl.
File metadata
- Download URL: evrmore_rpc-1.2.1-py3-none-any.whl
- Upload date:
- Size: 50.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f191fde7ea8a648b9e8be5b294e99cf4120787b4d0b4482dd28bafb10c7b3f59
|
|
| MD5 |
d3fbcd54dbf5378eb17d3b3c79b23e5d
|
|
| BLAKE2b-256 |
02a887b9569048cb33839272a8a0275c6eff58c38e570c3079c9a42d13af6a05
|