Skip to main content

Python library for newsdata client-API Call

Project description

Alt text

NewsData.io Python Client

newsdataapi allows you to create a library for accessing http services easily, in a centralized way. An API defined by newsdataapi will return a JSON object when called.

Build Status License PyPI Supported Python versions Python


Installation

Supported Python Versions

Python >= 3.5 fully supported and tested.

Install Package

pip install newsdataapi

Documentation

Newsdataapi docs can be seen here.


Latest News API

GET /1/news

# To get latest news use our news_api method.

from newsdataapi import NewsDataApiClient

# API key authorization, Initialize the client with your API key

api = NewsDataApiClient(apikey='YOUR_API_KEY')
response = api.news_api(q='entertainment')
print(response)

# Latest news with page parameter

response = api.news_api(q='entertainment',page='nextPage_value')
print(response)

# To scroll through all latest news

response = api.news_api(q='entertainment',page='nextPage_value',scroll=True)
print(response)


News Archive API

GET /1/archive

# To get archive news use our archive_api method.

from newsdataapi import NewsDataApiClient

# API key authorization, Initialize the client with your API key

api = NewsDataApiClient(apikey='YOUR_API_KEY')
response = api.archive_api(q='olympic',from_date='2021-01-01',to_date='2021-06-06')
print(response)

# Archive news with page parameter

response = api.archive_api(q='olympic',from_date='2021-01-01',to_date='2021-06-06',page='nextPage_value')
print(response)

# To scroll through all archive news

response = api.archive_api(q='olympic',from_date='2021-01-01',to_date='2021-06-06',page='nextPage_value',scroll=True)
print(response)


News Sources API

GET /1/sources

# To get sources use our sources_api method.

from newsdataapi import NewsDataApiClient

# API key authorization, Initialize the client with your API key

api = NewsDataApiClient(apikey="YOUR_API_KEY")
response = api.sources_api()
print(response)


Crypto News API

GET /1/crypto

# To get crypto news use our crypto_api method.

from newsdataapi import NewsDataApiClient

# API key authorization, Initialize the client with your API key

api = NewsDataApiClient(apikey='YOUR_API_KEY')
response = api.crypto_api(q='bitcoin')
print(response)

# Crypto with page parameter

response = api.crypto_api(q='bitcoin',page='nextPage_value')
print(response)

# To scroll through all crypto news

response = api.crypto_api(q='bitcoin',page='nextPage_value',scroll=True)
print(response)


News API with Pagination

GET /1/news

from newsdataapi import NewsDataApiClient

# API key authorization, Initialize the client with your API key

api = NewsDataApiClient(apikey="YOUR_API_KEY")
response = api.news_api()

# You can go to next page by providing Page parameter

response = api.news_api(page = "nextPage value")

# You can paginate till last page by providing Page parameter in Loop

page=None
while True:
    response = api.news_api(page = page)
    page = response.get('nextPage',None)
    if not page:
        break


News API with Scrolling

# Note: Scrolling through all result will counsume api as per your defined size. you can also define max_result to stop scrolling at desired result size.scroll is avaliable in news_archive,news_api and news_crypto, it will return all result when scrolling is compleated.

from newsdataapi import NewsDataApiClient

# API key authorization, Initialize the client with your API key

api = NewsDataApiClient(apikey="YOUR_API_KEY")

response = api.news_api(q='entertainment',page='nextPage_value',scroll=True,max_result=1000)
print(response)


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.

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

newsdataapi-0.1.9.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

newsdataapi-0.1.9-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file newsdataapi-0.1.9.tar.gz.

File metadata

  • Download URL: newsdataapi-0.1.9.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.18

File hashes

Hashes for newsdataapi-0.1.9.tar.gz
Algorithm Hash digest
SHA256 0e00629fbf4239460101b354e400dcebc7dcf6b937d60f27fb92421ab4334591
MD5 6ed8b55ce54db99f667c4eef6cc8f2c2
BLAKE2b-256 ae959f687408ac756e9c97aceda28b870ea1aeec922c270c6dca58d52ab3d62d

See more details on using hashes here.

File details

Details for the file newsdataapi-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: newsdataapi-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.18

File hashes

Hashes for newsdataapi-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 1cc1e2979693571f6546425dabca5602b3b1078766b371be4293058adbd5bbe0
MD5 bb31ec36281317a094a3314b802f3713
BLAKE2b-256 6644852e069466f8bbd25cde1581783bcc2a9355dc34fb645da704279a47d635

See more details on using hashes here.

Supported by

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