CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-praw

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

Pending
Overview
Eval results
Files

submissions-comments.mddocs/

Submissions and Comments

PRAW provides comprehensive support for interacting with Reddit submissions (posts) and comments. These models support all standard Reddit operations including creation, editing, voting, saving, and advanced features like gilding and moderation.

Capabilities

Submission Management

Create, edit, and manage Reddit submissions with full support for text posts, link posts, and media uploads.

class Submission:
    def __init__(self, reddit, id: str = None, url: str = None): ...
    
    @classmethod
    def id_from_url(cls, url: str) -> str:
        """
        Extract submission ID from Reddit URL.
        
        Parameters:
        - url: Reddit submission URL
        
        Returns:
        Submission ID (base36)
        """
    
    def reply(self, body: str):
        """
        Reply to submission with comment.
        
        Parameters:
        - body: Comment text (markdown supported)
        
        Returns:
        Comment instance
        """
    
    def edit(self, body: str):
        """
        Edit submission text (self posts only).
        
        Parameters:
        - body: New text content (markdown supported)
        
        Returns:
        Updated Submission instance
        """
    
    def delete(self):
        """Delete the submission."""
    
    def hide(self):
        """Hide submission from user's view."""
        
    def unhide(self):
        """Unhide submission from user's view."""
    
    def save(self, category: str = None):
        """
        Save submission.
        
        Parameters:
        - category: Save category (Reddit Premium feature)
        """
        
    def unsave(self):
        """Unsave submission."""
    
    def report(self, reason: str):
        """
        Report submission.
        
        Parameters:
        - reason: Report reason
        """

Submission Voting

Vote on submissions with support for upvotes, downvotes, and clearing votes.

def upvote(self):
    """Upvote the submission."""

def downvote(self):
    """Downvote the submission."""

def clear_vote(self):
    """Clear existing vote on submission."""

Submission Properties and Data

Access submission metadata, content, and related objects.

# Core properties
id: str  # Submission ID
title: str  # Submission title
author: Redditor  # Submission author
subreddit: Subreddit  # Subreddit where posted
score: int  # Current score (upvotes - downvotes)
upvote_ratio: float  # Ratio of upvotes (0.0-1.0)
num_comments: int  # Number of comments
created_utc: float  # Creation timestamp (UTC)
edited: bool | float  # Edit timestamp or False
url: str  # Submission URL
permalink: str  # Reddit permalink
shortlink: str  # Short Reddit URL (redd.it)

# Content properties  
selftext: str  # Self-post text content
selftext_html: str  # Self-post HTML content
is_self: bool  # Whether self-post
is_video: bool  # Whether video post
media: dict  # Media metadata
secure_media: dict  # Secure media metadata

# Status properties
archived: bool  # Whether archived
locked: bool  # Whether locked
pinned: bool  # Whether pinned
stickied: bool  # Whether stickied
over_18: bool  # Whether NSFW
spoiler: bool  # Whether spoiler
hidden: bool  # Whether hidden by user
saved: bool  # Whether saved by user
clicked: bool  # Whether clicked by user
visited: bool  # Whether visited by user

# Interaction objects
comments: CommentForest  # Comment tree
flair: SubmissionFlair  # Flair management
mod: SubmissionModeration  # Moderation actions

Comment Management

Create, edit, and manage Reddit comments with full threading support.

class Comment:
    def __init__(self, reddit, id: str = None, url: str = None): ...
    
    @classmethod
    def id_from_url(cls, url: str) -> str:
        """
        Extract comment ID from Reddit URL.
        
        Parameters:
        - url: Reddit comment URL
        
        Returns:
        Comment ID (base36)
        """
    
    def reply(self, body: str):
        """
        Reply to comment.
        
        Parameters:
        - body: Reply text (markdown supported)
        
        Returns:
        Comment instance
        """
    
    def edit(self, body: str):
        """
        Edit comment text.
        
        Parameters:
        - body: New comment text (markdown supported)
        
        Returns:
        Updated Comment instance
        """
    
    def delete(self):
        """Delete the comment."""
    
    def save(self, category: str = None):
        """
        Save comment.
        
        Parameters:
        - category: Save category (Reddit Premium feature)
        """
        
    def unsave(self):
        """Unsave comment."""
    
    def report(self, reason: str):
        """
        Report comment.
        
        Parameters:
        - reason: Report reason
        """
    
    def parent(self):
        """
        Get parent comment or submission.
        
        Returns:
        Comment or Submission instance
        """
    
    def refresh(self):
        """Refresh comment and load replies."""

Comment Voting

Vote on comments with support for upvotes, downvotes, and clearing votes.

def upvote(self):
    """Upvote the comment."""

def downvote(self):
    """Downvote the comment."""

def clear_vote(self):
    """Clear existing vote on comment."""

Comment Properties and Data

Access comment metadata, content, and threading information.

# Core properties
id: str  # Comment ID
body: str  # Comment text
body_html: str  # Comment HTML
author: Redditor  # Comment author
subreddit: Subreddit  # Subreddit where posted
submission: Submission  # Parent submission
score: int  # Current score
ups: int  # Upvote count
downs: int  # Downvote count (always 0)
created_utc: float  # Creation timestamp (UTC)
edited: bool | float  # Edit timestamp or False
permalink: str  # Comment permalink

# Threading properties
parent_id: str  # Parent comment/submission ID
is_root: bool  # Whether top-level comment
depth: int  # Comment thread depth
replies: CommentForest  # Comment replies

# Status properties
archived: bool  # Whether archived
locked: bool  # Whether locked
stickied: bool  # Whether stickied
saved: bool  # Whether saved by user
score_hidden: bool  # Whether score hidden
collapsed: bool  # Whether collapsed
is_submitter: bool  # Whether author is OP

# Interaction objects
mod: CommentModeration  # Moderation actions

Comment Forest Navigation

Navigate and manipulate comment trees efficiently.

class CommentForest:
    """Container for comment trees with lazy loading."""
    
    def __init__(self, submission): ...
    
    def list(self) -> list:
        """
        Return flattened list of all comments.
        
        Returns:
        List of Comment instances
        """
    
    def replace_more(self, limit: int = 32, threshold: int = 0) -> list:
        """
        Replace MoreComments objects with actual comments.
        
        Parameters:
        - limit: Maximum MoreComments to replace
        - threshold: Minimum comment count threshold
        
        Returns:
        List of MoreComments that were removed
        """

Advanced Features

Gilding Support

Give awards and gold to submissions and comments.

def gild(self):
    """Give gold award (Reddit Premium required)."""

def award(self, gild_type: str = "gid_1"):
    """
    Give specific award.
    
    Parameters:
    - gild_type: Award type ID
    """

Media and Rich Content

Handle media uploads and rich content in submissions.

# Inline media support
class InlineMedia:
    """Base class for inline media."""
    
class InlineGif(InlineMedia):
    """Inline GIF media."""
    
class InlineImage(InlineMedia):
    """Inline image media."""
    
class InlineVideo(InlineMedia):
    """Inline video media."""

Usage Examples

Creating Submissions

# Text post
subreddit = reddit.subreddit("test")
submission = subreddit.submit(
    title="My Text Post",
    selftext="This is the post content with **markdown** support."
)

# Link post  
submission = subreddit.submit(
    title="Interesting Article",
    url="https://example.com/article"
)

# Image post
submission = subreddit.submit_image(
    title="My Image",
    image_path="/path/to/image.jpg"
)

Working with Comments

# Get submission and add comment
submission = reddit.submission(id="abc123")
comment = submission.reply("Great post!")

# Reply to a comment
reply = comment.reply("Thanks for sharing!")

# Navigate comment tree
for top_comment in submission.comments:
    print(f"Comment: {top_comment.body}")
    for reply in top_comment.replies:
        print(f"  Reply: {reply.body}")

# Load all comments
submission.comments.replace_more(limit=None)
all_comments = submission.comments.list()

Voting and Interaction

# Vote on content
submission.upvote()
comment.downvote()

# Save interesting content
submission.save()
comment.save(category="interesting")

# Report problematic content
submission.report("Spam")
comment.report("Harassment")

Types

class MoreComments:
    """Placeholder for additional comments."""
    count: int  # Number of hidden comments
    children: list  # Child comment IDs
    
    def comments(self, **kwargs):
        """Load the additional comments."""

class SubmissionFlair:
    """Submission flair management."""
    
class CommentModeration:
    """Comment moderation actions."""
    
class SubmissionModeration:
    """Submission moderation actions."""

Install with Tessl CLI

npx tessl i tessl/pypi-praw

docs

authentication.md

content-discovery.md

index.md

live-threads.md

messaging-inbox.md

moderation.md

reddit-client.md

submissions-comments.md

subreddits.md

user-management.md

tile.json