🚀 langchain-reddit
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.
✨ Features
| 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 |
🔑 Getting Reddit Credentials
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.
📦 Installation
pip install langchain-reddit
🚀 Quick Start
Search Reddit Posts
from 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")
Fetch Subreddit Feed
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")
Fetch a Comment Thread
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]}...")
📄 License
MIT — see LICENSE for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_reddit-0.1.0.tar.gz.
File metadata
- Download URL: langchain_reddit-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f6cfca8dc2f0eaa5102fabe1e0b17ea8cb14f8e2b5d3874ff9c410c99bf0aca
|
|
| MD5 |
970c4e342c128cfefe59acad355190e1
|
|
| BLAKE2b-256 |
ebe3f606fbdb6a6136e35e63cd42496d9d730859bbfbfafe65fce30ac1793cf4
|
File details
Details for the file langchain_reddit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_reddit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06172ead5b8a7f4986dd073de4886117f8e76f40e0caa8b81f46e6bd23ad0c25
|
|
| MD5 |
8f9d6ffd9d6866adb76ca0796bf58f79
|
|
| BLAKE2b-256 |
740170e2b17875d5f0469114e4f8dc5a73f00ad48dd3730a1477a62d1219432c
|