GNews API Python Client
Official Python client for the GNews API: search news articles and top headlines from 80,000+ sources in 41 languages.
- No dependencies, Python 3.10+
- Typed responses (
Article,Source) with editor autocompletion - One exception per API error (invalid key, quota reached, rate limit...)
- Automatic retry on rate limit (429), server (5xx) and network errors
- Lazy pagination helpers that stop at a requested limit
Installation
pip install gnews-io-python
Note: gnews on PyPI is an unrelated Google News scraper and gnewsio is an unofficial client. The official client is gnews-io-python, imported as gnews_io.
Quick start
Get a free API key at gnews.io/register.
from gnews_io import GNews
client = GNews("YOUR_API_KEY") # or set the GNEWS_API_KEY environment variable and call GNews()
result = client.search("bitcoin", lang="en", max=10)
print(result.total_articles)
for article in result.articles:
print(article.published_at, article.source.name, article.title)
Search
from datetime import datetime, timezone
result = client.search(
'"Federal Reserve" AND rates',
lang="en",
country="us",
max=10,
in_=["title", "description"],
from_=datetime(2026, 10, 1, tzinfo=timezone.utc),
sortby="relevance",
)
The query supports quotes, AND, OR, NOT and parentheses: see the query syntax.
Top headlines
result = client.top_headlines("business", lang="en", country="us", max=10)
Categories: general (default), world, nation, business, technology, entertainment, sports, science, health.
Parameters
| Parameter | search |
top_headlines |
Notes |
|---|---|---|---|
q |
required | optional | Keywords, max 200 characters |
category |
first argument | One of the categories above | |
lang |
yes | yes | 2-letter language code, e.g. "en" |
country |
yes | yes | 2-letter country code, e.g. "us" |
max |
yes | yes | Articles per request, 1 to 100 depending on your plan (default 10) |
in_ |
yes | Fields to search: "title", "description", "content" (string or list) |
|
nullable |
yes | yes | Fields allowed to be null: "description", "content", "image" |
from_, to |
yes | yes | datetime, date or ISO 8601 string. Naive datetimes are treated as UTC |
sortby |
yes | "publishedAt" (default) or "relevance" |
|
page |
yes | yes | Page number, starts at 1 (up to 1,000 articles in total) |
truncate |
yes | yes | True to truncate content |
in_ and from_ end with an underscore because in and from are Python keywords.
Full reference: docs.gnews.io.
Response
search and top_headlines return an ArticlesResponse:
| Attribute | Type |
|---|---|
total_articles |
int |
articles |
list[Article] |
raw |
dict, the JSON returned by the API |
Each Article has id, title, description, content, url, image, published_at (timezone-aware datetime, UTC), lang and source (id, name, url, country). source.country is only returned by search.
On the Free plan, content is truncated. Full content is available on paid plans.
Pagination
iter_search and iter_top_headlines take the same parameters as search and top_headlines, fetch the next page only when you reach it, and stop at limit, at the last page or at the API's 1,000-article cap:
for article in client.iter_search("climate", lang="en", max=10, limit=50):
print(article.title)
Each page is one API request. You can also pass page yourself to search and top_headlines.
Error handling
All errors inherit from GNewsError, which exposes status (HTTP code) and errors (the API error payload).
from gnews_io import GNews, GNewsError, QuotaExceededError
try:
result = client.search("bitcoin")
except QuotaExceededError:
print("Daily quota reached, it resets at 00:00 UTC")
except GNewsError as e:
print(e.status, e)
| Exception | HTTP | Cause |
|---|---|---|
BadRequestError |
400 | Missing or invalid parameter, query syntax error |
AuthenticationError |
401 (or 400) | Missing or invalid API key |
QuotaExceededError |
403 | Daily quota reached or subscription expired |
RateLimitError |
429 | Too many requests per second (1/s on Free, 10/s on paid plans) |
ServerError |
5xx | Server error or maintenance |
GNewsError |
Base class, also raised on network errors and invalid responses |
Rate limit, server and network errors are retried twice with a short randomized backoff (about 1 s, then 2 s) before raising. Change it with GNews(max_retries=0).
Options
client = GNews(
"YOUR_API_KEY",
timeout=10.0, # seconds per request
max_retries=2, # retries on 429, 5xx and network errors
)
Development
pip install -e ".[dev]"
python -m unittest discover -v
mypy
License
MIT
Metadata
Release files for gnews-io-python 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 | |
|---|---|---|---|
| gnews_io_python-0.1.0.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gnews_io_python-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.7 kB
Release files / gnews_io_python-0.1.0.tar.gz
| Download URL | gnews_io_python-0.1.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c4d0c254fe49e464d19fce5492cde7c9ea62501bff9117e3efb2e3887b635a01
|
|
BLAKE2b-256 checksum How to use checksums |
75b4c34f70fae69ce70b070376972a77f1089a916ee8457f695a66fece241a97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / gnews_io_python-0.1.0-py3-none-any.whl
| Download URL | gnews_io_python-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
166a95e7d20647e490c6a7e15c30162db6cda49ba9b9e2b7d988862cc35c24c2
|
|
BLAKE2b-256 checksum How to use checksums |
d21a95d1aefcdd373f84039d13744cbb3a91e9d3ca2c3df9741c893486ee609d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency log