Tools¶
steem-python comes with batteries included.
This page lists a collection of convenient tools at your disposal.
Account¶
-
class
steem.account.Account(account_name, steemd_instance=None)¶ This class allows to easily access Account data
Parameters: - account_name (str) – Name of the account
- steemd_instance (Steemd) – Steemd() instance to use when accessing a RPC
-
export(load_extras=True)¶ Strip Python specific data-types and return a dictionary that can be safely stored as JSON or database entry.
- Args:
- load_extras: Fetch extra information related to the account.
-
get_account_history(index, limit, start=None, stop=None, order=-1, filter_by=None, raw_output=False)¶ A generator over steemd.get_account_history.
It offers serialization, filtering and fine grained iteration control.
Parameters: - index (int) – start index for get_account_history
- limit (int) – How many items are we interested in.
- start (int) – (Optional) skip items until this index
- stop (int) – (Optional) stop iteration early at this index
- order – (1, -1): 1 for chronological, -1 for reverse order
- filter_by (str, list) – filter out all but these operations
- raw_output (bool) – (Defaults to False). If True, return history in steemd format (unchanged).
-
history(filter_by=None, start=0, batch_size=1000, raw_output=False)¶ Stream account history in chronological order.
-
history_reverse(filter_by=None, batch_size=1000, raw_output=False)¶ Stream account history in reverse chronological order.
Amount¶
-
class
steem.amount.Amount(amount_string='0 SBD')¶ This class helps deal and calculate with the different assets on the chain.
Parameters: amountString (str) – Amount string as used by the backend (e.g. “10 SBD”)
Blockchain¶
-
class
steem.blockchain.Blockchain(steemd_instance=None, mode='irreversible')¶ Access the blockchain and read data from it.
Parameters: - steemd_instance (Steemd) – Steemd() instance to use when accessing a RPC
- mode (str) – irreversible or head. irreversible is default.
-
get_all_usernames(*args, **kwargs)¶ Fetch the full list of STEEM usernames.
-
get_current_block()¶ This call returns the current block
-
get_current_block_num()¶ This call returns the current block
-
static
hash_op(event: dict)¶ This method generates a hash of blockchain operation.
-
history(filter_by: typing.Union[str, list] = [], start_block=1, end_block=None, raw_output=False, **kwargs)¶ Yield a stream of historic operations.
Similar to
Blockchain.stream(), but starts at beginning of chain unlessstart_blockis set.Parameters: - filter_by (str, list) – List of operations to filter for
- start_block (int) – Block to start with. If not provided, start of blockchain is used (block 1).
- end_block (int) – Stop iterating at this block. If not provided, this generator will run forever.
- raw_output (bool) – (Defaults to False). If True, return ops in a unmodified steemd structure.
-
info()¶ This call returns the dynamic global properties
-
stream(filter_by: typing.Union[str, list] = [], *args, **kwargs)¶ Yield a stream of operations, starting with current head block.
Parameters: filter_by (str, list) – List of operations to filter for
-
stream_from(start_block=None, end_block=None, batch_operations=False, full_blocks=False, **kwargs)¶ This call yields raw blocks or operations depending on
full_blocksparam.By default, this generator will yield operations, one by one. You can choose to yield lists of operations, batched to contain all operations for each block with
batch_operations=True. You can also yield full blocks instead, withfull_blocks=True.Parameters: - start_block (int) – Block to start with. If not provided, current (head) block is used.
- end_block (int) – Stop iterating at this block. If not provided, this generator will run forever (streaming mode).
- batch_operations (bool) – (Defaults to False) Rather than yielding operations one by one, yield a list of all operations for each block.
- full_blocks (bool) – (Defaults to False) Rather than yielding operations, return raw, unedited blocks as provided by steemd. This mode will NOT include virtual operations.
Blog¶
-
class
steem.blog.Blog(account_name: str, comments_only=False, steemd_instance=None)¶ Obtain a list of blog posts for an account
Parameters: - account_name (str) – Name of the account
- comments_only (bool) – (Default False). Toggle between posts and comments.
- steemd_instance (Steemd) – Steemd instance overload
Returns: Generator with Post objects in reverse chronological order.
Example
To get all posts, you can use either generator:
gen1 = Blog('furion') gen2 = b.all() next(gen1) next(gen2)
To get some posts, you can call take():
b = Blog('furion') posts = b.take(5)
-
all()¶ A generator that will return ALL of account history.
-
take(limit=5)¶ Take up to n (n = limit) posts/comments at a time.
You can call this method as many times as you want. Once there are no more posts to take, it will return [].
Returns: List of posts/comments in a batch of size up to limit.
Converter¶
-
class
steem.converter.Converter(steemd_instance=None)¶ Converter simplifies the handling of different metrics of the blockchain
Parameters: steemd_instance (Steemd) – Steemd() instance to use when accessing a RPC Obtain weight from rshares
Parameters: rshares (number) – R-Shares
-
sbd_median_price()¶ Obtain the sbd price as derived from the median over all witness feeds. Return value will be SBD
Obtain r-shares from SBD
Parameters: sbd_payout (number) – Amount of SBD
-
sbd_to_steem(amount_sbd)¶ Conversion Ratio for given amount of SBD to STEEM at current price feed
Parameters: amount_sbd (number) – Amount of SBD
Obtain the r-shares
Parameters: - sp (number) – Steem Power
- voting_power (int) – voting power (100% = 10000)
- vote_pct (int) – voting participation (100% = 10000)
-
sp_to_vests(sp)¶ Obtain VESTS (not MVESTS!) from SP
Parameters: sp (number) – SP to convert
-
steem_per_mvests()¶ Obtain STEEM/MVESTS ratio
-
steem_to_sbd(amount_steem)¶ Conversion Ratio for given amount of STEEM to SBD at current price feed
Parameters: amount_steem (number) – Amount of STEEM
-
vests_to_sp(vests)¶ Obtain SP from VESTS (not MVESTS!)
Parameters: vests (number) – Vests to convert to SP
Dex¶
-
class
steem.dex.Dex(steemd_instance=None)¶ This class allows to access calls specific for the internal exchange of STEEM.
Parameters: steemd_instance (Steemd) – Steemd() instance to use when accessing a RPC -
buy(amount, quote_symbol, rate, expiration=604800, killfill=False, account=None, order_id=None)¶ Places a buy order in a given market (buy
quote, sellbasein marketquote_base). If successful, the method will return the order creating (signed) transaction.Parameters: - amount (number) – Amount of
quoteto buy - quote_symbol (str) – STEEM, or SBD
- price (float) – price denoted in
base/quote - expiration (number) – (optional) expiration time of the order in seconds (defaults to 7 days)
- killfill (bool) – flag that indicates if the order shall be killed if it is not filled (defaults to False)
- account (str) – (optional) the source account for the transfer if not
default_account - order_id (int) – (optional) a 32bit orderid for tracking of the created order (random by default)
Prices/Rates are denoted in ‘base’, i.e. the STEEM:SBD market is priced in SBD per STEEM.
- amount (number) – Amount of
-
cancel(orderid, account=None)¶ Cancels an order you have placed in a given market.
Parameters: - orderid (int) – the 32bit orderid
- account (str) – (optional) the source account for the transfer if not
default_account
-
get_ticker()¶ Returns the ticker for all markets.
Output Parameters:
latest: Price of the order last filledlowest_ask: Price of the lowest askhighest_bid: Price of the highest bidsbd_volume: Volume of SBDsteem_volume: Volume of STEEMpercent_change: 24h change percentage (in %)
Note
Market is STEEM:SBD and prices are SBD per STEEM!
Sample Output:
{'highest_bid': 0.30100226633322913, 'latest': 0.0, 'lowest_ask': 0.3249636958897082, 'percent_change': 0.0, 'sbd_volume': 108329611.0, 'steem_volume': 355094043.0}
-
market_history(bucket_seconds=300, start_age=3600, end_age=0)¶ Return the market history (filled orders).
Parameters: - bucket_seconds (int) – Bucket size in seconds (see returnMarketHistoryBuckets())
- start_age (int) – Age (in seconds) of the start of the window (default: 1h/3600)
- end_age (int) – Age (in seconds) of the end of the window (default: now/0)
Example:
{'close_sbd': 2493387, 'close_steem': 7743431, 'high_sbd': 1943872, 'high_steem': 5999610, 'id': '7.1.5252', 'low_sbd': 534928, 'low_steem': 1661266, 'open': '2016-07-08T11:25:00', 'open_sbd': 534928, 'open_steem': 1661266, 'sbd_volume': 9714435, 'seconds': 300, 'steem_volume': 30088443},
-
sell(amount, quote_symbol, rate, expiration=604800, killfill=False, account=None, orderid=None)¶ Places a sell order in a given market (sell
quote, buybasein marketquote_base). If successful, the method will return the order creating (signed) transaction.Parameters: - amount (number) – Amount of
quoteto sell - quote_symbol (str) – STEEM, or SBD
- price (float) – price denoted in
base/quote - expiration (number) – (optional) expiration time of the order in seconds (defaults to 7 days)
- killfill (bool) – flag that indicates if the order shall be killed if it is not filled (defaults to False)
- account (str) – (optional) the source account for the transfer if not
default_account - orderid (int) – (optional) a 32bit orderid for tracking of the created order (random by default)
Prices/Rates are denoted in ‘base’, i.e. the STEEM:SBD market is priced in SBD per STEEM.
- amount (number) – Amount of
-
trade_history(time=3600, limit=100)¶ Returns the trade history for the internal market
Parameters: - time (int) – Show the last x seconds of trades (default 1h)
- limit (int) – amount of trades to show (<100) (default: 100)
-
Post¶
-
class
steem.post.Post(post, steemd_instance=None)¶ This object gets instantiated by Steem.streams and is used as an abstraction layer for Comments in Steem
Parameters: - post (str or dict) –
@author/permlinkor rawcommentas dictionary. - steemd_instance (Steemd) – Steemd node to connect to
-
curation_reward_pct()¶ If post is less than 30 minutes old, it will incur a curation reward penalty.
-
downvote(weight=-100, voter=None)¶ Downvote the post
Parameters: - weight (float) – (optional) Weight for posting (-100.0 - +100.0) defaults to -100.0
- voter (str) – (optional) Voting account
-
edit(body, meta=None, replace=False)¶ Edit an existing post
Parameters: - body (str) – Body of the reply
- meta (json) – JSON meta object that can be attached to the post. (optional)
- replace (bool) – Instead of calculating a diff, replace
the post entirely (defaults to
False)
-
export()¶ This method returns a dictionary that is type-safe to store as JSON or in a database.
-
static
get_all_replies(root_post=None, comments=[], all_comments=[])¶ Recursively fetch all the child comments, and return them as a list.
Usage: all_comments = Post.get_all_replies(Post(‘@foo/bar’))
-
get_replies()¶ Return first-level comments of the post.
-
is_comment()¶ Retuns True if post is a comment
-
is_main_post()¶ Retuns True if main post, and False if this is a comment (reply).
-
static
parse_identifier(uri)¶ Extract post identifier from post URL.
-
reply(body, title='', author='', meta=None)¶ Reply to an existing post
Parameters: - body (str) – Body of the reply
- title (str) – Title of the reply post
- author (str) – Author of reply (optional) if not provided
default_userwill be used, if present, else aValueErrorwill be raised. - meta (json) – JSON meta object that can be attached to the post. (optional)
-
reward¶ Return a float value of estimated total SBD reward.
-
time_elapsed()¶ Return a timedelta on how old the post is.
-
upvote(weight=100, voter=None)¶ Upvote the post
Parameters: - weight (float) – (optional) Weight for posting (-100.0 - +100.0) defaults to +100.0
- voter (str) – (optional) Voting account
-
vote(weight, voter=None)¶ Vote the post
Parameters: - weight (float) – Weight for posting (-100.0 - +100.0)
- voter (str) – Voting account
- post (str or dict) –
steem.utils¶
-
steem.utils.block_num_from_hash(block_hash: str) → int¶ return the first 4 bytes (8 hex digits) of the block ID (the block_num) :param block_hash: :type block_hash: str
Returns: Return type: int
-
steem.utils.block_num_from_previous(previous_block_hash: str) → int¶ Parameters: previous_block_hash (str) – Returns: Return type: int
-
steem.utils.chunkify(iterable, chunksize=10000)¶ Yield successive chunksized chunks from iterable.
Parameters: - iterable –
- chunksize – (Default value = 10000)
Returns:
-
steem.utils.construct_identifier(*args, username_prefix='@')¶ Create a post identifier from comment/post object or arguments.
Examples
construct_identifier('username', 'permlink') construct_identifier({'author': 'username', 'permlink': 'permlink'})
-
steem.utils.env_unlocked()¶ Check if wallet password is provided as ENV variable.
-
steem.utils.fmt_time(t)¶ Properly Format Time for permlinks
-
steem.utils.fmt_time_from_now(secs=0)¶ Properly Format Time that is x seconds in the future
Parameters: secs (int) – Seconds to go in the future (x>0) or the past (x<0) Returns: Properly formated time for Graphene (%Y-%m-%dT%H:%M:%S) Return type: str
-
steem.utils.fmt_time_string(t)¶ Properly Format Time for permlinks
-
steem.utils.is_comment(item)¶ Quick check whether an item is a comment (reply) to another post. The item can be a Post object or just a raw comment object from the blockchain.
-
steem.utils.json_expand(json_op, key_name='json')¶ Convert a string json object to Python dict in an op.
-
steem.utils.keep_in_dict(obj, allowed_keys=[])¶ Prune a class or dictionary of all but allowed keys.
-
steem.utils.parse_time(block_time)¶ Take a string representation of time from the blockchain, and parse it into datetime object.
-
steem.utils.remove_from_dict(obj, remove_keys=[])¶ Prune a class or dictionary of specified keys.
-
steem.utils.strfage(time, fmt=None)¶ Format time/age
-
steem.utils.strfdelta(tdelta, fmt)¶ Format time/age
-
steem.utils.time_elapsed(posting_time)¶ Takes a string time from a post or blockchain event, and returns a time delta from now.