Skip to main content

LangChain

langchain-gnews gives LangChain and LangGraph agents two tools built on the GNews API. Web search tools return the most relevant pages; these tools return dated news articles with their source, filterable by country and language, including over past periods.

ToolName seen by the modelUse it for
GNewsTopHeadlinesgnews_top_headlinesToday's top headlines, ranked like Google News, by category, country and language: news briefings, digests
GNewsSearchgnews_searchArticles about a topic, company or person, filtered by language, country and date, over an archive since 2020

Each tool call makes one API request with your key: it counts toward your daily quota and follows your plan (articles per request, historical archive and data freshness, see Article Availability).

Install​

pip install langchain-gnews

Python 3.10+. The package depends on langchain-core 1.x and on the official Python SDK.

Get a free API key at gnews.io/register, then put it in the GNEWS_API_KEY environment variable, or pass it to the tools with api_key="YOUR_API_KEY".

export GNEWS_API_KEY="YOUR_API_KEY"

Use With an Agent​

Requires langchain and a model integration, for example pip install langchain langchain-anthropic.

from langchain.agents import create_agent
from langchain_gnews import GNewsSearch, GNewsTopHeadlines

agent = create_agent("anthropic:claude-sonnet-5-5", tools=[GNewsTopHeadlines(), GNewsSearch()])
agent.invoke({"messages": [{"role": "user", "content": "Summarize this morning's top business headlines in France"}]})

The model picks the tool from its description: headlines for a briefing, search for a topic or a period.

Use Directly​

from langchain_gnews import GNewsSearch, GNewsTopHeadlines

GNewsTopHeadlines().invoke({"category": "business", "country": "fr", "lang": "fr"})
GNewsSearch().invoke({"q": '"NVIDIA" AND earnings', "lang": "en", "from_date": "2025-01-01", "to_date": "2025-03-31"})

Both return {"total_articles": int, "articles": [...]}, each article with title, description, content, url, source and published_at.

Available Tools​

Searches articles by keywords, like the Search endpoint.

ParameterDefaultDescription
qrequiredKeywords, with the query syntax (quotes, AND, OR, NOT, parentheses)
langany2-letter language code, e.g. en
countryany2-letter country code of the source, e.g. us
from_datenoneOldest publication date, ISO 8601, e.g. 2025-03-01. The archive starts in 2020
to_datenoneNewest publication date, ISO 8601
sortbypublishedAtpublishedAt (most recent first) or relevance

gnews_top_headlines​

Gets the current trending articles of a category, like the Top Headlines endpoint.

ParameterDefaultDescription
categorygeneralgeneral, world, nation, business, technology, entertainment, sports, science or health
langany2-letter language code, e.g. en
countryany2-letter country code, e.g. us
qnoneOptional keywords to narrow the headlines

Options​

Both tools accept these keyword arguments when created, e.g. GNewsSearch(max_results=5, include_content=False).

OptionDefaultEffect
api_keyGNEWS_API_KEYGNews API key
max_results10Articles per call, up to the limit of your plan
include_contentTrueInclude the article text. Set to False to save tokens

API errors (invalid key, quota reached, rate limit) are returned to the model as tool errors instead of raising, so the agent can tell the user or try again.

What Your Plan Returns​

PlanArchiveFreshnessArticle text
Freelast 30 days12-hour delaytruncated
Paidsince 2020real timefull

See Article Availability, JSON Response and the pricing page.

Source Code​

The package is open source: github.com/gnews-io/langchain-gnews, published on PyPI.