Skip to content
A Python Client for News API
Python
Branch: master
Clone or download
MichaelBalazs and mattlisiv Added qintitle support (#58)
* Added support for qintitle parameter.

* Minor fix to comment.
Latest commit 9e55789 Oct 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update pythonpackage.yml (#49) Sep 7, 2019
docs add master doc location (#56) Sep 12, 2019
newsapi Added qintitle support (#58) Oct 3, 2019
tests
.flake8 Standardize code style with black.py + isort (#52) Sep 7, 2019
.gitignore Create documentation source RST (#55) Sep 12, 2019
.isort.cfg Standardize code style with black.py + isort (#52) Sep 7, 2019
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md May 2, 2018
LICENSE.txt Touch up README.md Sep 6, 2019
README.md Touch up README.md Sep 6, 2019
pyproject.toml Standardize code style with black.py + isort (#52) Sep 7, 2019
requirements-dev.txt Create documentation source RST (#55) Sep 12, 2019
requirements.txt Update pythonpackage.yml (#49) Sep 7, 2019
setup.cfg Initial Commit Jan 8, 2018
setup.py Create documentation source RST (#55) Sep 12, 2019

README.md

newsapi-python

A Python client for the News API.

License PyPI Status Python

License

Provided under MIT License by Matt Lisivick.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

General

This is a Python client library for News API V2. The functions and methods for this library should mirror the endpoints specified by the News API documentation.

Installation

Installation for the package can be done via pip:

$ python -m pip install newsapi-python

Usage

After installation, import the client class into your project:

from newsapi import NewsApiClient

Initialize the client with your API key:

api = NewsApiClient(api_key='XXXXXXXXXXXXXXXXXXXXXXX')

Endpoints

An instance of NewsApiClient has three instance methods corresponding to three News API endpoints.

Top Headlines

Use .get_top_headlines() to pull from the /top-headlines endpoint:

api.get_top_headlines(sources='bbc-news')

Everything

Use .get_everything() to pull from the /everything endpoint:

api.get_everything(q='bitcoin')

Sources

Use .get_sources() to pull from the /sources endpoint:

api.get_sources()

For Windows users printing to cmd or powershell

You will encounter an error if you attempt to print the .json() object to the command line. This is because the '{', '}' curly braces to be printed to the console. This becomes especially annoying if developers wish to get 'under the hood'.

Here is the error:

UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 1444: character maps to <undefined>

This can be fixed by: - installing 'win-unicode-console' py -mpip install win-unicode-console - then running it while calling your python script... py -mrun myPythonScript.py

Another option is hardcoding your console to only print in utf-8. This is a bad idea, as it could ruin many other scripts and/or make errors MUCH more difficult to track. More information.

Support

Feel free to make suggestions or provide feedback regarding the library. Thanks. Reach out at lisivickmatt@gmail.com

You can’t perform that action at this time.