The News API Python Wrapper
This package provides an asynchronous Python client for The News API, allowing you to easily fetch headlines, top stories, all news, sources, and similar articles.
Features
- Async API client using
httpx - Typed responses via Pydantic models
- Category validation
- Context manager support for resource management
Endpoints
The client exposes the following endpoints:
- get_headlines: Get the latest headlines.
- get_top_stories: Fetch top stories with advanced filtering.
- get_all_news: Retrieve all news articles with search and filter options.
- get_sources: List available news sources.
- get_similar_news: Find articles similar to a given article UUID.
- get_news_by_uuid: Fetch a single article by its UUID.
Installation
pip install py-the-news-api
Usage
import asyncio
from the_news_api.client import NewsAPIClient
async def main():
async with NewsAPIClient(api_token="YOUR_API_TOKEN") as client:
headlines = await client.get_headlines(language="en")
print(headlines)
asyncio.run(main())
Example: Fetch Top Stories
async with NewsAPIClient(api_token="YOUR_API_TOKEN") as client:
stories = await client.get_top_stories(categories=["tech", "science"], limit=5)
for article in stories.articles:
print(article.title)
Category Filtering
Supported categories:
general,science,sports,business,health,entertainment,tech,politics,food,travel
License
MIT
Links
Metadata
Release files for py-the-news-api 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 | |
|---|---|---|---|
| py_the_news_api-0.1.0.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_the_news_api-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.8 kB
Release files / py_the_news_api-0.1.0.tar.gz
| Download URL | py_the_news_api-0.1.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ebdcf2e9e499f7521cffbc96ff4c477fd3bd80ddc6f4a610c856b3375d8fdfa
|
|
BLAKE2b-256 checksum How to use checksums |
7716a07108aa1535511e84bcc49ac14e89a53f5147d15ca7ac2f0dd07376afb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Sep 22, 2025.
Transparency logRelease files / py_the_news_api-0.1.0-py3-none-any.whl
| Download URL | py_the_news_api-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07363439e16f01367ef29685aa7bfd80a4d395ba40d0814a0b1feca8d3942803
|
|
BLAKE2b-256 checksum How to use checksums |
9d3eab15c1d4e97627c8edada16e45b413546e44435fe17a9cd12746e91e958a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Sep 22, 2025.
Transparency log