Skip to main content

Easy Bitcoin RPC

Easy Bitcoin RPC is a simple and easy to use Python library for Bitcoin RPC

Installation

Use the package manager pip to install.

pip install easybitcoinrpc

Usage

Connecting

from easybitcoinrpc import RPC

# RPC() returns connection object

rpc = RPC() # defaults: ip=127.0.0.1, port=8332, user="user", password="password", wallet_name=None

rpc = RPC(user="rpcuser", password="rpcpassword")

rpc = RPC(ip="192.168.1.1", port=9999, user="rpcuser", password="rpcpassword")

rpc = RPC(wallet_name="Wallet")

Specifing wallet when connection is made is prefered method to get access to wallet, loading wallet after connecting sometimes dosn't work.

RPC methods

RPC object has methods for all Bitcoins RPC calls and those methods are seperated into sections as on Bitcoin RPC API Reference

from easybitcoinrpc import RPC
rpc = RPC()

rpc.blockchain # returns object which has all methods from blockchain category
rpc.wallet # returns object which has all methods from wallet category
rpc.util # returns object which has all methods from util category
rpc.mining # returns object which has all methods from mining category
rpc.network # returns object which has all methods from network category
rpc.generating # returns object which has all methods from generating category
rpc.control # returns object which has all methods from control category
rpc.transactions # returns object which has all methods from transactions category

rpc.client.call("getbestblockhash") # any RPC command can be called directly
rpc.client.call("getblock", block_hash, 2) # parameters follow the command

All methods have documentation copied from Bitcoin RPC API Reference, they also have parameters specified with their types and their default values.

Data

Methods for blocks and transactions return frozen dataclasses: Block, Transaction, Vin, Vout, ScriptSig, ScriptPubKey, TransactionSummary. Every field is a plain attribute and amounts are Decimal, never float.

from easybitcoinrpc import RPC

rpc = RPC()

block = rpc.blockchain.get_block(669376, 2)
print(block.height, block.mined_at, block.transaction_count)

for transaction in block.transactions:
    if transaction.is_segwit:
        print(transaction.txid, transaction.total_output)

get_block is overloaded on the verbosity: 0 returns the hex string, 1 and 2 return a Block, and only 2 fills block.transactions.

raw_hex = rpc.blockchain.get_block(669376, 0)
with_txids = rpc.blockchain.get_block(669376)
with_transactions = rpc.blockchain.get_block(669376, 2)

Batching

Anything that would otherwise be a loop of calls goes out as one JSON-RPC batch.

blocks = rpc.blockchain.get_blocks([669376, 669377, 669378])
transactions = rpc.transactions.get_transactions([first_txid, second_txid])

Transaction summary

TransactionSummary resolves the spent outputs into addresses and amounts. The funding transactions are fetched in a single batch.

summary = rpc.transactions.get_transaction_summary(txid)

for entry in summary.inputs:
    print(entry.address, entry.amount)

print(summary.total_input, summary.total_output, summary.fee)

The price is an argument, so the library never reaches out to a price feed on its own.

from decimal import Decimal

print(summary.value_in(Decimal("42000")))

Errors

A rejected call raises a subclass of RpcError carrying the node's code and message.

from easybitcoinrpc import RPC, WalletNotFoundError, AuthenticationError, RpcError

try:
    rpc.wallet.get_balance()
except WalletNotFoundError:
    ...
except AuthenticationError:
    ...
except RpcError as error:
    print(error.code, error.message)

Closing the connection

RPC keeps one pooled HTTP session and works as a context manager.

with RPC(user="rpcuser", password="rpcpassword") as rpc:
    print(rpc.blockchain.get_block_count())

Download files

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

Source Distribution

easybitcoinrpc-2.0.0.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

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

easybitcoinrpc-2.0.0-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

Details for the file easybitcoinrpc-2.0.0.tar.gz.

File metadata

  • Download URL: easybitcoinrpc-2.0.0.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for easybitcoinrpc-2.0.0.tar.gz
Algorithm Hash digest
SHA256 f4ffb8dac7f620be0df30941b61b12469de33d7fa7daf91d6b37cedb03640312
MD5 204007ea19957fb54096fc54fbcf203b
BLAKE2b-256 fa7eea3d33d03f5eb938ec3bdf854a9ef63e4bcab253641a5081ac258219c47c

See more details on using hashes here.

Provenance

The following attestation bundles were made for easybitcoinrpc-2.0.0.tar.gz:

Publisher: python-publish.yml on DorianKucharski/easybitcoinrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file easybitcoinrpc-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: easybitcoinrpc-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 44.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for easybitcoinrpc-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d13850c55f419419403edc66fae8ffa94f6791789c6a64708781a46f02daf880
MD5 ea681e354f2097aad0b691e9c1fa53da
BLAKE2b-256 daaf447c5661e3ac4123d4a853898d992c9fabbf8bb994634727d9d461be8472

See more details on using hashes here.

Provenance

The following attestation bundles were made for easybitcoinrpc-2.0.0-py3-none-any.whl:

Publisher: python-publish.yml on DorianKucharski/easybitcoinrpc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.1.1

2 files

1.1.0

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page