AllNewsAPI Python SDK
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
allnewsapi-0.1.2.tar.gz
(12.3 kB
view details)
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 allnewsapi-0.1.2.tar.gz.
File metadata
- Download URL: allnewsapi-0.1.2.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c425756a8b5159f14f2424d42870af024f177bb149940df12bfe0dba5082963
|
|
| MD5 |
88a4fa0a8d996c492391e15644a60541
|
|
| BLAKE2b-256 |
91f8127e611198a449d8b6757815e0d7e1859a1af22d8dfc82b6fbc011822509
|
File details
Details for the file allnewsapi-0.1.2-py3-none-any.whl.
File metadata
- Download URL: allnewsapi-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
395fd89534a5f309cc3377c9381872ce5f38449a0267917df95223d839f3c261
|
|
| MD5 |
8afa099767a9715d1e8a77b5f656f008
|
|
| BLAKE2b-256 |
97ff321e3474866d8e5f3fe2febf00dcbba225ddf5c5b351ba79f7edfde63c7f
|