Twisted based asynchonous python steem API
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 3 commits ahead, 27 commits behind pibara-utopian:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
asyncsteem
examples
.gitignore
LICENSE
README.md
TODO.md
setup.py

README.md

asyncsteem3

Twisted based asynchonous python STEEM JSON-RPC API.

This project is a Python 3 port of asyncsteem, which aims to implement a complete asynchronous alternative to steem-python. It is designed to work with the defacto Python asynchonous networking framework twisted. Twisted is the only dependency for asyncsteem3.

The current beta does not yet implement cryptographic signing operations that would be needed to, post, vote, etc. However, it is easy to create bots for collecting stats or dispatching alerts by monitoring the blockchain with minimal boilerplate code.

If you wish to stay informed on the progress of asyncsteem, please follow @mattockfs on steemit or join this discord server. Donations for this project in the form of STEEM or in the form of steemit post upvotes are very much welcomed, as are pull requests with features or bug fixes.

Install

A setup.py file is included, if you wish to install the package.

python setup.py install

Usage

See examples/print_votes.py for a simple bot that spits out info about votes happening on the Steem blockchain.

class DemoBot(object):
    def vote(self,tm,vote_event,client):
        w = vote_event["weight"]
        if w > 0:
            print("Vote by",vote_event["voter"],"for",vote_event["author"])
        else:
            if w < 0:
                print("Downvote by",vote_event["voter"],"for",vote_event["author"])
            else:
                print("(Down)vote by",vote_event["voter"],"for",vote_event["author"],"CANCELED")

A bot class can implement one or more of the following methods, which are called whenever a new event of that type arrives:

  • account_create
  • account_create_with_delegation
  • account_update
  • account_witness_proxy
  • account_witness_vote
  • cancel_transfer_from_savings
  • change_recovery_account
  • claim_reward_balance
  • comment
  • comment_options
  • convert
  • custom
  • custom_json
  • delegate_vesting_shares
  • delete_comment
  • feed_publish
  • limit_order_cancel
  • limit_order_create
  • recover_account
  • request_account_recovery
  • set_withdraw_vesting_route
  • transfer
  • transfer_from_savings
  • transfer_to_savings
  • transfer_to_vesting
  • vote
  • withdraw_vesting
  • witness_update

These methods map one on one to the operation types that are found on the blockchain. For convenience, the following methods may also be implemented:

  • transaction
  • block
  • hour
  • day
  • week

Rewind

You may also instead opt to pick a day in the past where the bot should start streaming. This could come in handy if you want to test your code, or if you want to limit your bot's online time.

blockchain = ActiveBlockChain(reactor,rewind_days=7)

Other API Methods

While the core of the library is aimed at streaming operations from the blockchain, it is likely your bot will need to query other JSON-RPC API's as well. For this, the client argument of the bots methods provides the entry point. But note, the API is asynchonous and works through a command queue and a client pool. Let us zoom in a bit on how to use the client argument in our code.

    def vote(self,tm,vote_event,client):
        def process_vote_content(event, client):
            for vote in  event["active_votes"]:
                if vote["voter"] == vote_event["voter"] and vote["rshares"] != 0:
                    print( vote["time"],vote["voter"],"=>",vote_event["author"],vote["rshares"])
        opp = client.get_content(vote_event["author"],vote_event["permlink"])
        opp.on_result(process_vote_content)

Basically, you define a closure for handling the additional API query, you put the command you wish to invoke on the asynchonous command queue and then you bind the result to your closure that will be invoked asynchonously when the command on the queue has been handled by the HTTPS client pool.

In some cases, a JSON-RPC call may return an error for your command. You may create an other callback for the error situation:

   def err_handler(errno, msg, rpcclient):
       print("OOPS:",msg,"(",errno,")")
   opp.on_error(err_handler)

You've seen the example using get_content, this is one of a wide range of JSON-RPC API calls available through the API. The API is fully transperant, so any silly typo you make will result in a bogus JSON-RPC call to one of the STEEM API nodes. For convenience, here is a list of currently commonly available valid API method names:

  • get_account_bandwidth
  • get_account_count
  • get_account_history
  • get_account_references
  • get_account_votes
  • get_accounts
  • get_active_votes
  • get_active_witnesses
  • get_block
  • get_block_header
  • get_chain_properties
  • get_comment_discussions_by_payout
  • get_config
  • get_content
  • get_content_replies
  • get_conversion_requests
  • get_current_median_history_price
  • get_discussions_by_active
  • get_discussions_by_author_before_date
  • get_discussions_by_blog
  • get_discussions_by_cashout
  • get_discussions_by_children
  • get_discussions_by_comments
  • get_discussions_by_created
  • get_discussions_by_feed
  • get_discussions_by_hot
  • get_discussions_by_payout
  • get_discussions_by_promoted
  • get_discussions_by_trending
  • get_discussions_by_votes
  • get_dynamic_global_properties
  • get_escrow
  • get_expiring_vesting_delegations
  • get_feed_history
  • get_hardfork_version
  • get_key_references
  • get_liquidity_queue
  • get_miner_queue
  • get_next_scheduled_hardfork
  • get_open_orders
  • get_ops_in_block
  • get_order_book
  • get_owner_history
  • get_post_discussions_by_payout
  • get_potential_signatures
  • get_recovery_request
  • get_replies_by_last_update
  • get_required_signatures
  • get_reward_fund
  • get_savings_withdraw_from
  • get_savings_withdraw_to
  • get_state
  • get_tags_used_by_author
  • get_transaction
  • get_transaction_hex
  • get_trending_tags
  • get_vesting_delegations
  • get_withdraw_routes
  • get_witness_by_account
  • get_witness_count
  • get_witness_schedule
  • get_witnesses
  • get_witnesses_by_vote
  • lookup_account_names
  • lookup_accounts
  • lookup_witness_accounts
  • set_block_applied_callback
  • verify_account_authority
  • verify_authority

Documentation for steemd API calls can be found on GitHub. Often the error messages can provide some info on correct usage—use an on_error callback to print the error.

Both asyncsteem and asyncsteem3 are beta releases. Please report any issues with asyncsteem3 to its own GitHub repository so they can be addressed or forwarded to asyncsteem as appropriate.