Skip to main content

RedditEasy is an API wrapper for getting posts using the Reddit JSON API with both normal and async options

Project description

Documentation Status License GitHub stars PyPI version Monthly Downloads

RedditEasy

RedditEasy is an API wrapper for getting posts using the Reddit JSON API with both normal and async options

Install

To install RedditEasy, do:

pip install redditeasy

OR

python -m pip install redditeasy

Documentation

Docs can be found here

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 it: https://github.com/MakufonSkifto/RedditEasy/blob/main/examples/async_meme.py

You can and should use this in a discord.py bot. The normal classes could cause a blocking in a discord.py bot.

This will not work outside an async function whatsoever.

Usage

THE MODULE WILL USE ITS OWN DEFAULT CLIENT INFO IF AT LEAST ONE OF THESE ARE NOT GIVEN: client_id, client_secret, and user_agent.

Without Reddit API client info

This method is not suggested as it may be slow and throw errors more often

import redditeasy

post = redditeasy.Subreddit(subreddit="dankmemes")   #Subreddit name

postoutput = post.get_post()

print(f"Posts Title: {postoutput.title}\n"
      f"Posts Content: {postoutput.content}\n"
      f"Posts Author: u/{postoutput.author}\n"
      f"Posts URL: {postoutput.post_url}\n"
      f"Spoiler?: {postoutput.spoiler}\n"
      f"Post Created At: {postoutput.created_at}\n"
      f"Posts Upvote Count: {postoutput.score}\n"
      f"Posts Award Count: {postoutput.total_awards}\n"
      f"NSFW?: {postoutput.nsfw}\n"
      f"Post Flair: {postoutput.post_flair}\n"
      f"User Flair: {postoutput.author_flair}\n"
      f"Subreddit Subscribers: {postoutput.subreddit_subscribers}")

With Reddit API client info

import redditeasy

post = redditeasy.Subreddit(subreddit="dankmemes",   #Subreddit name
                            client_id="",            #Your client ID
                            client_secret="",        #Your client secret
                            user_agent=""            #Your user agent (ex: ClientName/0.1 by YourUsername")
                            )

postoutput = post.get_post()

print(f"Posts Title: {postoutput.title}\n"
      f"Posts Content: {postoutput.content}\n"
      f"Posts Author: u/{postoutput.author}\n"
      f"Posts URL: {postoutput.post_url}\n"
      f"Spoiler?: {postoutput.spoiler}\n"
      f"Post Created At: {postoutput.created_at}\n"
      f"Posts Upvote Count: {postoutput.score}\n"
      f"Posts Award Count: {postoutput.total_awards}\n"
      f"NSFW?: {postoutput.nsfw}\n"
      f"Post Flair: {postoutput.post_flair}\n"
      f"User Flair: {postoutput.author_flair}\n"
      f"Subreddit Subscribers: {postoutput.subreddit_subscribers}")

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")

Errors

The module will raise KeyError if the given user / subreddit is not found

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 ValueError if the given user / subreddit is empty

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redditeasy-3.2.1.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

redditeasy-3.2.1-py3-none-any.whl (19.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page