or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdcontent-discovery.mdindex.mdlive-threads.mdmessaging-inbox.mdmoderation.mdreddit-client.mdsubmissions-comments.mdsubreddits.mduser-management.md
tile.json

tessl/pypi-praw

Python Reddit API Wrapper - simple access to Reddit's API

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/praw@7.8.x

To install, run

npx @tessl/cli install tessl/pypi-praw@7.8.0

index.mddocs/

PRAW (Python Reddit API Wrapper)

PRAW provides simple access to Reddit's API while following all of Reddit's API rules automatically. It handles authentication, rate limiting, and API compliance, making it easy to build Reddit bots, data analysis tools, content aggregators, and moderation utilities. PRAW supports both script-based and web application OAuth flows and provides extensive object-oriented models for Reddit entities.

Package Information

  • Package Name: praw
  • Language: Python
  • Installation: pip install praw
  • Supported Python: 3.8+

Core Imports

import praw

Primary usage:

from praw import Reddit

Basic Usage

import praw

# Create Reddit instance with script authentication
reddit = praw.Reddit(
    client_id="CLIENT_ID",
    client_secret="CLIENT_SECRET", 
    password="PASSWORD",
    user_agent="USERAGENT",
    username="USERNAME",
)

# Access a subreddit
subreddit = reddit.subreddit("python")

# Submit a new post
submission = subreddit.submit("My Title", selftext="My post content")

# Get top submissions
for submission in subreddit.hot(limit=10):
    print(submission.title)
    
# Reply to a submission
submission.reply("Great post!")

# Access user information
redditor = reddit.redditor("username")
print(f"User karma: {redditor.comment_karma}")

Architecture

PRAW is built around a central Reddit client that provides access to specialized helper objects and models:

  • Reddit Client: Main entry point managing authentication and API requests
  • Models: Object-oriented representations of Reddit entities (Submission, Comment, Subreddit, Redditor)
  • Helpers: Specialized classes for discovery, authentication, and content management
  • Listing Generators: Efficient iteration over API results with automatic pagination

Capabilities

Reddit Client

Core Reddit API client providing authentication, request handling, and access to all Reddit functionality.

class Reddit:
    def __init__(
        self,
        site_name: str = None,
        config_interpolation: str = None,
        requestor_class = None,
        requestor_kwargs: dict = None,
        token_manager = None,
        **config_settings
    ): ...
    
    def comment(self, id: str = None, url: str = None): ...
    def submission(self, id: str = None, url: str = None): ...
    def redditor(self, name: str = None, fullname: str = None): ...
    def subreddit(self, display_name: str): ...
    def random_subreddit(self, nsfw: bool = False): ...
    def info(self, fullnames: list = None, subreddits: list = None, url: str = None): ...
    def username_available(self, name: str) -> bool: ...
    def domain(self, domain: str): ...
    
    # HTTP Methods
    def get(self, path: str, params: dict = None): ...
    def post(self, path: str, data: dict = None, files: dict = None, json: dict = None, params: dict = None): ...
    def put(self, path: str, data: dict = None, json: dict = None): ...
    def patch(self, path: str, data: dict = None, json: dict = None, params: dict = None): ...
    def delete(self, path: str, data: dict = None, json: dict = None, params: dict = None): ...
    def request(self, method: str, path: str, params: dict = None, data: dict = None, files: dict = None, json: dict = None): ...
    
    # Properties
    read_only: bool
    validate_on_submit: bool
    
    # Helper Objects
    auth: Auth
    front: Front
    inbox: Inbox
    user: User
    subreddits: Subreddits
    redditors: Redditors
    drafts: DraftHelper
    live: LiveHelper
    multireddit: MultiredditHelper
    notes: RedditModNotes

Reddit Client

Submissions and Comments

Interact with Reddit posts and comments including creating, editing, voting, and managing content.

class Submission:
    def submit(self, title: str, **kwargs): ...
    def reply(self, body: str): ...
    def edit(self, body: str): ...
    def delete(self): ...
    def upvote(self): ...
    def downvote(self): ...
    def clear_vote(self): ...

class Comment:
    def reply(self, body: str): ...
    def edit(self, body: str): ...
    def delete(self): ...
    def parent(self): ...

Submissions and Comments

Subreddits

Access and manage subreddit communities including posting, searching, moderation, and configuration.

class Subreddit:
    def submit(self, title: str, **kwargs): ...
    def search(self, query: str, **kwargs): ...
    def subscribe(self): ...
    def unsubscribe(self): ...
    def message(self, subject: str, message: str, **kwargs): ...
    def hot(self, **kwargs): ...
    def new(self, **kwargs): ...
    def top(self, **kwargs): ...

Subreddits

User Management

Work with Reddit users including profiles, messaging, friends, and user-generated content.

class Redditor:
    def message(self, subject: str, message: str, **kwargs): ...
    def friend(self): ...
    def unfriend(self): ...
    def block(self): ...
    def unblock(self): ...

class User:
    def me(self): ...
    def karma(self): ...
    def friends(self): ...
    def blocked(self): ...

User Management

Authentication

Handle OAuth authentication flows including script apps, web apps, and token management.

class Auth:
    def authorize(self, code: str): ...
    def implicit(self, access_token: str, expires_in: int, scope: str): ...
    def url(self, scopes: list, state: str, **kwargs) -> str: ...
    def revoke_token(self, token: str, **kwargs): ...
    def scopes(self) -> set: ...

Authentication

Content Discovery

Discover content across Reddit including front page, popular posts, trending subreddits, and user discovery.

class Front:
    def best(self, **kwargs): ...
    def hot(self, **kwargs): ...
    def new(self, **kwargs): ...
    def top(self, **kwargs): ...
    def controversial(self, **kwargs): ...

class Subreddits:
    def popular(self, **kwargs): ...
    def new(self, **kwargs): ...
    def search(self, query: str, **kwargs): ...

Content Discovery

Messaging and Inbox

Manage private messages, modmail, notifications, and inbox functionality.

class Inbox:
    def all(self, **kwargs): ...
    def unread(self, **kwargs): ...
    def messages(self, **kwargs): ...
    def comment_replies(self, **kwargs): ...
    def submission_replies(self, **kwargs): ...
    def mentions(self, **kwargs): ...

Messaging and Inbox

Moderation

Comprehensive moderation tools for submissions, comments, users, and subreddit management.

class SubredditModeration:
    def approve(self, thing): ...
    def remove(self, thing, **kwargs): ...
    def spam(self, thing): ...
    def distinguish(self, thing, **kwargs): ...
    def ignore_reports(self, thing): ...
    def unignore_reports(self, thing): ...

Moderation

Live Threads

Create and manage Reddit live threads for real-time event coverage.

class LiveHelper:
    def create(self, title: str, **kwargs): ...
    def info(self, ids: list): ...
    def now(self): ...

class LiveThread:
    def contribute(self): ...
    def discussions(self, **kwargs): ...
    def updates(self, **kwargs): ...

Live Threads

Exception Handling

PRAW-specific exceptions for error handling and API response management.

class PRAWException(Exception): ...
class RedditAPIException(PRAWException): ...
class APIException(PRAWException): ...
class ClientException(PRAWException): ...
class InvalidURL(ClientException): ...
class ReadOnlyException(ClientException): ...
class TooLargeMediaException(ClientException): ...
class DuplicateReplaceException(ClientException): ...
class InvalidFlairTemplateID(ClientException): ...
class InvalidImplicitAuth(ClientException): ...
class MissingRequiredAttributeException(ClientException): ...
class WebSocketException(ClientException): ...
class MediaPostFailed(WebSocketException): ...

Types

class Reddit:
    """Main Reddit API client."""
    read_only: bool
    validate_on_submit: bool
    auth: Auth
    front: Front
    inbox: Inbox
    user: User
    subreddits: Subreddits
    redditors: Redditors
    drafts: DraftHelper
    live: LiveHelper
    multireddit: MultiredditHelper
    notes: RedditModNotes

class Submission:
    """Reddit submission/post."""
    id: str
    title: str
    author: Redditor
    subreddit: Subreddit
    score: int
    num_comments: int
    created_utc: float
    url: str
    selftext: str
    thumbnail: str
    is_self: bool
    permalink: str
    shortlink: str
    stickied: bool
    over_18: bool
    spoiler: bool
    locked: bool
    
class Comment:
    """Reddit comment."""
    id: str
    author: Redditor
    body: str
    score: int
    created_utc: float
    is_root: bool
    replies: CommentForest
    permalink: str
    parent_id: str
    link_id: str
    subreddit: Subreddit
    stickied: bool
    is_submitter: bool

class Subreddit:
    """Reddit subreddit."""
    display_name: str
    subscribers: int
    description: str
    public_description: str
    over18: bool
    url: str
    created_utc: float
    subreddit_type: str
    lang: str
    title: str
    active_user_count: int
    
class Redditor:
    """Reddit user."""
    name: str
    comment_karma: int
    link_karma: int
    created_utc: float
    is_gold: bool
    is_mod: bool
    is_employee: bool
    has_verified_email: bool
    id: str
    verified: bool
    
class CommentForest:
    """Container for comment replies."""
    def replace_more(self, limit: int = 32, threshold: int = 0) -> list: ...
    def list(self) -> list[Comment]: ...
    
class More:
    """Represents collapsed comment threads."""
    count: int
    children: list[str]
    
class DraftHelper:
    """Helper for managing draft submissions."""
    def __call__(self, draft_id: str = None): ...
    
class LiveHelper:
    """Helper for live thread functionality."""
    def __call__(self, id: str): ...
    def create(self, title: str, **kwargs): ...
    def info(self, ids: list): ...
    def now(self): ...
    
class MultiredditHelper:
    """Helper for multireddit functionality."""
    def __call__(self, name: str, redditor: str): ...
    
class RedditModNotes:
    """Helper for moderator notes functionality."""
    def create(self, **kwargs): ...
    def delete(self, delete_id: str): ...