The World News API gives you access to thousands of news sources in over 50 languages from over 150 countries. News are semantically tagged allowing for semantic news search like never before.
This is the python-package for easy acccess to the api.
- API version: 1.2.0
- Package version: 1.2.0
Python 3.7+
This package is hosted on PyPi, you can install directly using:
pip install worldnewsapi
(you may need to run pip
with root permission: sudo pip install worldnewsapi
)
Then import the package:
import worldnewsapi
Install via Setuptools.
python setup.py install --user
(or sudo python setup.py install
to install the package for all users)
Then import the package:
import worldnewsapi
Execute pytest
to run the tests.
Please follow the installation procedure and then run the following:
import worldnewsapi
from worldnewsapi.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://api.worldnewsapi.com
# See configuration.py for a list of all supported configuration parameters.
configuration = worldnewsapi.Configuration(
host = "https://api.worldnewsapi.com"
)
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure API key authorization: apiKey
configuration.api_key['apiKey'] = os.environ["API_KEY"]
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['apiKey'] = 'Bearer'
# Configure API key authorization: headerApiKey
configuration.api_key['headerApiKey'] = os.environ["API_KEY"]
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['headerApiKey'] = 'Bearer'
# Enter a context with an instance of the API client
with worldnewsapi.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = worldnewsapi.NewsApi(api_client)
url = 'https://www.bbc.com/news/world-us-canada-59340789' # str | The url of the news.
analyze = true # bool | Whether to analyze the news (extract entities etc.)
try:
# Extract News
api_response = api_instance.extract_news(url, analyze)
print("The response of NewsApi->extract_news:\n")
pprint(api_response)
except ApiException as e:
print("Exception when calling NewsApi->extract_news: %s\n" % e)
All URIs are relative to https://api.worldnewsapi.com
Class | Method | HTTP request | Description |
---|---|---|---|
NewsApi | extract_news | GET /extract-news | Extract News |
NewsApi | extract_news_links | GET /extract-news-links | Extract News Links |
NewsApi | get_geo_coordinates | GET /geo-coordinates | Get Geo Coordinates |
NewsApi | news_website_to_rss_feed | GET /feed.rss | News Website to RSS Feed |
NewsApi | retrieve_news_articles_by_ids | GET /retrieve-news | Retrieve News Articles by Ids |
NewsApi | search_news | GET /search-news | Search News |
NewsApi | top_news | GET /top-news | Top News |
- ExtractNews200Response
- ExtractNews200ResponseImagesInner
- ExtractNews200ResponseVideosInner
- ExtractNewsLinks200Response
- GetGeoCoordinates200Response
- RetrieveNewsArticlesByIds200Response
- RetrieveNewsArticlesByIds200ResponseNewsInner
- SearchNews200Response
- SearchNews200ResponseNewsInner
- TopNews200Response
- TopNews200ResponseTopNewsInner
- TopNews200ResponseTopNewsInnerNewsInner
Authentication schemes defined for the API:
- Type: API key
- API key parameter name: api-key
- Location: URL query string
- Type: API key
- API key parameter name: x-api-key
- Location: HTTP header