Introducing Lightsteem: A thin Python client for Steem

in utopian-io •  4 months ago

Screen Shot 2018-08-07 at 7.14.36 PM.png


lightsteem

Lightsteem is a light python 3.6+ client to interact with the STEEM blockchain. It's simple and stupid. You ask something, you get something.

After working extensively with steem-python and beem in the past, I found myself frusturated while debugging simple scripts. Both of these libraries include enourmous amount of work, but they do a good amount of encapsulation and magic inside.

Simple is better than complex.

is from the Zen of Python. That brought the idea of having a simple client myself with my design decisions.

What's supported?

lightsteem is designed for appbase nodes. Every call supported by the appbase is
accessible via the Client interface. It also supports jussi's batch calls.

It also supports auto retry and node failovers out of the box.

Installation

$ (sudo) pip install lightsteem

Usage

from lightsteem.client import Client

client = Client(nodes=["https://api.steemit.com"])

print(client.get_dynamic_global_properties())

By default, client uses condenser_api to make the calls. If you
want to change the api, just call the client instance
with the api name.

Examples

Get Account History
from lightsteem.client import Client

c = Client()

history = c.get_account_history("emrebeyler", 1000, 10)

for op in history:
    print(op)
Get accounts by key (account_by_key_api)

from lightsteem.client import Client

client = Client()

accounts = client('account_by_key_api').get_key_references({
    "keys":["STM5jZtLoV8YbxCxr4imnbWn61zMB24wwonpnVhfXRmv7j6fk3dTH"]
})

print(accounts)
Get last 10 posts of a user (tags_api)
from lightsteem.client import Client

c = Client()

posts = c('tags_api').get_discussions_by_blog({"tag": "ned", "limit": 10})
for p in posts["discussions"]:
    print(p["title"])
Get block detail (block_api)
from lightsteem.client import Client

c = Client()

block = c('block_api').get_block({"block_num": 24858937})

print(block)

Get current reserve ratio (witness_api)

from lightsteem.client import Client

c = Client()

ratio = c('witness_api').get_reserve_ratio()

print(ratio)
Get list of supported methods by RPC node (jsonrpc)
from lightsteem.client import Client

c = Client()

methods = c('jsonrpc').get_methods()

print(methods)

Get vesting delegations of an account (database_api)
from lightsteem.client import Client

c = Client()

outgoing_delegations = c('database_api').find_vesting_delegations({"account": "emrebeyler"})

print(outgoing_delegations)

Batch calls

If a JUSSI instance is set on the appbase node, you can enjoy batch calls.

from lightsteem.client import Client

c = Client()

c.get_block(24858937, batch=True)
c.get_block(24858938, batch=True)

blocks = c.process_batch()

print(blocks)

Roadmap

  • Transaction signing, support for broadcast APIs.
  • Helpers for different kind of topics. (Account, Witness, Streaming helpers, etc.)
  • Having a good code coverage in terms of unit tests.

Contributing

  • You can stop by Lightsteem discord and join the development with your feedback and ideas.

  • You can pick an open issue and start working on it. But we should reach a consensus about the design decisions before any merge.

Notes

Consider using condenser_api methods until the other apis becomes stable. A warning from the official portal:

While the condenser_api.* calls are ready for use, all other appbase methods are currently works in progress and may change, or be unsuitable for production use.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Ok, gave it spin.

Tried pulling number of posts for a user. It's really fast. Think it just might be my go-to for that sort of thing. Also, think I like the time format for active votes may work better for us.

Of course, I'll still need to leverage Beem for the transfers but I'll likely do a side by side performance comparison in the future.

Nice work, @emrebeyler.

Here's the link to the vid of my trying it out.

https://dlive.io/video/anthonyadavisii/27f69ea1-9aa8-11e8-9e1e-0242ac110003

  • Great foundation for many future projects and development on STEEM.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

·

Thanks for the fast review. :)

Nice to see you going 3 only! I like using packages that take advantage of the latest features and aren't burdened by 2 support.

I am excited.
This is a huge gain for the python family here on steem.

·

Python family is the best. :)

Good work, can't wait until all points in your roadmap are finished :).

·

Thanks! :)

great job!! thanks for making this client. I know from experience KISS the enduser (end-developer in this case) result indeed means a lot of work. :)

are you contemplating also adding the sign & broadcast libs or do u want to keep it for light and easy access to reads on the chain?

·

Thanks @roelandp :)

Transaction signing and broadcasting support is already merged to master. See the pull request.

I have decoupled the signing stuff from steem-python. (without serializers) It's still light considering the amount of boilerplate code for signing. (only 2 extra dependencies.)

I have not released the new version to the PyPI yet, but it will land this weekend and I will announce the new version.

How is it different from beem? It will grow to the same sizes in the future..

·

It won't grow the same size with Beem, or steem-python.

  • No planned support serializations. (get_transaction_hex call helps with that.)

  • No support for pre-app base nodes.

There will be helper modules for well-known objects in the chain and broadcasting support. That's all.

FENA BİŞEY

·

reis seni python dev yapalim.

I guess it’s true that they say, “the more the merrier” 😉
I’m still behind testing out beem, but maybe I find some time to try out your light.

Well done putting it together!

·

Transaction signing is not there yet, but it will come soon.

·
·

I'm sure it will be there before I get around trying it out...

Hey @emrebeyler
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Good stuff bro, i' ll definitely give it a try