Python client of SteemConnect API

in #utopian-io6 years ago (edited)

steemconnect-python-client is a simple yet powerful library to interact with the Steemconnect. There was no production ready library for Python (Or I couldn't find it.) so I have decided to write my own.

SteemConnect V2 implements OAUTH standards. If you don't know about it, you can read the SteemConnect wiki to learn the workflow and the token based authorization.

Also, you need to register your app into steemconnect before working with them. This will provide client_id and client_secret information which you will need to interact with the API.


SteemConnect application management screen

Installation

$ (sudo) pip install steemconnect

Authorization Workflow

c = Client(
    client_id="app_name",
    client_secret="client_secret",
)

After getting the Client instance:

auth_url = c.get_login_url(
    "callback_url_to_your_app",
    "login,vote",
)

This will return a full login URL which you redirect users and after they login, you get the access_token in the query string with the specified callback url.

Access tokens has a limited lifetime, so if you need to refresh them in your own without authenticating the user again, you can add get_refresh_token=True parameter to this function.

If you set this as True, callback url will have a authorization code instead of an access token. With this code, you can ask access tokens first:

tokens = c.get_access_token(
    code,
) 

Example output:

 {
     'access_token': 'access_token_string',
     'expires_in': 604800,
     'username': 'emrebeyler',
     'refresh_token': 'refresh_token_string'
 }

As you can see, the lifetime of this token is 604800 seconds. After it expires, you can refresh it with refresh_access_token method.

c.refresh_access_token(
    access_token_response.get("refresh_token"),
    "login,vote" # scopes
)

SC2 api to interact with the chain

Once you get the access token, you can create a new Client instance with just access_token.

c = Client(
    access_token="access_token",
)

/me endpoint

This endpoint returns information about the authorized user.

print(c.me())

/broadcast endpoint

All supported operations are located at the steemconnect.operations module.

Voting
vote = Vote("account", "author", "permlink", percent)
c.broadcast([vote.to_operation_structure()])
Creating a Comment
comment = Comment(
    "author",
    "permlink",
    "body",
    title="test title",
    json_metadata={"app":"foo/0.0.1"},
)
c.broadcast([comment.to_operation_structure()])

Creating a Comment with CommentOptions
comment = Comment(
    "author",
    "permlink",
    "body",
    title="test title",
    json_metadata={"app":"foo/0.0.1"},
)
    
comment_options = CommentOptions(
      parent_comment=comment,
    allow_curation_rewards=False,
)

c.broadcast([
    comment.to_operation_structure(),
    comment_options. comment.to_operation_structure()
])

Follow
follow = Follow("follower", "following")
c.broadcast([follow.to_operation_structure()])
Unfollow
unfollow = Unfollow("follower", "following")
c.broadcast([unfollow.to_operation_structure()])
Ignore
ignore = Mute("follower", "following")
c.broadcast([ignore.to_operation_structure()])
Resteem
resteem = Resteem("account", "author", "permlink")
c.broadcast([resteem.to_operation_structure()])
Claim Reward Balance
claim_reward_balance = ClaimRewardBalance('account', '0.000 STEEM', '1.500 SBD', '1132.996000 VESTS')
c.broadcast([claim_reward_balance.to_operation_structure()])
Delete Comment
delete_comment = DeleteComment(
    "author", "permlink"
)
c.broadcast([delete_comment.to_operation_structure()])
CustomJson
custom_json = CustomJson(
    required_auth,
    required_posting_auths,
    id
    json_structure,
)
c.broadcast([custom_json.to_operation_structure()])

Roadmap

Even though I have implemented all operation types, not all specs are ready yet. I will try to complete the rest in next iteration like hot-signing and revoking tokens, etc.

How to contribute

Contribution process is same with any other open-source project. You can checkout open issues at Github and can start working on it. Just make sure, you will comment on the related issue before starting working on it.

Also, run unit tests before creating a pull request and make sure it's all green.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Kusadasi cointurk discord üzerinde 3.sü düzenlenen yarışmada doğru cevap verdiğiniz için oylandınız. İleride de yarışmalarımıza katılmanız dileğimle

Seçilen Logo Kuşadası - Şeffaf Arkaplan-01.png

This is so generous of you to share! I was just looking for how to do this and now you’ve made it much easier :) thank you!

You just don't stop impressing me, good work!

This is absolutely incredible. I'm developing a Python project relying on SteemConnect and I found myself beating my head against the wall when it comes to dealing with that. Thank you so much!

[utopian-moderator]

Full upvote because full awesome!

That could really help me... Thanks!

Nice work mate! Python always looks so tidy compared to js 💪

Thanks for the contribution, it has been approved.

Looks really cool @emrebeyler! I will definitely keep an eye on it!


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

[utopian-moderator]

Loading...

What do you mean by same?

my project will not always stay the same, I would go ahead with development and I think you could pull requests instead of starting a new project, I think this is what's right

Thanks Amos! :)

dear @emrebeyler i am new in @Steemconnect contest . im not understad this contest . plese help me

This is not a contest.

All kind of dumb people with dramas.. O_O

Hey @emrebeyler! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

Coin Marketplace

STEEM 0.20
TRX 0.12
JST 0.030
BTC 60248.53
ETH 3368.01
USDT 1.00
SBD 2.51