News API Reference¶
financelib.news.client.News(data: Optional[Dict[str, str]] = None)
¶
Represents a news article with metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Optional[Dict[str, str]]
|
Dictionary with article data (title, content, date, author, etc.). |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
Article title. |
content |
str
|
Article body text. |
date |
str | date | datetime
|
Publication date. |
author |
str
|
Author name(s). |
category |
str
|
Article category (default: 'news'). |
source |
str
|
Source name. |
article_url |
str
|
URL to the full article. |
article_thumbnail_url |
str
|
URL to the article thumbnail image. |
Example
article = News({'title': 'BIST Rallies', 'content': 'Market surged...', 'date': '2025-01-01'}) print(article.title)
Source code in financelib/news/client.py
Functions¶
to_dict() -> Dict[str, str]
¶
Convert the news article to a dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dictionary with all article fields. |
Source code in financelib/news/client.py
financelib.news.client.BaseQueryClass
¶
Base class for news query implementations.
Subclasses must implement the search_articles method.
Functions¶
search_articles(query: str, limit: int = 5, print_results: bool = False) -> List[News]
¶
Search for articles matching a query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query string. |
required |
limit
|
int
|
Maximum number of results. |
5
|
print_results
|
bool
|
Whether to print results to console. |
False
|
Returns:
| Type | Description |
|---|---|
List[News]
|
List of News objects. |
Source code in financelib/news/client.py
financelib.news.client.BloombergQuery()
¶
Bases: BaseQueryClass
Bloomberg news scraper.
Fetches news articles from Bloomberg's search page via web scraping.
Example
query = BloombergQuery() articles = query.search_articles("Turkish stocks", limit=3)
Source code in financelib/news/client.py
Functions¶
print_article_details(article: News) -> None
¶
Print formatted article details to console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
article
|
News
|
News object to display. |
required |
Source code in financelib/news/client.py
search_articles(query: str, limit: int = 5, print_results: bool = False) -> List[News]
¶
Search Bloomberg for articles matching a query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query string. |
required |
limit
|
int
|
Maximum number of articles to return. |
5
|
print_results
|
bool
|
Whether to print results to console. |
False
|
Returns:
| Type | Description |
|---|---|
List[News]
|
List of News objects. |
Source code in financelib/news/client.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
financelib.news.client.NewsAPIQuery(api_key: str = '')
¶
Bases: BaseQueryClass
NewsAPI.org query client.
Fetches news articles via the NewsAPI service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
NewsAPI API key. If empty, loads from environment. |
''
|
Example
query = NewsAPIQuery() articles = query.search_articles("Bitcoin", sources_from_ids=["bbc-news"])
Source code in financelib/news/client.py
Functions¶
get_all_news_source_ids() -> List[str]
¶
Get all available NewsAPI source IDs.
Returns:
| Type | Description |
|---|---|
List[str]
|
List of source ID strings. |
get_all_news_sources_detailed() -> List[Dict[str, str]]
¶
Get detailed information about all available NewsAPI sources.
Returns:
| Type | Description |
|---|---|
List[Dict[str, str]]
|
List of source detail dictionaries. |
Source code in financelib/news/client.py
print_article_details(article: Dict) -> None
¶
Print formatted article details from NewsAPI response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
article
|
Dict
|
Raw article dictionary from NewsAPI. |
required |
Source code in financelib/news/client.py
search_articles(query: str, sources_from_ids: Optional[str | List[str]] = None, limit: int = 5, print_results: bool = False) -> List[Dict]
¶
Search for articles via NewsAPI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query string. |
required |
sources_from_ids
|
Optional[str | List[str]]
|
Source ID(s) to filter by (string or list). |
None
|
limit
|
int
|
Maximum number of articles. |
5
|
print_results
|
bool
|
Whether to print results to console. |
False
|
Returns:
| Type | Description |
|---|---|
List[Dict]
|
List of article dictionaries from NewsAPI. |