Skip to main content

Enhanced version of python-jsonrpc for Monero (monerod, monero-wallet-rpc).

Project description

# python-monerorpc

**python-monerorpc** is an improved version of python-jsonrpc for Monero (`monerod rpc`, `monero-wallet-rpc`).

**python-monerorpc** was originally forked from [**python-bitcoinrpc**](https://github.com/jgarzik/python-bitcoinrpc).

It includes the following generic improvements:

- HTTP connections persist for the life of the `AuthServiceProxy` object using `requests.Session`
- sends protocol 'jsonrpc', per JSON-RPC 2.0
- sends proper, incrementing 'id'
- uses standard Python json lib
- can optionally log all RPC calls and results
- JSON-2.0 batch support

It also includes some more specific details:

- sends Digest HTTP authentication headers
- parses all JSON numbers that look like floats as Decimal,
and serializes Decimal values to JSON-RPC connections.

## What does it do?
**python-monerorpc** communicates with monero over RPC.

That includes:
* `monerod rpc` as well as
* `monero-wallet-rpc`.

**python-monerorpc** takes over the actual HTTP request containing all the necessary headers.

## Compared to similar projects:
* [**monero-python**](https://github.com/emesik/monero-python)
- **monero-python**
- The module implements a json RPC backend (`monerod rpc`, `monero-wallet-rpc`).
- It implements implementations around this backend (accounts, wallets, transactions, etc. )
- It offers helpful utilities like a monero wallet address validator.
* A practical difference:
- Should a RPC method change or a new one should be added, **monero-python** would have to adapt its backend and the implementations around it, while with **python-monerorpc** you just have to modify the property or use a new method like:

```
rpc_connection.getbalance() -> rpc_connection.get_balance()

rpc_connection.new_method()
```


## Installation:

- change the first line of `setup.py` to point to the directory of your installation of python 2.*
- run `python setup.py install --user`

**Note**: This will only install `monerorpc`. If you also want to install `jsonrpc` to preserve
backwards compatibility, you have to replace `monerorpc` with `jsonrpc` in `setup.py` and run it again.

## Examples:

Example usage `monerod` (get info):

```
from monerorpc.authproxy import AuthServiceProxy, JSONRPCException

# initialisation, rpc_user and rpc_password are set as flags in the cli command
rpc_connection = AuthServiceProxy('http://{0}:{1}@127.0.0.1:18081'.format(rpc_user, rpc_password))
info = rpc_connection.get_info()
print(info)
# rpc_user and rpc_password can also be left out (testing, develop, not recommended)
rpc_connection = AuthServiceProxy('http://127.0.0.1:18081')
```

Example usage `monero-wallet-rpc` (get balance):

```
from monerorpc.authproxy import AuthServiceProxy, JSONRPCException

# initialisation, rpc_user and rpc_password are set as flags in the cli command
rpc_connection = AuthServiceProxy('http://{0}:{1}@127.0.0.1:18083'.format(rpc_user, rpc_password))
balance = rpc_connection.get_balance()
print(balance)
```

Example usage `monero-wallet-rpc` (make transfer):

```
from monerorpc.authproxy import AuthServiceProxy, JSONRPCException

# initialisation, rpc_user and rpc_password are set as flags in the cli command
rpc_connection = AuthServiceProxy('http://{0}:{1}@127.0.0.1:18083'.format(rpc_user, rpc_password))
destinations = {"destinations": [{"address": "some_address", "amount": 1}], "mixin": 10}
result = rpc_connection.transfer(destinations)
print(result)
```


## Logging:

Logging all RPC calls to stderr:

```
from monerorpc.authproxy import AuthServiceProxy, JSONRPCException

import logging
logging.basicConfig()
logging.getLogger("MoneroRPC").setLevel(logging.DEBUG)
rpc_connection = AuthServiceProxy('http://{0}:{1}@127.0.0.1:18081'.format(rpc_user, rpc_password))
print(rpc_connection.get_info())
```

Produces output on stderr like:

```
DEBUG:MoneroRPC:-1-> get_info []
DEBUG:MoneroRPC:<-1- {u'result': {u'incoming_connections_count': 0, ...etc }
```

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

python-monerorpc-0.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distributions

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

python_monerorpc-0.3-py3.6.egg (9.3 kB view details)

Uploaded Egg

python_monerorpc-0.3-py2.7.egg (9.4 kB view details)

Uploaded Egg

File details

Details for the file python-monerorpc-0.3.tar.gz.

File metadata

  • Download URL: python-monerorpc-0.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for python-monerorpc-0.3.tar.gz
Algorithm Hash digest
SHA256 33cbc3d981ea7aecef758e131b4c3157e098a7ebe6f119a690049c590008d513
MD5 48d39ccbb11e14051c22f6a3c060f8ae
BLAKE2b-256 ee8c6b2e67bea51202893ec68aa38110255abfef891b44fc986f91e1ef6ad062

See more details on using hashes here.

File details

Details for the file python_monerorpc-0.3-py3.6.egg.

File metadata

  • Download URL: python_monerorpc-0.3-py3.6.egg
  • Upload date:
  • Size: 9.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for python_monerorpc-0.3-py3.6.egg
Algorithm Hash digest
SHA256 a223e7ca5a4bfbcd765c385d37284424c8cb25d36423442e2fa42d2d84a1d78f
MD5 04cfb54fbf2f9cee8014372c5b99c830
BLAKE2b-256 fd2f73a0f7fccb459a34e39b29040e567bcf198131246b2b164bc59a4fd20287

See more details on using hashes here.

File details

Details for the file python_monerorpc-0.3-py2.7.egg.

File metadata

  • Download URL: python_monerorpc-0.3-py2.7.egg
  • Upload date:
  • Size: 9.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for python_monerorpc-0.3-py2.7.egg
Algorithm Hash digest
SHA256 065a84499c826050f7da1d59ee11489f23edd7bfe9a6b0e96b9ee1c978476bf0
MD5 2edfd8a0ba52c707c466381b232e4b10
BLAKE2b-256 41797be44a63da0cbaee683f758e23572940c34487969200bfd46a02ee9acb87

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