How to setup a python development environment for Steem

in #programming7 years ago

I was chatting to @kryptik and he needed help getting setup for python development in Steem. I figured this information would be useful to others, so here it is.

This article assumes you're running on Linux. If you're running on another platform, the commands to install applications will be different; however, anything run in python should work the same.

Install dependencies

The library we'll be using to talk to Steem has some dependencies. We'll also setup a virtual environment to isolate python from the system.

sudo apt-get install libssl-dev python3-dev python3-venv

Setup the virtual environment

A virtual environment isolates python libraries from the system. This is useful if you create multiple projects that depend on different versions.

mkdir -p ~/projects/myproject
cd ~/projects/myproject
python3 -m venv venv

This command sets up a virtual environment in the folder ~/projects/myprojects/venv. To activate the virtual environment run:

source venv/bin/activate

First we need to install the wheel library:

pip install wheel

Now we can install piston-lib, the python steem library created by @xeroc:

pip install piston-lib

Test it works

To test that the environment is setup correctly we'll run the following simple script that outputs new posts:

from piston import Steem
steem = Steem()
for c in steem.stream_comments():
    # ignore comments
    if c.is_comment():
        continue
    print("{} by {}".format(c.title, c.author))

Save the above script to the file ~/projects/myproject/myproject.py and run it with:

python3 myproject.py

If everything is working you'll start seeing a list of posts showing the title and author.

Sort:  

Well, some nice introducing to the basics, i like that. Upvoted and Resteemed this post, maybe some future developer will get wet fingers ;)

I like this! I need to set this up. What are the normal prerequisites before the first command?

Assuming you have linux installed, you should be fine with the commands here. Even if you don't have python, apt should add it as a dependency to the python libraries you install.

Good work keep it up.:)

Cool.. followed n upvoted

A special publication Thank you my greetings

Thanks for the quick tutorial! Upvoted and followed.

Thanks for the elaborations. You got me interested and now I've set up a widget so you can query steemit to tell you user info :)

qed, writing "@bitcalm", you summoned the info service of @qed:
99.124% of steemers have lower reputation than bitcalm.
84.537% of steemers signed up later than bitcalm (2016.07.28 at 11:56:03).
Hope that helps. Take care!

So I'm part of the 1%. I call that a success! :)

Ruling class, haha

Fantastic! Short and crisp. I'm sure it will be useful for developers in the future and we may see many more tools related to steem. Keep up the good work. BTW, I'm new to steemit, do checkout my introduction post. Thanks.

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 90827.60
ETH 3116.50
USDT 1.00
SBD 2.97