Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_the_news_api-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_the_news_api-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

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

Hashes for py_the_news_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4ebdcf2e9e499f7521cffbc96ff4c477fd3bd80ddc6f4a610c856b3375d8fdfa
MD5 83dd5b760fe1812583e1d1846ac5fce3
BLAKE2b-256 7716a07108aa1535511e84bcc49ac14e89a53f5147d15ca7ac2f0dd07376afb1

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_the_news_api-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_the_news_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07363439e16f01367ef29685aa7bfd80a4d395ba40d0814a0b1feca8d3942803
MD5 08cc98a40f702e03fd04b1b995a4e258
BLAKE2b-256 9d3eab15c1d4e97627c8edada16e45b413546e44435fe17a9cd12746e91e958a

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page