Python Reddit API Wrapper (PRAW)

7.8.1 · active · verified Sat Apr 11

PRAW (Python Reddit API Wrapper) is a Python package that provides a straightforward interface to Reddit's API. It abstracts away much of the complexity, adhering to Reddit's API rules internally, such as managing rate limits. The library is actively maintained, currently at version 7.8.1, with a regular release cadence that often includes new features and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize PRAW for both read-only (if only client_id, client_secret, and user_agent are provided) or authenticated (if username and password are also provided) access. It then shows how to fetch popular posts from a subreddit. Credentials should ideally be stored in a `praw.ini` file or environment variables, not hardcoded.

import praw
import os

# It's recommended to use a praw.ini file or environment variables for credentials.
# For quickstart, we'll use environment variables.

reddit = praw.Reddit(
    client_id=os.environ.get("REDDIT_CLIENT_ID", ""),
    client_secret=os.environ.get("REDDIT_CLIENT_SECRET", ""),
    password=os.environ.get("REDDIT_PASSWORD", ""),
    user_agent=os.environ.get("REDDIT_USER_AGENT", "my_unique_user_agent_string_v1.0 (by u/YOUR_REDDIT_USERNAME)"),
    username=os.environ.get("REDDIT_USERNAME", ""),
)

# Example: Get top 5 hot posts from r/python
print("Top 5 hot posts from r/python:")
for submission in reddit.subreddit("python").hot(limit=5):
    print(f"- {submission.title} (Score: {submission.score})")

# Example: Access your inbox (requires authenticated instance)
# try:
#     for message in reddit.inbox.unread(limit=5):
#         print(f"New message: {message.subject}")
#         message.mark_read()
# except prawcore.exceptions.ResponseException as e:
#     print(f"Could not access inbox (read_only instance or invalid auth?): {e}")

# To verify if the instance is read-only:
print(f"Is Reddit instance read-only? {reddit.read_only}")

view raw JSON →