Skip to content

Latest commit

 

History

History
139 lines (92 loc) · 3.01 KB

README.md

File metadata and controls

139 lines (92 loc) · 3.01 KB

Newspy

The news client written in Python that fetches and curates the world news across the web.


PyPI - Version GitHub PyPI - Python Version Static Badge Codecov GitHub Workflow Status (with event)


Table of contents

Requirements

  • Python 3.10+
  • Poetry 1.4.0+ (for dependency management)
  • yarn (for the semantic-release versioning)
  • API Key from the New API Organisation: https://newsapi.org/

News Sources

Basic usage

Create virtual environment

python -m venv .venv

# Activate virtual environment
.venv/bin/activate # Linux or MacOS
.venv/Script/activate # Windows


# Install
pip install newspy

RSS feeds client

Get available news sources from RSS feeds

from newspy import rss

rss_sources = rss.get_sources()
print(rss_sources)

Get articles from RSS feeds

rss_articles = rss.get_articles()
print(rss_articles)

Newsorg client

Configure your Newsorg API key

You can get one here: https://newsapi.org/

import newspy.client as newspy

newsorg_api_key = "YOUR_NEWSORG_KEY"
newspy.configure(newsorg_api_key=newsorg_api_key)

Get available news sources from Newsorg

from newspy import newsorg

newsorg_sources = newsorg.get_sources()
print(newsorg_sources)

Get articles from Newsorg

from newspy import newsorg
from newspy.newsorg.models import NewsorgEndpoint

newsorg_articles = newsorg.get_articles(
    endpoint=NewsorgEndpoint.TOP_HEADLINES,
    search_text="bitcoin",
)

print(newsorg_articles)

Newspy client

The newspy client makes it convenient to get articles from both the RSS feeds and Newsorg APIs.

Configure your Newsapi API key

import newspy.client as newspy

newsorg_api_key = "YOUR_NEWSORG_KEY"
newspy.configure(newsorg_api_key=newsorg_api_key)

Get available news sources from both RSS feeds and Newsorg

import newspy.client as newspy

news_sources = newspy.get_sources()
print(news_sources)

Get articles from both RSS feeds and Newsorg

import newspy.client as newspy

news_articles = newspy.get_articles()
print(news_articles)

Examples

See the examples directory for more examples.

Contributing

Want to contribute? Read our contribution guideline.