LangChain retrievers for Reddit — search posts, fetch subreddit feeds, and retrieve full comment trees as LangChain Document objects using PRAW.
Perfect for building RAG applications that can analyze sentiment on Reddit, read trending news, and summarize discussion threads.
| Retriever | What it does | API Key Required? |
|---|---|---|
RedditSearchRetriever |
Search Reddit posts by keyword | ✅ Yes |
RedditSubredditRetriever |
Fetch hot/new/top posts from a subreddit | ✅ Yes |
RedditCommentsRetriever |
Fetch a full discussion thread for a post | ✅ Yes |
You need a free Reddit App to get your client_id and client_secret.
- Go to https://www.reddit.com/prefs/apps
- Click "create another app..." at the bottom.
- Fill in the details:
- name:
langchain-reddit - type: Select script
- redirect uri:
http://localhost:8080(Not used, but required)
- name:
- Click Create app.
- Your client_id is under the app name, and client_secret is in the details.
pip install langchain-redditfrom langchain_reddit import RedditSearchRetriever
retriever = RedditSearchRetriever(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
subreddit="python", # Optional: default is "all"
max_results=5,
sort="relevance",
)
docs = retriever.invoke("langchain")
for doc in docs:
print(f"📰 {doc.page_content.splitlines()[0]}")
print(f" 👍 {doc.metadata['score']} upvotes | 💬 {doc.metadata['num_comments']} comments")from langchain_reddit import RedditSubredditRetriever
retriever = RedditSubredditRetriever(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
subreddit_name="machinelearning",
listing="hot", # "hot", "new", "top", "rising"
max_results=10,
)
# The query is ignored for subreddit feeds
docs = retriever.invoke("fetch")from langchain_reddit import RedditCommentsRetriever
retriever = RedditCommentsRetriever(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
max_results=50,
)
# Pass the post URL or ID
docs = retriever.invoke("https://www.reddit.com/r/Python/comments/1f2a3b4/example_post/")
for doc in docs:
print(f"💬 {doc.metadata['author']}: {doc.page_content[:80]}...")MIT — see LICENSE for details.