Skip to main content

Lightweight Bitcoin JSON-RPC Python asynchronous client

Project description

bitcoin-python-async-rpc

Lightweight Bitcoin async JSON-RPC Python client.

Serves as a tiny layer between an application and a Bitcoin daemon, its primary usage is querying the current state of Bitcoin blockchain, network stats, transactions...

If you want complete Bitcoin experience in Python, consult python-bitcoinlib.

Installation

$ pip install bitcoinrpc

Supported methods

Here is a list of supported methods, divided by their categories. Should you need method not implemented, wrap the call in BitcoinRPC.acall(<your_method>, ...) coroutine.

Blockchain

Method Supported?
getbestblockhash
getblock
getblockchaininfo
getblockcount
getblockhash
getblockheader
getblockstats
getchaintips
getdifficulty
getmempoolinfo
getnetworkhashps

Mining

Method Supported?
getmininginfo

Network

Method Supported?
getconnectioncount
getnetworkinfo

Raw transactions

Method Supported?
getrawtransaction

Usage

Minimal illustration (assuming Python 3.8+, where you can run async code in console)

$ python -m asyncio
>>> import asyncio
>>>
>>> from bitcoinrpc import BitcoinRPC
>>> rpc = BitcoinRPC("127.0.0.1", 8332, "rpc_user", "rpc_passwd")
>>> await rpc.getconnectioncount()
10
>>> await rpc.aclose()  # Clean-up resource

You can also use the BitcoinRPC as an asynchronous context manager, which does all the resource clean-up automatically, as the following example shows:

$ cat btc_rpc_minimal.py
import asyncio

from bitcoinrpc import BitcoinRPC


async def main():
    async with BitcoinRPC("localhost", 18443, "rpc_user", "rpc_password") as rpc:
        print(await rpc.getconnectioncount())


if __name__ == "__main__":
    asyncio.run(main())

Running this script yields:

$ python btc_rpc_minimal.py
10

License

MIT

Project details


Download files

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

Files for bitcoinrpc, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size bitcoinrpc-0.4.0-py3-none-any.whl (7.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size bitcoinrpc-0.4.0.tar.gz (7.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page