Skip to content
Related Articles
Open in App
Not now

Related Articles

Python | PRAW – Python Reddit API Wrapper

Improve Article
Save Article
  • Last Updated : 09 Aug, 2021
Improve Article
Save Article

PRAW (Python Reddit API Wrapper) is a Python module that provides a simple access to Reddit’s API. PRAW is easy to use and follows all of Reddit’s API rules.
The documentation regarding PRAW is located here.

  • Basic Python Programming Skills
  • Basic Reddit Knowledge : Reddit is a network of communities based on people’s interests. Each of these communities is called a subreddit. Users can subscribe to multiple subreddits to post, comment and interact with them.
  • A Reddit Account

To install PRAW, we run the following pip script on the terminal / command prompt. 

pip install praw

After installing PRAW, we need to import it: 


import praw

After importing PRAW, we need to instantiate it. There are 2 types of PRAW instances: 

  • Read-only Instance: With read-only instance we can only retrieve public information from Reddit. Information like top 10 posts from a certain subreddit. We can’t post material from this.
  • Authorized Instance: With authorized instance we can do whatever a normal reddit account can do. Actions like comment, post, repost, upvote etc. can be performed.

Creating a read-only instance: 


reddit = praw.Reddit(client_id ='my client id',
                     client_secret ='my client secret',
                     user_agent ='my user agent')
# to verify whether the instance is read-only instance or not



Creating an authorized instance: 


reddit = praw.Reddit(client_id ='my client id',
                     client_secret ='my client secret',
                     user_agent ='my user agent',
                     username ='my username',
                     password ='my password')
# to verify whether the instance is authorized instance or not



To switch back to read-only mode: 


reddit.read_only = True

Now let us see some of the operations we can achieve using PRAW:

  • Access a Subreddit: In reddit there are multiple communities known as subreddits. We can obtain a subreddit instance using the method subreddit. 


subreddit = reddit.subreddit('GRE')
# display the subreddit name
# display the subreddit title
# display the subreddit description

  • Output : 

This subreddit is for discussion of the GRE (Graduate Record Examination). If you're studying for the GRE, or can help people who are studying for the GRE, you're in the right place!




- You must read and follow the rules!

  • Access a Submission: Within a subreddit there are multiple post submissions. We can iterate through the submissions in the submission instance. Reddit provides us multiple ways to sort submissions: 
    • rising
    • new
    • hot
    • gilded
    • controversial
    • top
  • Access a Redditor: In Reddit, the user is called a Redditor. We can obtain the redditor instance using the method redditor. In the method we pass the username of the redditor. 


# let the redditor be "AutoModerator"
redditor = reddit.redditor('AutoModerator')
# display AutoModerator's karma

  • Output: 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!