Search⌘ K

Use PRAW to Interact With Posts and Comments

Explore how to use the Python Reddit API Wrapper (PRAW) to create and manage posts and comments on Reddit. Learn to submit posts, reply with comments, and efficiently read posts and comment threads from subreddits.

Make a post

We can make a post using the submit() method. We'll need to provide the title and the body to submit the post.

Here are some important parameters we'll use to call the method:

Parameter

Type

Category

Description

title

string

required

The title we want in our new post.

self_text

string

required

The body of the post.

Press "Run" to submit a new post to a subreddit.

Python 3.8
import praw
import json
reddit = praw.Reddit(
client_id="{{CLIENT_ID}}",
client_secret="{{CLIENT_SECRET}}",
refresh_token="{{REFRESH_TOKEN}}",
user_agent="testscript by u/{{USERNAME}}"
)
try:
subreddit = reddit.subreddit("{{SUBREDDIT_NAME}}")
title = "Sample title"
selftext = "Heyyy from PRAW!"
response = subreddit.submit(title=title,selftext=selftext)
print(response)
except Exception as e:
print(e)

Lines 4–9: We initialize the Reddit class, the parameters are explained here.

Line 11: We obtain an instance of the Subreddit class.

Lines 12–13: We make the variables title and selftext to ...