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.0.tar.gz (136.7 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.0-py3-none-any.whl (50.4 kB view details)

Uploaded Python 3

File details

Details for the file evrmore-rpc-1.2.0.tar.gz.

File metadata

  • Download URL: evrmore-rpc-1.2.0.tar.gz
  • Upload date:
  • Size: 136.7 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.0.tar.gz
Algorithm Hash digest
SHA256 704e083997f0bec709767151e84c2541a25b40423a9fd470a9e91a7d650ff69d
MD5 0f466a8056de9f93808f1c84c738643d
BLAKE2b-256 b59607d5caa23e592b4d10a9d8ddfe30926a8716b838f8eeee3424d212bfea23

See more details on using hashes here.

File details

Details for the file evrmore_rpc-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: evrmore_rpc-1.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6e06789fe0d4275f02338bafd5d553a5b2c08b6c142ff9f1a3bf4f853cf74bc
MD5 4162f22bf84e9c722a8e40a4633bd7a1
BLAKE2b-256 8a0e3f9358798968048156621dc4a660306c1615b65475a19b12ceb1c2cb847c

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