The Wayback Machine - https://web.archive.org/web/20220705000723/https://www.geeksforgeeks.org/python-praw-python-reddit-api-wrapper/amp/

Python | PRAW – Python Reddit API Wrapper

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.
Prerequisites
 

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: 
 

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
print(reddit.read_only)

Output: 
 

True

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
print(reddit.read_only)

Output: 
 

False

To switch back to read-only mode: 
 




reddit.read_only = True

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




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

GRE
GRE
#/r/GRE  

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!

  

-----

#Rules

- You must read and follow the rules! 
https://www.reddit.com/r/gre/about/rules

-----




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

6554

 




Article Tags :