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.
- comment_kind: str
The prefix that represents
Comment
in API responses, such ast1
.- account_kind: str
The prefix that represents
Redditor
in API responses, such ast2
.- link_kind: str
The prefix that represents
Submission
in API responses, such ast3
.- message_kind: str
The prefix that represents
Message
in API responses, such ast4
.- subreddit_kind: str
The prefix that represents
Subreddit
in API responses, such ast5
.- award_kind: str
The prefix that represents awards in API responses, such as
t6
.- modaction_kind: str
The prefix that represents
ModAction
in API responses, such asmodaction
.- listing_kind: str
The prefix that represents
Listing
in API responses, such aslisting
.- wiki_revision_kind: str
The prefix that represents
WikipageRevision
in API responses, such asWikiRevision
.- wikipage_kind: str
The prefix that represents
SubredditWikipage
in API responses, such aswikipage
.- more_kind: str
The prefix that represents
MoreComments
in API responses, such asmore
.- request_handler: RequestHandler
An instance of
RequestHandler
with which this Reddit instance will perform HTTP requests.
- async comment(id: str = '', url: str = '') apraw.models.reddit.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
- async delete(*args, **kwargs) Any ¶
Perform an HTTP DELETE 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.
kwargs – Query parameters to be appended after the URL.
- Returns
resp – The response JSON data.
- Return type
Any
- async get(*args, **kwargs) Any ¶
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
Any
- async get_listing(endpoint: str, subreddit: Optional[apraw.models.subreddit.subreddit.Subreddit] = None, kind_filter: Optional[List[str]] = None, **kwargs) apraw.models.reddit.listing.Listing ¶
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.
kind_filter – Kinds to return if given, otherwise all are returned.
kwargs (**Dict) – Query parameters to be appended after the URL.
- Returns
listing – The listing containing all the endpoint’s children.
- Return type
- 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.
- async message(to: Union[str, apraw.models.reddit.redditor.Redditor], subject: str, text: str, from_sr: Union[str, apraw.models.subreddit.subreddit.Subreddit] = '') bool ¶
Message a Redditor or Subreddit.
- Parameters
- Returns
result – The response JSON data.
- Return type
Dict
- async post(*args, **kwargs) Any ¶
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
Any
- async put(*args, **kwargs) Any ¶
Perform an HTTP PUT 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
Any
- async redditor(username: str) apraw.models.reddit.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
- async submission(id: str = '', url: str = '') apraw.models.reddit.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
- async subreddit(display_name: str) apraw.models.subreddit.subreddit.Subreddit ¶
Get a Subreddit object according to the given name.
- Parameters
display_name (str) – The display name of the subreddit.
- Returns
subreddit – The subreddit if found.
- Return type
- subreddits(*args, **kwargs)¶
A
ListingGenerator
that returns newly created subreddits, which can be streamed usingreddit.subreddits.stream()
.- Parameters
kwargs (**Dict) –
ListingGenerator
kwargs
.- Returns
generator – A
ListingGenerator
that retrieves newly created subreddits.- Return type