• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bitcoinrpc/H24-Aug-2016-197161

LICENSEH A D24-Aug-201625.3 KiB459383

MANIFEST.inH A D24-Aug-201655 43

PKG-INFOH A D24-Aug-20163.2 KiB8360

README.rstH A D24-Aug-20162.2 KiB7149

setup.pyH A D24-Aug-2016617 2016

README.rst

1=================
2python-bitcoinrpc
3=================
4
5AuthServiceProxy is an improved version of python-jsonrpc.
6
7It includes the following generic improvements:
8
9* HTTP connections persist for the life of the AuthServiceProxy object
10* sends protocol 'version', per JSON-RPC 1.1
11* sends proper, incrementing 'id'
12* uses standard Python json lib
13* can optionally log all RPC calls and results
14* JSON-2.0 batch support
15
16It also includes the following bitcoin-specific details:
17
18* sends Basic HTTP authentication headers
19* parses all JSON numbers that look like floats as Decimal,
20  and serializes Decimal values to JSON-RPC connections.
21
22Installation
23============
24
251. change the first line of setup.py to point to the directory of your installation of python 2.*
262. run setup.py
27
28Note: This will only install bitcoinrpc. If you also want to install jsonrpc to preserve
29backwards compatibility, you have to replace 'bitcoinrpc' with 'jsonrpc' in setup.py and run it again.
30
31Or simply install the library using pip::
32
33    pip install python-bitcoinrpc
34
35Example
36=======
37.. code:: python
38
39    from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
40
41    # rpc_user and rpc_password are set in the bitcoin.conf file
42    rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332"%(rpc_user, rpc_password))
43    best_block_hash = rpc_connection.getbestblockhash()
44    print(rpc_connection.getblock(best_block_hash))
45
46    # batch support : print timestamps of blocks 0 to 99 in 2 RPC round-trips:
47    commands = [ [ "getblockhash", height] for height in range(100) ]
48    block_hashes = rpc_connection.batch_(commands)
49    blocks = rpc_connection.batch_([ [ "getblock", h ] for h in block_hashes ])
50    block_times = [ block["time"] for block in blocks ]
51    print(block_times)
52
53Logging all RPC calls to stderr
54===============================
55.. code:: python
56
57    from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
58    import logging
59
60    logging.basicConfig()
61    logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG)
62
63    rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332"%(rpc_user, rpc_password))
64    print(rpc_connection.getinfo())
65
66Produces output on stderr like
67
68    DEBUG:BitcoinRPC:-1-> getinfo []
69    DEBUG:BitcoinRPC:<-1- {"connections": 8, ...etc }
70
71