Getting Started#
Install#
To install RedditEasy, do:
pip install redditeasy
OR
python -m pip install redditeasy
OR (not recommended)
pip install git+https://github.com/MakufonSkifto/RedditEasy.git
Async RedditEasy#
Yes, there is an async version of RedditEasy. To use it, you need to use the Async classes. Which are AsyncSubreddit and AsyncUser
Here is a small example on using AsyncSubreddit: https://github.com/MakufonSkifto/RedditEasy/blob/main/examples/async_meme.py
You can and should use this in an async program (e.g. discord bot) The normal classes could cause a blocking in an async program.
This will not work outside an async function whatsoever.
Usage#
Without client info#
This method is not suggested as it may be slow and throw errors more often
1import redditeasy
2import datetime
3
4# To get your Reddit API client info go to
5# https://www.reddit.com/prefs/apps
6# and create an app
7
8# For more detailed explanation, see this image: https://i.imgur.com/Ri13AQu.png
9
10
11post = redditeasy.Subreddit()
12
13postoutput = post.get_post(subreddit="dankmemes") # Subreddit name
14
15# Formatted version of created_at
16formatted_time = datetime.datetime.fromtimestamp(postoutput.created_at).strftime("%d/%m/%Y %I:%M:%S UTC")
17
18print(f"Posts Title: {postoutput.title}\n"
19 f"Posts Content: {postoutput.content}\n"
20 f"Posts Author: u/{postoutput.author}\n"
21 f"Posts URL: {postoutput.post_url}\n"
22 f"Spoiler?: {postoutput.spoiler}\n"
23 f"Post Created At: {formatted_time}\n"
24 f"Posts Upvote Count: {postoutput.score}\n"
25 f"Posts Award Count: {postoutput.total_awards}\n"
26 f"NSFW?: {postoutput.nsfw}\n"
27 f"Post Flair: {postoutput.post_flair}\n"
28 f"User Flair: {postoutput.author_flair}\n"
29 f"Subreddit Subscribers: {postoutput.subreddit_subscribers}\n"
30 f"Comment count: {postoutput.comment_count}\n"
31 f"Is Media?: {postoutput.is_media}\n"
32 f"Subreddit Name: r/{postoutput.subreddit_name}\n"
33 f"Content Type: {postoutput.content_type}")
With client info#
1import redditeasy
2import datetime
3
4# To get your Reddit API client info go to
5# https://www.reddit.com/prefs/apps
6# and create an app
7
8# For more detailed explanation, see this image: https://i.imgur.com/Ri13AQu.png
9
10
11post = redditeasy.Subreddit(client_id="", # Your client ID
12 client_secret="", # Your client secret
13 user_agent="" # Your user agent (ex: ClientName/0.1 by YourUsername")
14 )
15
16postoutput = post.get_post(subreddit="dankmemes") # Subreddit name
17
18# Formatted version of created_at
19formatted_time = datetime.datetime.fromtimestamp(postoutput.created_at).strftime("%d/%m/%Y %I:%M:%S UTC")
20
21print(f"Posts Title: {postoutput.title}\n"
22 f"Posts Content: {postoutput.content}\n"
23 f"Posts Author: u/{postoutput.author}\n"
24 f"Posts URL: {postoutput.post_url}\n"
25 f"Spoiler?: {postoutput.spoiler}\n"
26 f"Post Created At: {formatted_time}\n"
27 f"Posts Upvote Count: {postoutput.score}\n"
28 f"Posts Award Count: {postoutput.total_awards}\n"
29 f"NSFW?: {postoutput.nsfw}\n"
30 f"Post Flair: {postoutput.post_flair}\n"
31 f"User Flair: {postoutput.author_flair}\n"
32 f"Subreddit Subscribers: {postoutput.subreddit_subscribers}\n"
33 f"Comment count: {postoutput.comment_count}\n"
34 f"Is Media?: {postoutput.is_media}\n"
35 f"Subreddit Name: r/{postoutput.subreddit_name}\n"
36 f"Content Type: {postoutput.content_type}")
More examples are in the examples folder
Getting Reddit API Client info#
To get your Reddit API client info go to https://www.reddit.com/prefs/apps and create a script.
(You don’t have to fill “redirect_uri”)
Operating Systems#
All of RedditEasy’s versions were tested in Windows, Linux (Ubuntu) and MacOS
Errors#
The module will raise redditeasy.exceptions.RequestError if there was an error with the request. Traceback will show the details about the error
The module will raise redditeasy.exceptions.EmptyResult if the given user / subreddit is empty
Issues#
If you have any issues with RedditEasy, please report them via the issue tracker