create account

Python for STEEM #3: Modules by felixxx

View this thread on: hive.blogpeakd.comecency.com
· @felixxx ·
$11.18
Python for STEEM #3: Modules
>This is the third part to a series of tutorials.
The goal is to produce a hands-on guide for people who want to jump straight into developing tools for STEEM.

- [part1](https://steemit.com/busy/@felixxx/python-for-steem-how-to-beem)
-  [part2](https://steemit.com/busy/@felixxx/pyhton-for-steem-2-json)
___
## API
####
Whenever I query data 'from the blockchain', I have to connect to a node that runs the corresponding API plugin to my request. I just got reminded of how little I understand about [this](https://steemit.com/testnet/@felixxx/q0et70).
I will stick to what works for me and explain as best as I can.
For this guide I will treat the API like a black box and will look at beem's modules only. Most of beem's methods closely reflect the underlying API calls, though.

## Modules
####
These are beem's modules
https://beem.readthedocs.io/en/latest/modules.html

![image.png](https://ipfs.busy.org/ipfs/QmPYo93zhr7N9BxGbNrQZscYFqWbAACoHyZvpt7ss1CRrw)


In the last part, I used the ``blockchain`` module.
https://beem.readthedocs.io/en/latest/beem.blockchain.html

```
from beem.blockchain import Blockchain
blockchain = Blockchain()
```
This instantiates ``blockchain`` as of the class Blockchain like defined in:
https://github.com/holgern/beem/blob/master/beem/blockchain.py

In the documentation you can look up, which parameters the different methods accept and what data type they will return.

```
head_block = blockchain.get_current_block_num()
```
The method ``get_current_block_num``,  returns an ``int``.

## account.py
####
As an example, I will go through some methods of the ``account`` module;
https://beem.readthedocs.io/en/latest/beem.account.html

#### method: ``balances``
####
```
from beem.account import Account

test_account = Account(account = 'holger80')
print(test_account.balances)
```

This returns a dictionary, but the print() function will print it as a string automagically.

#### method: ``get_balances()``
####
```
from beem.account import Account

test_account = Account(account = "holger80")
print(test_account.get_balances())
```
This returns the same dictionary as the ``balances`` method does.

#### method: ``get_voting_power()``
####

beem has some higher level functions, which are abstracted from the raw API data:

```
from beem.account import Account

test_account = Account(account = "holger80")
print(test_account.get_voting_power())
print(test_account.get_voting_power(with_regeneration = False))
```
By default, the parameter ``with_regeneration`` is set to ``True``.
The regeneration however, is being calculated for you by beem.
The STEEM API will always only return the voting power at the time of the last vote.

## Account.history()
####
The ``history()`` method deserves its own chapter.
Sadly, the default node set in beem does not support it at the moment.
I have to set the node by hand like this:
```
from beem import Steem
from beem.instance import set_shared_steem_instance

steemit_api = Steem(node=["https://api.steemit.com"])
set_shared_steem_instance(steemit_api)
```

This makes our black box API work again.
Leave this in front of all examples from now on, for good measure.
____
For most purposes, ``history_reverse`` is the more useful function, but is derived from ``history`` anyways - It is just the other way around starting at the latest block, going backwards.

```
from beem.account import Account
from beem.blockchain import Blockchain

blockchain = Blockchain()
head_block = blockchain.get_current_block_num()

test_account = Account("holger80")

for operation in test_account.history_reverse(start = head_block, stop = head_block - 10000, use_block_num = True):
    print(operation)
```
This returns all operations during the last 10000 blocks for the specified account.
There are more examples in the documentation.

## Congratulations
####
This should enable you to explore all of beem's modules and methods.
If you want me to explain a specific method more closely, let me know in the comments or in chat. 

## Homework
####
Can you calculate the average of your last 10 curation rewards ?
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 59 others
πŸ‘Ž  
properties (23)
authorfelixxx
permlinkpython-for-steem-3-modules
categorybusy
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["busy","steem","python","beem","stem"],"users":["felixxx"],"links":["https://steemit.com/busy/@felixxx/python-for-steem-how-to-beem","https://steemit.com/busy/@felixxx/pyhton-for-steem-2-json","https://steemit.com/testnet/@felixxx/q0et70","https://beem.readthedocs.io/en/latest/modules.html","https://beem.readthedocs.io/en/latest/beem.blockchain.html","https://github.com/holgern/beem/blob/master/beem/blockchain.py","https://beem.readthedocs.io/en/latest/beem.account.html"],"image":["https://ipfs.busy.org/ipfs/QmPYo93zhr7N9BxGbNrQZscYFqWbAACoHyZvpt7ss1CRrw"]}
created2019-11-04 09:34:15
last_update2019-11-04 09:34:15
depth0
children12
last_payout2019-11-11 09:34:15
cashout_time1969-12-31 23:59:59
total_payout_value5.715 HBD
curator_payout_value5.464 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,084
author_reputation217,825,762,716,184
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,185,788
net_rshares36,938,340,964,964
author_curate_reward""
vote details (124)
@beerlover ·
<div class='pull-right'>https://cdn.steemitimages.com/DQmaHThyECGhEx8tSfHZbiMFRNYjJ35K92cDgiJjkzBUaJo/One%20sip%20of%20BEER%20for%20you.gif<p><sup><a href='https://steem-engine.com/?p=market&t=BEER'>View or trade </a> <code>BEER</code>.</sup></p></div><center><br><br> <p> Hey @felixxx, here is a little bit of  <code>BEER</code> for you. Enjoy it!</p> </center>
properties (22)
authorbeerlover
permlinkre-python-for-steem-3-modules-20191104t110834z
categorybusy
json_metadata"{"app": "beem/0.21.1"}"
created2019-11-04 11:08:36
last_update2019-11-04 11:08:36
depth1
children0
last_payout2019-11-11 11:08:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length362
author_reputation25,804,705,307,691
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,187,680
net_rshares0
@emrebeyler ·
Great series, have a !BEER.

Will work on the homework :)
πŸ‘  
properties (23)
authoremrebeyler
permlinkq0fyxy
categorybusy
json_metadata{"app":"steemit/0.1"}
created2019-11-04 11:08:24
last_update2019-11-04 11:08:24
depth1
children1
last_payout2019-11-11 11:08:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length57
author_reputation448,535,049,068,622
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,187,676
net_rshares5,639,209,442
author_curate_reward""
vote details (1)
@felixxx ·
You can get some bonus points for figuring out how I can configure beem to work with the testnet :)
properties (22)
authorfelixxx
permlinkq0g46h
categorybusy
json_metadata{"app":"steemit/0.1"}
created2019-11-04 13:01:30
last_update2019-11-04 13:01:30
depth2
children0
last_payout2019-11-11 13:01:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length99
author_reputation217,825,762,716,184
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,190,346
net_rshares0
@geekgirl ·
I find your tutorials to be useful. But I don’t like homework :)
πŸ‘  
properties (23)
authorgeekgirl
permlinkq0fvhw
categorybusy
json_metadata{"app":"steemit/0.1"}
created2019-11-04 09:53:57
last_update2019-11-04 09:53:57
depth1
children1
last_payout2019-11-11 09:53:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation1,588,017,852,468,897
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,186,172
net_rshares0
author_curate_reward""
vote details (1)
@felixxx ·
I kind of got ahead of myself there XD
As I am doing it myself, I realize it is not trivial.
properties (22)
authorfelixxx
permlinkq0fw5n
categorybusy
json_metadata{"app":"steemit/0.1"}
created2019-11-04 10:08:12
last_update2019-11-04 10:08:12
depth2
children0
last_payout2019-11-11 10:08:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length92
author_reputation217,825,762,716,184
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,186,457
net_rshares0
@goldcoin ·
$trdo
πŸ‘  
properties (23)
authorgoldcoin
permlinkq0hqpk
categorybusy
json_metadata{"app":"steemit/0.1"}
created2019-11-05 10:38:12
last_update2019-11-05 10:38:12
depth1
children1
last_payout2019-11-12 10:38:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5
author_reputation18,709,206,614,560
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,217,515
net_rshares1,870,175,073
author_curate_reward""
vote details (1)
@trendotoken ·
Congratulations @goldcoin, you are successfuly trended the post that shared by @felixxx!
@felixxx will receive <b>3.59609625</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) & @goldcoin will get <b>2.39739750</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) curation in 3 Days from Post Created Date!

<b>"Call [TRDO](https://steem-engine.com/?p=history&t=TRDO), Your Comment Worth Something!"</b>
---
<sup>To view or trade TRDO go to [steem-engine.com](https://steem-engine.com/?p=market&t=TRDO)
Join [TRDO Discord Channel](https://discord.gg/wySP8T9) or Join [TRDO Web Site](http://www.trendotoken.info/)</sup>
properties (22)
authortrendotoken
permlinkre-goldcoin-q0hqpk-20191105t103824597z
categorybusy
json_metadata{"tags":["comments-scot","trendo-bot"],"app":"comments-scot/1.1","format":"markdown"}
created2019-11-05 10:38:24
last_update2019-11-05 10:38:24
depth2
children0
last_payout2019-11-12 10:38:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length624
author_reputation5,546,209,053,433
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,217,530
net_rshares0
@maxsieg ·
yes i agree i would love to use python on steem (tho i have to still learn json)
properties (22)
authormaxsieg
permlinkq0fuwe
categorybusy
json_metadata{"app":"steemit/0.1"}
created2019-11-04 09:41:03
last_update2019-11-04 09:41:03
depth1
children0
last_payout2019-11-11 09:41:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length80
author_reputation4,035,631,210,399
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,185,891
net_rshares0
@mytechtrail ·
Well I have some fun with testing various beem modules, but I have yet to find out how to convert VESTS to SP. I need to learn how to extract items from a dictionary to be able to do the homework.

PS. I will do a post of some of my testing shortly. 
properties (22)
authormytechtrail
permlinkre-felixxx-q0gnbq
categorybusy
json_metadata{"tags":["busy"],"app":"steempeak/1.19.0"}
created2019-11-04 19:55:03
last_update2019-11-04 19:55:03
depth1
children1
last_payout2019-11-11 19:55:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length250
author_reputation19,007,675,085,002
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,200,894
net_rshares0
@felixxx ·
If you can do it in VESTS, that's fine.
I will introduce the asset class later ...
properties (22)
authorfelixxx
permlinkq0gpk9
categorybusy
json_metadata{"app":"steemit/0.1"}
created2019-11-04 20:43:21
last_update2019-11-04 20:43:21
depth2
children0
last_payout2019-11-11 20:43:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length82
author_reputation217,825,762,716,184
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,201,951
net_rshares0
@trendotoken ·
Congratulations @felixxx, your post successfully recieved <b>3.59609625</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) from below listed TRENDO callers:<br>

>	<sup>@goldcoin earned : **2.3973975** [TRDO](https://steem-engine.com/?p=history&t=TRDO) curation</sup> 

---
<sup>To view or trade TRDO go to [steem-engine.com](https://steem-engine.com/?p=market&t=TRDO)
Join [TRDO Discord Channel](https://discord.gg/wySP8T9) or Join [TRDO Web Site](http://www.trendotoken.info/)</sup>
properties (22)
authortrendotoken
permlinkre-felixxx-python-for-steem-3-modules-20191107t101748248z
categorybusy
json_metadata{"tags":["trdo","trendo-bot"],"app":"comments-scot/1.1","format":"markdown"}
created2019-11-07 10:17:57
last_update2019-11-07 10:17:57
depth1
children0
last_payout2019-11-14 10:17:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length488
author_reputation5,546,209,053,433
root_title"Python for STEEM #3: Modules"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,279,950
net_rshares0
@xmauron3 ·
thats amazing! thanks for sharing =)
properties (22)
authorxmauron3
permlinkre-felixxx-2019114t63615508z
categorybusy
json_metadata{"tags":["busy","steem","python","beem","stem"],"app":"esteem/2.2.2-surfer","format":"markdown+html","community":"esteem.app"}
created2019-11-04 09:36:15
last_update2019-11-04 09:36:15
depth1
children0
last_payout2019-11-11 09:36:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length36
author_reputation20,850,952,654,220
root_title"Python for STEEM #3: Modules"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id92,185,822
net_rshares0