Reddit

Contents

class apraw.Reddit(praw_key: str = '', username: str = '', password: str = '', client_id: str = '', client_secret: str = '', user_agent='aPRAW by Dan6erbond')

The Reddit instance with which root requests can be made.

user: User
An instance of the logged-in Reddit user.
subreddits: ListingGenerator
A ListingGenerator that returns newly created subreddits, which can be streamed using reddit.subreddits.stream().
comment(id: str = '', url: str = '') → apraw.models.comment.Comment

Get a Comment object based on its ID or URL.

Parameters:
  • id (str) – The ID of a comment (with or without kind).
  • url (str) – The URL of a comment.
Returns:

comment – The requested comment.

Return type:

Comment

get_listing(endpoint: str, subreddit: apraw.models.subreddit.Subreddit = None, **kwargs)

Retrieve a listing from an endpoint.

Parameters:
  • endpoint (str) – The endpoint to be appended after the base URL (https://oauth.reddit.com/).
  • subreddit (Subreddit) – The subreddit to dependency inject into retrieved items when possible.
  • kwargs (**Dict) – Query parameters to be appended after the URL.
Returns:

listing – The listing containing all the endpoint’s children.

Return type:

Listing

get_request(*args, **kwargs)

Perform an HTTP GET request on the Reddit API.

Parameters:
  • endpoint (str) – The endpoint to be appended after the base URL (https://oauth.reddit.com/).
  • kwargs – Query parameters to be appended after the URL.
Returns:

resp – The response JSON data.

Return type:

Dict or None

info(id: str = '', ids: List[str] = [], url: str = '')

Get a Reddit item based on its ID or URL.

Parameters:
  • id (str) – The item’s ID.
  • ids (List[str]) – Multiple IDs to fetch multiple items at once (max 100).
  • url (str) – The item’s URL.
Yields:
  • comment (Comment) – A Comment object.
  • submission (Submission) – A Submission object.
message(to: Union[str, apraw.models.redditor.Redditor], subject: str, text: str, from_sr: Union[str, apraw.models.subreddit.Subreddit] = '') → Dict

Message a Redditor or Subreddit.

Parameters:
  • to (str or Redditor or Subreddit) – The Redditor or Subreddit the message should be sent to.
  • subject (str) – The subject of the message.
  • text (str) – The text contents of the message.
  • from_sr (str or Subreddit) – Optional if the message is being sent from a subreddit.
Returns:

result – The response JSON data.

Return type:

Dict

post_request(*args, **kwargs)

Perform an HTTP POST request on the Reddit API.

Parameters:
  • endpoint (str) – The endpoint to be appended after the base URL (https://oauth.reddit.com/).
  • url (str) – The direct URL to perform the request on.
  • data – The data to add to the POST body.
  • kwargs – Query parameters to be appended after the URL.
Returns:

resp – The response JSON data.

Return type:

Dict or None

redditor(username: str) → apraw.models.redditor.Redditor

Get a Redditor object based the Redditor’s username.

Parameters:username (str) – The Redditor’s username (without ‘/u/’).
Returns:redditor – The requested Redditor, returns None if not found.
Return type:Redditor or None
submission(id: str = '', url: str = '') → apraw.models.submission.Submission

Get a Submission object based on its ID or URL.

Parameters:
  • id (str) – The ID of a submission (with or without kind).
  • url (str) – The URL of a submission.
Returns:

submission – The requested submission.

Return type:

Submission

subreddit(display_name: str) → apraw.models.subreddit.Subreddit

Get a Subreddit object according to the given name.

Parameters:display_name (str) – The display name of the subreddit.
Returns:
  • subreddit (Subreddit) – The subreddit if found.
  • result (None) – Returns None if subreddit not found.