Skip to main content

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.

PyPI version Python Versions License: MIT Documentation Status

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


Download files

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

Source Distribution

evrmore_rpc-1.2.1.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

evrmore_rpc-1.2.1-py3-none-any.whl (50.4 kB view details)

Uploaded Python 3

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

Hashes for evrmore_rpc-1.2.1.tar.gz
Algorithm Hash digest
SHA256 494eedda98b105fad13f4c4c587b6256fd9d8136cfa989f6da172b600b49a6da
MD5 73c759c34abbe0b012773b520fcfa3a8
BLAKE2b-256 d3d011c7a5e4d8f3760f03f7a761fb8549887d7ac873c144abc97b5cbc408e02

See more details on using hashes here.

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

Hashes for evrmore_rpc-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f191fde7ea8a648b9e8be5b294e99cf4120787b4d0b4482dd28bafb10c7b3f59
MD5 d3fbcd54dbf5378eb17d3b3c79b23e5d
BLAKE2b-256 02a887b9569048cb33839272a8a0275c6eff58c38e570c3079c9a42d13af6a05

See more details on using hashes here.

Supported by

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