Python Reddit API Wrapper - simple access to Reddit's API
—
PRAW provides comprehensive user management capabilities including accessing user profiles, managing friends and blocked users, messaging, and working with the current authenticated user's account.
Access and interact with Reddit user profiles and their content.
class Redditor:
def __init__(self, reddit, name: str = None, fullname: str = None): ...
def message(
self,
subject: str,
message: str,
*,
from_subreddit = None
):
"""
Send a private message to the user.
Parameters:
- subject: Message subject
- message: Message body (markdown supported)
- from_subreddit: Send from subreddit instead of user account
Returns:
Message instance
"""
def friend(self):
"""Add user to friends list."""
def unfriend(self):
"""Remove user from friends list."""
def block(self):
"""Block the user."""
def unblock(self):
"""Unblock the user."""Access user profile information and statistics.
# Basic properties
name: str # Username
id: str # User ID
fullname: str # Reddit fullname (t2_xxxxx)
created_utc: float # Account creation timestamp (UTC)
# Karma and activity
comment_karma: int # Comment karma points
link_karma: int # Link karma points
awardee_karma: int # Karma from receiving awards
awarder_karma: int # Karma from giving awards
total_karma: int # Total karma (may not be sum of individual karmas)
# Premium and status
is_gold: bool # Whether user has Reddit Premium
is_mod: bool # Whether user is a moderator somewhere
is_employee: bool # Whether user is Reddit employee
has_verified_email: bool # Whether email is verified
icon_img: str # Profile icon URL
subreddit: dict # User's profile subreddit info
# Suspension and verification
is_suspended: bool # Whether account is suspended
suspension_expiration_utc: float # Suspension expiration (if suspended)
verified: bool # Whether account is verifiedAccess user's submissions, comments, and activity.
def submissions(self, **kwargs):
"""
Get user's submissions.
Parameters:
- sort: Sort order ("new", "hot", "top", "controversial")
- time_filter: Time period ("all", "day", "week", "month", "year")
- limit: Number of submissions (default: 25, max: 100)
Returns:
ListingGenerator of Submission instances
"""
def comments(self, **kwargs):
"""
Get user's comments.
Parameters:
- sort: Sort order ("new", "hot", "top", "controversial")
- time_filter: Time period ("all", "day", "week", "month", "year")
- limit: Number of comments (default: 25, max: 100)
Returns:
ListingGenerator of Comment instances
"""
def hot(self, **kwargs):
"""Get user's hot submissions and comments."""
def new(self, **kwargs):
"""Get user's newest submissions and comments."""
def top(self, time_filter: str = "all", **kwargs):
"""Get user's top submissions and comments."""
def controversial(self, time_filter: str = "all", **kwargs):
"""Get user's controversial submissions and comments."""
def upvoted(self, **kwargs):
"""
Get submissions upvoted by user (requires authentication).
Returns:
ListingGenerator of Submission instances
"""
def downvoted(self, **kwargs):
"""
Get submissions downvoted by user (requires authentication).
Returns:
ListingGenerator of Submission instances
"""
def gilded(self, **kwargs):
"""
Get content gilded by user.
Returns:
ListingGenerator of submissions/comments
"""
def gildings(self, **kwargs):
"""
Get content user has gilded.
Returns:
ListingGenerator of submissions/comments
"""
def hidden(self, **kwargs):
"""
Get hidden submissions (requires authentication).
Returns:
ListingGenerator of Submission instances
"""
def saved(self, **kwargs):
"""
Get saved content (requires authentication).
Returns:
ListingGenerator of submissions/comments
"""Stream new content from a specific user.
class RedditorStream:
"""Real-time redditor content streaming."""
def submissions(self, **kwargs):
"""
Stream new submissions from the user.
Parameters:
- pause_after: Pause after this many requests
- skip_existing: Skip submissions created before stream start
Yields:
Submission instances
"""
def comments(self, **kwargs):
"""
Stream new comments from the user.
Parameters:
- pause_after: Pause after this many requests
- skip_existing: Skip comments created before stream start
Yields:
Comment instances
"""
stream: RedditorStream # Streaming instanceAccess moderator notes for users (requires moderation permissions).
class RedditorModNotes:
"""Moderator notes for redditors."""
def create(
self,
*,
note: str,
subreddit = None,
thing = None,
**kwargs
):
"""
Create moderator note.
Parameters:
- note: Note content
- subreddit: Subreddit context
- thing: Associated submission/comment
"""
notes: RedditorModNotes # Moderator notes instanceManage the currently authenticated user's account and preferences.
class User:
def __init__(self, reddit): ...
def me(self):
"""
Get current user's profile information.
Returns:
Redditor instance representing current user
"""
def karma(self):
"""
Get detailed karma breakdown by subreddit.
Returns:
Dictionary with karma breakdown
"""
def preferences(self):
"""
Get user preferences.
Returns:
Dictionary with user preferences
"""
def friends(self):
"""
Get friends list.
Returns:
List of Redditor instances
"""
def blocked(self):
"""
Get blocked users list.
Returns:
List of Redditor instances
"""
def contributor_subreddits(self, **kwargs):
"""
Get subreddits where user is contributor.
Returns:
ListingGenerator of Subreddit instances
"""
def moderator_subreddits(self, **kwargs):
"""
Get subreddits where user is moderator.
Returns:
ListingGenerator of Subreddit instances
"""
def multireddits(self):
"""
Get user's multireddits.
Returns:
List of Multireddit instances
"""
def subreddits(self, **kwargs):
"""
Get user's subreddits (subscribed).
Returns:
ListingGenerator of Subreddit instances
"""
def trophies(self):
"""
Get user's trophies.
Returns:
TrophyList instance
"""Manage detailed user preferences and account settings.
def update_preferences(self, **preferences):
"""
Update user preferences.
Parameters:
- lang: Interface language
- over_18: Show NSFW content
- search_include_over_18: Include NSFW in search
- label_nsfw: Auto-label NSFW
- hide_ups: Hide upvote scores
- hide_downs: Hide downvote scores
- min_comment_score: Minimum comment score to show
- min_link_score: Minimum link score to show
- num_comments: Default comments to show
- num_sites: Default submissions to show
- organic: Show promoted content
- compress: Compress links
- domain_details: Show domain details
- email_messages: Email on messages
- email_comments: Email on comment replies
- email_upvote_comment: Email on comment upvotes
- email_upvote_post: Email on post upvotes
- enable_default_themes: Use default themes
- show_trending: Show trending subreddits
- beta: Participate in beta tests
- research: Participate in research
- live_orangereds: Real-time notifications
- highlight_controversial: Highlight controversial
- show_stylesheets: Show custom stylesheets
- show_link_flair: Show link flair
- show_user_flair: Show user flair
- show_flair: Show all flair
- mark_messages_read: Auto-mark messages read
- threaded_messages: Use threaded messages
- collapse_read_messages: Collapse read messages
- monitor_mentions: Monitor username mentions
- send_welcome_messages: Send welcome messages to new users
- allow_clicktracking: Allow click tracking
- hide_from_robots: Hide from search engines
- public_votes: Make votes public
- public_server_seconds: Show server processing time
- no_profanity: Filter profanity
- newwindow: Open links in new window
- numsites: Custom number of links per page
- media: Auto-expand media
- media_preview: Show media previews
- nightmode: Use night mode
"""Access user trophies and achievements.
class Trophy:
"""User trophy/achievement."""
name: str # Trophy name
description: str # Trophy description
icon_40: str # 40px icon URL
icon_70: str # 70px icon URL
award_id: str # Award ID
granted_at: float # Grant timestamp (UTC)
url: str # Trophy details URL
class TrophyList:
"""Container for user trophies."""
def __iter__(self):
"""Iterate over trophies."""
def __len__(self):
"""Number of trophies."""Manage user's multireddits (curated subreddit collections).
class Multireddit:
"""User's multireddit collection."""
def add(self, subreddit):
"""Add subreddit to multireddit."""
def remove(self, subreddit):
"""Remove subreddit from multireddit."""
def update(self, **settings):
"""Update multireddit settings."""
def copy_from(self, multireddit):
"""Copy from another multireddit."""
def rename(self, new_name: str):
"""Rename the multireddit."""
def delete(self):
"""Delete the multireddit."""
class MultiredditHelper:
"""Helper for multireddit management."""
def create(
self,
display_name: str,
subreddits: list,
*,
description_md: str = None,
visibility: str = "private",
**kwargs
):
"""
Create new multireddit.
Parameters:
- display_name: Multireddit name
- subreddits: List of subreddit names
- description_md: Description (markdown)
- visibility: "private" or "public"
Returns:
Multireddit instance
"""Find and search for Reddit users.
class Redditors:
"""Redditor discovery and search."""
def new(self, **kwargs):
"""
Get new redditors.
Returns:
ListingGenerator of Redditor instances
"""
def popular(self, **kwargs):
"""
Get popular redditors.
Returns:
ListingGenerator of Redditor instances
"""
def search(self, query: str, **kwargs):
"""
Search for redditors.
Parameters:
- query: Search query
- limit: Number of results (default: 25, max: 100)
Returns:
ListingGenerator of Redditor instances
"""# Get user by name
user = reddit.redditor("username")
# Access user info
print(f"User: {user.name}")
print(f"Comment Karma: {user.comment_karma}")
print(f"Link Karma: {user.link_karma}")
print(f"Account Age: {user.created_utc}")
# Check if user has Reddit Premium
if user.is_gold:
print("User has Reddit Premium")
# Get user's recent submissions
for submission in user.submissions.new(limit=10):
print(f"Post: {submission.title}")
# Get user's recent comments
for comment in user.comments.new(limit=10):
print(f"Comment: {comment.body[:50]}...")# Add/remove friends
user = reddit.redditor("friend_username")
user.friend()
user.unfriend()
# Block/unblock users
spam_user = reddit.redditor("spam_username")
spam_user.block()
spam_user.unblock()
# Get current user's friends and blocked lists
my_friends = reddit.user.friends()
blocked_users = reddit.user.blocked()
print(f"Friends: {len(my_friends)}")
print(f"Blocked: {len(blocked_users)}")# Send private message to user
recipient = reddit.redditor("recipient_username")
recipient.message(
subject="Hello from PRAW",
message="This is a test message sent using PRAW!"
)
# Send message from subreddit
recipient.message(
subject="Mod Message",
message="Message from the moderation team.",
from_subreddit=reddit.subreddit("mysubreddit")
)# Get current user info
me = reddit.user.me()
print(f"Logged in as: {me.name}")
# Get karma breakdown by subreddit
karma_breakdown = reddit.user.karma()
for subreddit, karma in karma_breakdown.items():
print(f"r/{subreddit}: {karma['comment_karma']} comment, {karma['link_karma']} link")
# Get user preferences
prefs = reddit.user.preferences()
print(f"Language: {prefs['lang']}")
print(f"NSFW enabled: {prefs['over_18']}")
# Get moderated subreddits
for subreddit in reddit.user.moderator_subreddits():
print(f"Moderates: r/{subreddit.display_name}")
# Get user's trophies
trophies = reddit.user.trophies()
for trophy in trophies:
print(f"Trophy: {trophy.name} - {trophy.description}")# Stream new submissions from user
target_user = reddit.redditor("target_username")
for submission in target_user.stream.submissions():
print(f"New post by {target_user.name}: {submission.title}")
# Stream new comments from user
for comment in target_user.stream.comments():
print(f"New comment by {target_user.name}: {comment.body[:100]}...")# Search for users
for user in reddit.redditors.search("python developer", limit=5):
print(f"Found user: {user.name}")
# Get new users
for user in reddit.redditors.new(limit=10):
print(f"New user: {user.name}")
# Get popular users
for user in reddit.redditors.popular(limit=10):
print(f"Popular user: {user.name}")# Create multireddit
multi = reddit.multireddit.create(
display_name="Tech News",
subreddits=["technology", "programming", "Python"],
description_md="Technology and programming news",
visibility="public"
)
# Add subreddit to existing multireddit
multi.add("MachineLearning")
# Get user's multireddits
user_multis = reddit.user.multireddits()
for multi in user_multis:
print(f"Multireddit: {multi.display_name}")class UserSubreddit:
"""User's profile subreddit."""
display_name: str # Profile name
title: str # Profile title
public_description: str # Profile description
icon_img: str # Profile icon URL
banner_img: str # Profile banner URL
subscribers: int # Profile followers countInstall with Tessl CLI
npx tessl i tessl/pypi-praw