perigon-news-wrapper 0.0.3

Last updated:

0 purchases

perigon-news-wrapper 0.0.3 Image
perigon-news-wrapper 0.0.3 Images
Add to Cart

Description:

perigonnewswrapper 0.0.3

Perigon API Wrapper

A minimalist Python wrapper for the Perigon News API. Currently only supports querying all news articles via the v1/all endpoint.
Installation (currently, only tested for Python 3.11):
pip install perigon-news-wrapper

Basic Usage
To initialize the API, import the package and add your API key:
from perigon_news_wrapper import PerigonAPI

# specify your credentials:
api_key = '...'

# initialize API:
api = PerigonAPI(api_key=api_key)

The main method is get_articles(), which takes the following arguments:

paginate [bool = True]: Whether or not to paginate results (if multiple pages are available). Defaults to True.
size [int = 100]: The number of results to return per page. Defaults to 100 (maximum allowed by Perigon).
**kwargs: Arbitrary keyword arguments supported by the Perigon API. Consult the API docs for a comprehensive list of parameters.

get_articles() returns a list of dictionaries, where each dictionary is the JSON of an individual article.
Example:
# speciy **kwargs (recommend dict format):
payload = {
'content': 'olympics AND usa AND gold',
'from': '2024-07-26',
'to': '2024-08-08',
'language': 'en',
'exclude_labels': [
'Non-news',
'Opinion',
'Fact Check',
'Roundup',
'Low Content'
]
}

# get results, using payload as **kwargs:
results = api.get_articles(paginate=False, size=100, **payload)

TODO

Establish tests for other Python versions (only tested on Python 3.11).
Add support for querying additional Perigon endpoints.
Add support for parsing/saving results?

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.