Skip to main content

🚀 langchain-stackoverflow

PyPI version Python 3.10+ License: MIT

LangChain retrievers for Stack Overflow — search questions and fetch full answers across the Stack Exchange network as LangChain Document objects. No API keys required (optional for higher rate limits).

Perfect for building coding assistants, RAG applications, and troubleshooting agents.

✨ Features

Retriever What it does API Key Required?
StackOverflowSearchRetriever Search questions by keyword or tags ❌ No!
StackOverflowAnswerRetriever Fetch all answers for a question ❌ No!

📦 Installation

pip install langchain-stackoverflow

🚀 Quick Start

Search Questions

from langchain_stackoverflow import StackOverflowSearchRetriever

retriever = StackOverflowSearchRetriever(
    max_results=3,
    sort="votes",           # "relevance", "votes", "creation", "activity"
    site="stackoverflow",   # any Stack Exchange site (e.g. "serverfault")
    tagged="python;pandas", # Optional: filter by tags
    accepted_only=True,     # Optional: only show questions with accepted answers
)

docs = retriever.invoke("how to merge dataframes")

for doc in docs:
    print(f"❓ {doc.page_content.splitlines()[0]}") # Print question title
    print(f"   👍 {doc.metadata['score']} votes | 💬 {doc.metadata['answer_count']} answers")
    print(f"   🔗 {doc.metadata['url']}")

Fetch Answers

from langchain_stackoverflow import StackOverflowAnswerRetriever

retriever = StackOverflowAnswerRetriever(sort="votes")

# Pass the Stack Overflow URL or just the question ID
docs = retriever.invoke("https://stackoverflow.com/questions/53645882/pandas-merge-two-dataframes-with-different-columns")

for doc in docs:
    if doc.metadata['is_accepted']:
        print("✅ ACCEPTED ANSWER:")
    else:
        print("💡 ANSWER:")
    
    print(f"Score: {doc.metadata['score']}")
    print(f"{doc.page_content[:150]}...\n")

🔑 Rate Limits & API Keys

By default, the Stack Exchange API allows 300 requests per day per IP address without an API key.

If you need more, you can register a free app at Stack Apps to get an API key, which increases your quota to 10,000 requests per day.

Pass your key to the retriever:

retriever = StackOverflowSearchRetriever(api_key="your_key_here")

📄 License

MIT — see LICENSE for details.

Metadata

Release files for langchain-stackoverflow 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-stackoverflow 0.1.0
File Size Uploaded
langchain_stackoverflow-0.1.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-stackoverflow 0.1.0
File Interpreter ABI Platform
langchain_stackoverflow-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / langchain_stackoverflow-0.1.0.tar.gz

Download URL langchain_stackoverflow-0.1.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
edc7a1145419f296a3dc7de75b70da40a8d28fc4aca45fb4c226d9ed1806eea6
BLAKE2b-256 checksum
How to use checksums
bf40f169e48e03a7e1508005352cbc43c6f49b50e75604f99f6f369f2a1d4c73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / langchain_stackoverflow-0.1.0-py3-none-any.whl

Download URL langchain_stackoverflow-0.1.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
098f22c8afce513b11415e74c9945922b4d42995eb5be280493366fe8cf9a4fe
BLAKE2b-256 checksum
How to use checksums
1ad5819de86921ff9151b0abe2e894a5a63c061604c9c833b5d6262996589daa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page