A minimalist Python wrapper for the Perigon News API.
Project description
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 toTrue.size [int = 100]: The number of results to return per page. Defaults to100(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?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for perigon_news_wrapper-0.0.3.tar.gz
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | b0aed70d8cff577cad2fb85a24f6467854a5b057ce2578f6a26556a9fd7eb652 |
|
| MD5 | cd70efad6568870caa3f49c9e0db078b |
|
| BLAKE2b-256 | 20e983680e84eddbc11a7c2f92f140aa26d84f82b2ae1e5e07b1e5f928e88042 |
Close
Hashes for perigon_news_wrapper-0.0.3-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 6e6f2c58b9ca174abc0fd0c286a4666717991989ef327586e5ae2a3faff067f8 |
|
| MD5 | e35e4dbc99d9f148e80519ae52855001 |
|
| BLAKE2b-256 | 4d5dca1d6c9baf81a9f66c1b64ae7167419d163cd9602493415e33555db01908 |