Async Bitcoin RPC client
To work with Bitcoin RPC from python there is a library Python-BitcoinRPC.
But recently i need to call API from tornado application. Mentioned lib works in synchronous, i.e. blocking mode. For tornado it will be much better to use asynchronous version. Tried to search for existing solution, but can’t find it. So i create my async fork, that use tornado’s AsyncHTTPClient: https://github.com/st4lk/python-bitcoinrpc-tornado.
Example (print current number of blocks in Bitcoin network):
from bitcoinrpc_async.authproxy import AsyncAuthServiceProxy
from tornado import ioloop, gen
BITCOIN_RPC_URL = "http://user:password@127.0.0.1:8332"
@gen.coroutine
def show_block_count():
service = AsyncAuthServiceProxy(BITCOIN_RPC_URL)
result = yield service.getblockcount()
print result
io_loop = ioloop.IOLoop.instance()
io_loop.add_callback(show_block_count)
io_loop.start()