🚀 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.
Metadata
Release files for langchain-reddit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_reddit-0.1.0.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_reddit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.0 kB
Release files / langchain_reddit-0.1.0.tar.gz
| Download URL | langchain_reddit-0.1.0.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f6cfca8dc2f0eaa5102fabe1e0b17ea8cb14f8e2b5d3874ff9c410c99bf0aca
|
|
BLAKE2b-256 checksum How to use checksums |
ebe3f606fbdb6a6136e35e63cd42496d9d730859bbfbfafe65fce30ac1793cf4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / langchain_reddit-0.1.0-py3-none-any.whl
| Download URL | langchain_reddit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
06172ead5b8a7f4986dd073de4886117f8e76f40e0caa8b81f46e6bd23ad0c25
|
|
BLAKE2b-256 checksum How to use checksums |
740170e2b17875d5f0469114e4f8dc5a73f00ad48dd3730a1477a62d1219432c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|