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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_stackoverflow-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_stackoverflow-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file langchain_stackoverflow-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_stackoverflow-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for langchain_stackoverflow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 edc7a1145419f296a3dc7de75b70da40a8d28fc4aca45fb4c226d9ed1806eea6
MD5 37cbb155de98dc910ed09f2024826339
BLAKE2b-256 bf40f169e48e03a7e1508005352cbc43c6f49b50e75604f99f6f369f2a1d4c73

See more details on using hashes here.

File details

Details for the file langchain_stackoverflow-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_stackoverflow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 098f22c8afce513b11415e74c9945922b4d42995eb5be280493366fe8cf9a4fe
MD5 dd7765e7c9b95f1f92eed6c39e2107e3
BLAKE2b-256 1ad5819de86921ff9151b0abe2e894a5a63c061604c9c833b5d6262996589daa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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