Perigon is a comprehensive news API that provides access to real-time contextual information in news articles, stories, metadata and wikipedia pages from thousands of sources worldwide.

Installation and Setup

Perigon integration exists in its own partner package. You can install it with:
%pip install -qU langchain-perigon
In order to use the package, you will also need to set the PERIGON_API_KEY environment variable to your Perigon API key.

Retrievers

Perigon provides two retrievers:

ArticlesRetriever

This retriever retrieves articles based on a given query and optional filters. See a full usage example.
# Make sure PERIGON_API_KEY environment variable is set to your Perigon API key
from langchain_perigon import ArticlesRetriever, ArticlesFilter

# Create retriever with specific number of results
retriever = ArticlesRetriever(k=12)

# Configure filter options to exclude reprints and focus on US articles
options: ArticlesFilter = {
    "showReprints": False,  # Exclude duplicate/reprint articles
    "filter": {"country": "us"},  # Only US-based news
}

try:
    documents = retriever.invoke("Recent big tech layoffs", options=options)

    # Check if we got results before accessing
    if documents:
        print(f"First document: {documents[0].page_content[:200]}...")
    else:
        print("No articles found for the given query.")
except Exception as e:
    print(f"Error retrieving articles: {e}")
You can use the ArticlesRetriever in a standard retrieval pipeline:

WikipediaRetriever

This retriever retrieves wikipedia pages based on a given query and optional filters. See a full usage example.
# Make sure PERIGON_API_KEY environment variable is set to your Perigon API key
from langchain_perigon import WikipediaRetriever

# Create retriever with specific number of results
retriever = WikipediaRetriever(k=12)

try:
    documents = retriever.invoke("machine learning")

    # Safely access results with error handling
    if documents:
        print(f"First document: {documents[0].page_content[:200]}...")
    else:
        print("No Wikipedia articles found for the given query.")
except Exception as e:
    print(f"Error retrieving Wikipedia articles: {e}")
You can use the WikipediaRetriever in a standard retrieval pipeline: