Author [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] Topic: [Python-API] python-bitsharesrpc  (Read 588 times)

0 Members and 1 Guest are viewing this topic.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12280
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
[Python-API] python-bitsharesrpc
« on: January 25, 2015, 05:54:08 PM »

python-bitsharesrpc
Python module for the BitShares client

Download
https://github.com/xeroc/python-bitsharesrpc

Installation
Code: [Select]
git clone https://github.com/xeroc/python-bitsharesrpc
cd python-bitsharesrpc
python setup install    # (optionally with parameter --user fo non-root installations)

Requirements
  • python-requests

Usage
All RPC commands of the BitShares client are exposed as methods in the class bitsharesrpc. Once an instance of bitsharesrpc is created, i.e.,

Code: [Select]
import bitsharesrpc
import config
rpc = bitsharesrpc.client(config.url, config.user, config.passwd)
any rpc command can be issued using the instance via the syntax rpc.command(parameters). Example:

Code: [Select]
rpc.get_info()
rpc.open_wallet("default")
rpc.ask(account, amount, quote, price, base)
...

Example to unlock the wallet
Code: [Select]
#!/usr/bin/python
import bitsharesrpc
import config

if __name__ == "__main__":
 rpc = bitsharesrpc.client(config.url, config.user, config.passwd)
 print(rpc.wallet_open(config.wallet))
 print(rpc.unlock(999999, config.unlock))

Example to lock the wallet
Code: [Select]
#!/usr/bin/python
import bitsharesrpc
import config

if __name__ == "__main__":
 rpc = bitsharesrpc.client(config.url, config.user, config.passwd)
 print rpc.wallet_open("delegate")
 print rpc.lock()

Minimalistic CLI:
Code: [Select]
#!/usr/bin/python
import bitsharesrpc, json
rpc = bitsharesrpc.client("http://localhost:1998/rpc", "username", "password")
while 1:
     cmd = raw_input(">>").split()
     print(json.dumps(rpc.rpcexec({"method":cmd[0],"params":list(cmd[1:]),
                                   "jsonrpc":"2.0","id":0}),indent=4))
« Last Edit: January 28, 2015, 02:10:14 PM by xeroc ¯\_(ツ)_/¯ »
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline mike623317

  • Hero Member
  • *****
  • Posts: 630
    • View Profile
Re: [Python-API] python-bitsharesrpc
« Reply #1 on: January 25, 2015, 06:31:13 PM »
So is this a potential vulnerability you fixed?

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12280
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: [Python-API] python-bitsharesrpc
« Reply #2 on: January 25, 2015, 06:57:12 PM »
So is this a potential vulnerability you fixed?
Hu? .. what vulnerability are you talking about?

The issues I recently fixed concerned the "genbtskey.py" script that replicated the generation of BTS pubkeys and addresses ..
The module in the OP is just a rewrite of the btsrpcapi.py class to make it alot easier to use and a standalone module ..

the only security issue I can see with this module is if people run this over the plain internet and not via tunnel .. I am unaware that the RPC can be run via SSL .. @toast ?
If it can run via SSL .. it's the responsibility of the coder to also ACCESS the RPC via SSL .. but if there is SSL available I could modify the script to ENFORCE the use of SSL if you wish


//edit: I reread you post and figured out yo meant it differently. The OP announces a python module that makes it alot easier to use inferface python with BitShares ..
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12280
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: [Python-API] python-bitsharesrpc
« Reply #3 on: January 28, 2015, 02:10:44 PM »
you can write a bitshares command line interface with just a few lines of python:
Minimalistic CLI:
Code: [Select]
#!/usr/bin/python
import bitsharesrpc, json
rpc = bitsharesrpc.client("http://localhost:1998/rpc", "username", "password")
while 1:
     cmd = raw_input(">>").split()
     print(json.dumps(rpc.rpcexec({"method":cmd[0],"params":list(cmd[1:]),
                                   "jsonrpc":"2.0","id":0}),indent=4))
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

 

Google+