Reddit's comment-thread structure makes it a genuinely good source for sentiment analysis — long-form, context-rich text, organized into nested conversations rather than isolated replies — but building a pipeline that handles it well takes a bit more thought than running a sentiment model on a flat list of comments and calling it done.
Step 1: Collection
def collect_thread(post_id, token):
return requests.get(
"https://ensembledata.com/apis/reddit/post/comments",
params={"post_id": post_id, "token": token}
).json()["data"]
def find_relevant_posts(keyword, token):
return requests.get(
"https://ensembledata.com/apis/reddit/search",
params={"keyword": keyword, "token": token}
).json()["data"]
Start with keyword search to find relevant posts, then pull full comment threads for the posts that matter most (highest upvotes, most comments, or most recent, depending on your goal). EnsembleData's Reddit endpoints, including comment thread structure and pagination, are documented in the API docs.
Step 2: Preserve thread structure before scoring
This is the step people skip and shouldn't. A reply's sentiment often only makes sense in context of what it's replying to — "yeah, exactly" reads as neutral in isolation but inherits the sentiment of whatever it's agreeing with. Keep the parent_id relationship intact through your pipeline rather than flattening comments into an unordered list before scoring.
Step 3: Score with context awareness
def score_thread(comments, sia):
scored = []
for c in comments:
score = sia.polarity_scores(c["text"])["compound"]
scored.append({
"id": c["id"],
"parent_id": c.get("parent_id"),
"score": score,
"upvotes": c["score"]
})
return scored
Weighting by upvotes when aggregating to a post-level or topic-level sentiment score is worth doing — a comment with 400 upvotes represents community consensus more than one with two upvotes, and averaging them as equals understates that.
Step 4: Aggregate and visualize
Track sentiment at the subreddit or keyword level over time rather than just producing a single aggregate number. A time series showing sentiment shifting after a specific event (product launch, controversy, pricing change) is far more actionable than a static "62% positive" figure that doesn't tell you what changed or when.
A realistic caveat
Reddit sentiment is not representative of your entire user base — it's representative of the subset of your user base that posts on Reddit, which skews toward more vocal, often more critical users on both ends of the spectrum. Useful as a leading indicator and a source of specific, actionable feedback; less useful as a stand-in for overall customer satisfaction.