AskNews Python SDK
raw JSON → 0.13.40 verified Mon Apr 27 auth: no python
Python SDK for AskNews, providing access to news aggregation and analysis APIs. Current version: 0.13.40. Release cadence: frequent (multiple per month).
pip install asknews Common errors
error ImportError: cannot import name 'AskNews' from 'asknews_sdk' ↓
cause Old import path from pre-0.13.0 versions.
fix
Uninstall the old package (pip uninstall asknews-sdk) and install the new one (pip install asknews). Then use 'from asknews import AskNews'.
error asknews.exceptions.AuthenticationError: Invalid API key or user ID ↓
cause Missing or incorrect credentials.
fix
Set the environment variables ASKNEWS_API_KEY and ASKNEWS_USER_ID, or pass them directly to AskNews(api_key='...', user_id='...').
error TypeError: search_news() got an unexpected keyword argument 'lang' ↓
cause Parameter name changed in a recent version.
fix
Use 'language' instead of 'lang'. Check the method signature.
Warnings
breaking In v0.13.0, the SDK migrated from 'asknews_sdk' to 'asknews' package. Imports and API structure changed. ↓
fix Uninstall old package (pip uninstall asknews-sdk) and install asknews (pip install asknews). Update imports from asknews_sdk to asknews.
gotcha The API key and user ID must be provided together. Missing either will cause authentication failure. ↓
fix Set both environment variables: ASKNEWS_API_KEY and ASKNEWS_USER_ID.
gotcha The search_news method's 'return_type' parameter defaults to 'articles', but some endpoints expect 'story' or 'alert'. Using wrong type may return empty results. ↓
fix Check the API docs for the correct return_type value for your query.
Imports
- AskNews wrong
from asknews_sdk import AskNewscorrectfrom asknews import AskNews - NewsQuery
from asknews import NewsQuery
Quickstart
import os
from asknews import AskNews
client = AskNews(
api_key=os.environ.get('ASKNEWS_API_KEY', ''),
user_id=os.environ.get('ASKNEWS_USER_ID', '')
)
news = client.news.search_news(query='AI', return_type='articles')
print(news)