redditpythonapi package

Submodules

redditpythonapi.reddit module

Wrapper for Reddit API. Using a wrapper simplifies accessing the API, mostly due to handling OAuth.

class redditpythonapi.reddit.ArticlesSortTime(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: StrEnum

Enum with all viable sort times

ALL = 'all'
DAY = 'day'
HOUR = 'hour'
MONTH = 'month'
WEEK = 'week'
YEAR = 'year'
class redditpythonapi.reddit.ArticlesSortType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: StrEnum

Enum with all viable sorting types

CONTROVERSIAL = 'controversial'
HOT = 'hot'
NEW = 'new'
RISING = 'rising'
TOP = 'top'
class redditpythonapi.reddit.Reddit(client_id: str, client_secret: str, user_agent: str = 'Reddit Python API (by Electronic-Mango on GitHub)')[source]

Bases: object

Class wrapping Reddit API

Class wrapping calls to Reddit API. Handles all necessary URLs, parameters, headers, etc. Also handles requesting new OAuth 2.0 access tokens and authorization in general.

Parameters:
  • client_id (str) – Reddit app client ID to use for authorization

  • client_secret (str) – Reddit app client secret to use for authorization

  • user_agent (str) – user agent used in all Reddit API requests

async subreddit_articles(subreddit: str, sort: ArticlesSortType | None = None, time: ArticlesSortTime | None = None, limit: int | None = None) list[dict[str, Any]][source]

Get a list of Reddit articles from the given subreddit

Parameters:
  • subreddit (str) – subreddit to load articles from

  • sort (ArticlesSortType | None) – sort type to use when loading articles, “hot” by default

  • time (ArticlesSortTime | None) – sort time to use when loading articles, by default not passed onto Reddit API

  • limit (int | None) – up to how many articles should be loaded, by default not passed onto Reddit API

Returns:

list of loaded articles from the given subreddit

Return type:

list[Article]

async user_articles(user: str, sort: ArticlesSortType | None = None, time: ArticlesSortTime | None = None, limit: int | None = None) list[dict[str, Any]][source]

Get a list of Reddit articles from the given Reddit user

Parameters:
  • user (str) – Reddit user to load articles from

  • sort (ArticlesSortType | None) – sort type to use when loading articles, by default not passed onto Reddit API

  • time (ArticlesSortTime | None) – sort time to use when loading articles, by default not passed onto Reddit API

  • limit (int | None) – up to how many articles should be loaded, by default not passed onto Reddit API

Returns:

list of loaded articles from the Reddit user

Return type:

list[Article]

Module contents