A Python wrapper for The News API.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_the_news_api-0.1.0.tar.gz.
File metadata
- Download URL: py_the_news_api-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ebdcf2e9e499f7521cffbc96ff4c477fd3bd80ddc6f4a610c856b3375d8fdfa
|
|
| MD5 |
83dd5b760fe1812583e1d1846ac5fce3
|
|
| BLAKE2b-256 |
7716a07108aa1535511e84bcc49ac14e89a53f5147d15ca7ac2f0dd07376afb1
|
Provenance
The following attestation bundles were made for py_the_news_api-0.1.0.tar.gz:
Publisher:
workflow.yml on Karsten-Larson/the-news-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_the_news_api-0.1.0.tar.gz -
Subject digest:
4ebdcf2e9e499f7521cffbc96ff4c477fd3bd80ddc6f4a610c856b3375d8fdfa - Sigstore transparency entry: 544558627
- Sigstore integration time:
-
Permalink:
Karsten-Larson/the-news-api@d6608c034b90dc8e8c6fbabd4b4024355cf86d8f -
Branch / Tag:
refs/tags/v.0.1.0 - Owner: https://github.com/Karsten-Larson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@d6608c034b90dc8e8c6fbabd4b4024355cf86d8f -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_the_news_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_the_news_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07363439e16f01367ef29685aa7bfd80a4d395ba40d0814a0b1feca8d3942803
|
|
| MD5 |
08cc98a40f702e03fd04b1b995a4e258
|
|
| BLAKE2b-256 |
9d3eab15c1d4e97627c8edada16e45b413546e44435fe17a9cd12746e91e958a
|
Provenance
The following attestation bundles were made for py_the_news_api-0.1.0-py3-none-any.whl:
Publisher:
workflow.yml on Karsten-Larson/the-news-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_the_news_api-0.1.0-py3-none-any.whl -
Subject digest:
07363439e16f01367ef29685aa7bfd80a4d395ba40d0814a0b1feca8d3942803 - Sigstore transparency entry: 544558641
- Sigstore integration time:
-
Permalink:
Karsten-Larson/the-news-api@d6608c034b90dc8e8c6fbabd4b4024355cf86d8f -
Branch / Tag:
refs/tags/v.0.1.0 - Owner: https://github.com/Karsten-Larson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@d6608c034b90dc8e8c6fbabd4b4024355cf86d8f -
Trigger Event:
push
-
Statement type: