Skip to main content

AsyncIO Python wrapper to News API

Project description

asyncnewsapi

License Build Status PyPI version Code Coverage Join the chat at https://gitter.im/pkpintoHUB/asyncnewsapi

An asyncio Python library to perform request against News API. It provides direct access to the endpoints defined in the documentation.

Two classes are implemented, returning async iterators for the request results. Session will return an iterator through the results of a single request. Alternatively, Stream will return an infinite iterator, performing successive requests and continuing to iterate through the results. A minimal implementation can be as simple as:

import asyncio

from asyncnewsapi import Session

async def main():
    async with Session() as api:
        async for article in api.top_headlines(language='en'):
            print(article['title'])

if __name__ == '__main__':
    asyncio.run(main())

The API key should be provided as an environment variable named NEWSAPI_KEY:

export NEWSAPI_KEY="..."

Go to the NewsAPI website to create a free API key.

This library is loosely based on / inspired by newsapi-python, a requests based library by Matt Lisivick.

Installation

Use pip to install this package, either directly from pypi:

pip install asyncnewsapi

or after cloning from github:

pip install .

Tests

Unit tests have been implemented using pytest. To run them, additional dependencies need be installed:

pip install ".[test]"

The tests can then be run using:

python -m pytest -v tests/

from the root of the repo (running it explicitly on the tests/ directory avoids interference with the venv folders).

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

asyncnewsapi-0.2.1.tar.gz (12.8 kB view hashes)

Uploaded source

Built Distribution

asyncnewsapi-0.2.1-py3-none-any.whl (12.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page