Skip to main content

A minimalist Python wrapper for the Perigon News API.

Project description

Perigon API Wrapper

python

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?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perigon_news_wrapper-0.0.3.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

perigon_news_wrapper-0.0.3-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page