This client wraps the Currents News API and gives you three main ways to get news:
- Latest News: Get the most recent articles in your language
- Search: Find articles by keywords or topics
- Category-based: Get news from specific categories like tech, business, sports, etc.
- Multi-language support - Works with 15+ languages (English, Spanish, French, German, etc.)
- Smart error handling - Handles API errors, rate limits, and connection issues gracefully
- Type safety - Full type hints and validation with Pydantic models
- Context manager - Clean resource management with
withstatements - Retry logic - Automatically retries failed requests
- Parameter validation - Checks inputs before making API calls
You'll need an API key from Currents News API.
git clone <your-repo-url>
cd currents-news-client
pip install -r requirements.txtexport NEWS_API_KEY="your_actual_api_key_here"
from currents_news_client import CurrentsClient
# Get the latest news
with CurrentsClient() as client:
news = client.get_latest_news("en", limit=5)
print(f"Found {news.total_count} articles")
for article in news.news:
print(f"- {article.title}")
print(f" Published: {article.published.strftime('%Y-%m-%d')}")
print(f" URL: {article.url}")latest = client.get_latest_news("en", limit=10)Gets the most recent news articles. Works with 15+ languages.
results = client.search_news("artificial intelligence", limit=20)Finds articles with specific keywords. You can also filter by domain.
tech_news = client.get_news_by_category("technology", limit=15)Gets articles from categories like:
world,politics,businesstechnology,sports,entertainmenthealth,science,regional
The client handles errors gracefully:
- Invalid API key → Clear error message
- Rate limiting → Automatic retry with backoff
- Network issues → Retry logic for failed connections
- Invalid parameters → Validation before API calls
- Server errors → Proper error classification
pip install -r requirements.txt
pytest tests/
mypy src/currents_news_client/
python3 -m flake8 src/ --config setup.cfgsrc/currents_news_client/
├── client.py # Main client class
├── models.py # Pydantic models
├── exceptions.py # Custom errors
└── types.py # Type definitions
tests/ # Test suite
examples/ # Usage examples
This project follows good practices:
- Type checking: Full mypy compliance with strict typing
- Linting: Follows wemake-python-styleguide (0.19.2)
- Testing: Good test coverage with pytest
- Documentation: Clear docstrings and examples
Check out the examples/ directory for more usage patterns, or run the demo:
python examples/basic_usage.pyFor detailed info about the API, see the official documentation.