Skip to main content

AllNewsAPI Python SDK

PyPI License: MIT

A lightweight Python SDK for the AllNewsAPI with zero external dependencies.

Installation

pip install allnewsapi

Quick Start

from allnewsapi import NewsAPI

client = NewsAPI("your-api-key")

results = client.search(q="artificial intelligence", lang="en", max=10)

for article in results.articles:
    print(f"{article.title} — {article.source.name}")

Methods

search(**kwargs) -> SearchResponse

Search for news articles matching any combination of filters.

results = client.search(
    q="climate change",
    start_date="2024-01-01",
    end_date="2024-06-01",
    lang=["en", "fr"],
    category="science",
    max=20,
)

headlines(**kwargs) -> SearchResponse

Fetch top headlines with the same filtering options as search.

headlines = client.headlines(country="us", category="business", max=5)

usage() -> UsageResponse

Check your API quota and consumption.

usage = client.usage()
print(f"Remaining: {usage.requests_remaining_24_hours}/{usage.requests_limit_24_hours}")

Parameter Reference

Parameter Type Description
q str Keywords to search for
start_date str | datetime Start date (ISO 8601)
end_date str | datetime End date (ISO 8601)
content bool Include full article content
lang str | list[str] Language(s) to filter by
country str | list[str] Country/countries to filter by
region str | list[str] Region(s) to filter by
category str | list[str] Category/categories to filter by
max int Maximum results (1-100)
attributes str | list[str] Search in title/description/content
page int Page number
sortby str Sort by publishedAt or relevance
publisher str | list[str] Publisher(s) to filter
format str Response format: json, csv, or xlsx
ai_sentiment str AI sentiment filter
ai_entity_name str AI entity name filter
ai_entity_type str AI entity type filter

Error Handling

from allnewsapi import NewsAPI, NewsAPIError

client = NewsAPI("your-api-key")

try:
    results = client.search(q="python")
except NewsAPIError as e:
    print(f"Error {e.status_code}: {e.message}")

License

MIT

Support

Found a bug or have a feature request? Please open an issue on GitHub.

Metadata

Release files for allnewsapi 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for allnewsapi 0.1.2
File Size Uploaded Provenance
allnewsapi-0.1.2.tar.gz 12.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for allnewsapi 0.1.2
File Interpreter ABI Platform
allnewsapi-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / allnewsapi-0.1.2.tar.gz

Download URL allnewsapi-0.1.2.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0c425756a8b5159f14f2424d42870af024f177bb149940df12bfe0dba5082963
BLAKE2b-256 checksum
How to use checksums
91f8127e611198a449d8b6757815e0d7e1859a1af22d8dfc82b6fbc011822509
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / allnewsapi-0.1.2-py3-none-any.whl

Download URL allnewsapi-0.1.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
395fd89534a5f309cc3377c9381872ce5f38449a0267917df95223d839f3c261
BLAKE2b-256 checksum
How to use checksums
97ff321e3474866d8e5f3fe2febf00dcbba225ddf5c5b351ba79f7edfde63c7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for allnewsapi 0.1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page