Skip to main content

NewsCatcher News API V2

Project description

newscatcherapi-python-sdk

NewsCatcher is a data-as-a-service startup that has one main goal: to build the largest database of structured news articles published online. In other words, we're like Google for the news part of the web, which you can access as a source of data.

Some useful links:

This Python package is automatically generated by the Konfig:

  • API version: 1.0.1
  • Package version: 2.0.0

Requirements.

Python >=3.6

Installation & Usage

pip install

If the python package is hosted on a repository, you can install directly using:

pip install git+https://github.com/konfig-dev/newscatcher-sdks/tree/main/python.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/konfig-dev/newscatcher-sdks/tree/main/python.git)

Then import the package:

import newscatcherapi_client

Setuptools

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 newscatcherapi_client

Getting Started

Please follow the installation procedure and then run the following:

import time
import newscatcherapi_client
from pprint import pprint
from newscatcherapi_client.api import latest_headlines_api
from newscatcherapi_client.model.error_response import ErrorResponse
from newscatcherapi_client.model.latest_headlines import LatestHeadlines
from newscatcherapi_client.model.model200_response_latest import Model200ResponseLatest
from newscatcherapi_client.model.page import Page
from newscatcherapi_client.model.page_size import PageSize
from newscatcherapi_client.model.topic import Topic
# 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: api_key
configuration = newscatcherapi_client.Configuration(api_key={'api_key': 'YOUR_API_KEY'})

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key'] = 'Bearer'


# Enter a context with an instance of the API client
with newscatcherapi_client.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = latest_headlines_api.LatestHeadlinesApi(api_client)
    lang = "en" # str | Specifies the languages of the search. For example: `en`. The only accepted format is [ISO 639-1 — 2](https://en.wikipedia.org/wiki/ISO_639-1) letter code.  (optional)
    not_lang = "af" # str | Inverse to the `lang` parameter  (optional)
    countries = "US,CA" # str | Countries where the news publisher is located. **Important**: This parameter is not responsible for the countries mentioned in the news article. One or multiple countries can be used in the search. The only acceptable format is [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) For example, `US,CA,MX` or just `US`  (optional)
    not_countries = "US,CA" # str | The inverse of the `countries` parameter.  (optional)
    topic = Topic("business") # Topic | Accepted values: `news`, `sport`, `tech`, `world`, `finance`, `politics`, `business`, `economics`, `entertainment`, `beauty`, `travel`, `music`, `food`, `science`, `gaming` The topic to which you want to restrict the articles of your choice. Not all news articles are assigned with a topic, therefore, we cannot guarantee that 100% of topics talking about technology will be assigned a tech label.  (optional)
    sources = "nytimes.com,theguardian.com" # str | One or more news resources to filter your search. It should be the normal form of the URL, For example: `nytimes.com,theguardian.com`  (optional)
    not_sources = "wsj.com" # str | One or more sources to be excluded from the search. Comma-separated list. For example: `nytimes.com,cnn.com,wsj.com`  (optional)
    ranked_only = True # bool | Default: `True` Limit the search only for the sources which are in the top 1 million online websites. Unranked sources are assigned a rank that equals `999999`  (optional)
    page_size = PageSize(100) # PageSize | `[1:100]` How many articles to return per page.  (optional)
    page = Page(1) # Page | The number of the page. Use it to scroll through the results. This parameter is used to paginate: scroll through results because one API response cannot return more than 100 articles.  (optional)

    try:
        # Get Latest News Articles
        api_response = api_instance.get(lang=lang, not_lang=not_lang, countries=countries, not_countries=not_countries, topic=topic, sources=sources, not_sources=not_sources, ranked_only=ranked_only, page_size=page_size, page=page)
        pprint(api_response)
    except newscatcherapi_client.ApiException as e:
        print("Exception when calling LatestHeadlinesApi->get: %s\n" % e)

Documentation for API Endpoints

All URIs are relative to https://api.newscatcherapi.com/v2

Class Method HTTP request Description
LatestHeadlinesApi get GET /latest_headlines Get Latest News Articles
LatestHeadlinesApi post POST /latest_headlines Get Latest News Articles
SearchApi get GET /search Search for specific news articles
SearchApi post POST /search Search for specific news articles
SourcesApi get GET /sources Get top news sources supported by NewsCatcher.
SourcesApi post POST /sources Get top news sources supported by NewsCatcher.

Documentation For Models

Documentation For Authorization

api_key

  • Type: API key
  • API key parameter name: x-api-key
  • Location: HTTP header

Author

team@newscatcherapi.com

Notes for Large OpenAPI documents

If the OpenAPI document is large, imports in newscatcherapi_client.apis and newscatcherapi_client.models may fail with a RecursionError indicating the maximum recursion limit has been exceeded. In that case, there are a couple of solutions:

Solution 1: Use specific imports for apis and models like:

  • from newscatcherapi_client.api.default_api import DefaultApi
  • from newscatcherapi_client.model.pet import Pet

Solution 2: Before importing the package, adjust the maximum recursion limit as shown below:

import sys
sys.setrecursionlimit(1500)
import newscatcherapi_client
from newscatcherapi_client.apis import *
from newscatcherapi_client.models import *

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

newscatcherapi-python-sdk-2.0.0.tar.gz (60.6 kB view hashes)

Uploaded Source

Built Distribution

newscatcherapi_python_sdk-2.0.0-py3-none-any.whl (120.9 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