A python wrapper for the Reddit API.
This is a Python wrapper for Reddit's API, aiming to be as easy to use as possible. Here's a quick peek, getting the first 10 submissions from the 'hot' section of the 'opensource' subreddit.
import reddit
r = reddit.Reddit(user_agent='my_cool_application')
submissions = r.get_subreddit('opensource').get_hot(limit=5)
[str(x) for x in submissions]
this will display something similar to the following:
['10 :: Gun.io Debuts Group Funding for Open Source Projects\n Gun.io',
'24 :: Support the Free Software Foundation',
'67 :: The 10 Most Important Open Source Projects of 2011',
'2 :: Open-source webOS is dead on arrival ',
'85 :: Plan 9 - A distributed OS with a unified communication protocol and I/O driver model. Wow.']
The preferred way to install is via pip
pip install reddit
For the most up to date code, you can install via setup.py from a checkout of this repo
python setup.py install
Building the Reddit object (requires a user agent):
r = reddit.Reddit(user_agent='example')
Logging in:
r.login('username', 'password')
Send a message (requires login):
r.compose_message('bboe', 'Subject Line', 'You are awesome!')
Get the top submissions for r/python:
submissions = r.get_subreddit('python').get_top(limit=10)
Get comments from a given submission:
submission = submissions.next()
submission.comments
Comment on a submission (requires login):
submission.add_comment('text')
Voting (requires login):
# item can be a comment or submission
item.upvote()
item.downvote()
item.clear_vote()
For a more extensive set of examples, see the wiki.