Skip to main content

NewsAPI Python Client

Description

This project provides a Python client for accessing the NewsAPI. It aims to make it easier for developers to integrate news searching capabilities into their applications. Whether you are building a news aggregation service, a stock trading platform that needs financial news, or a social media app that needs to show relevant news to users, this library is for you.

Features

  • Simple and intuitive Python interface to the NewsAPI.
  • Uses the requests library for making HTTP requests.
  • Object-oriented models for request and response data.
  • Supports all parameters of the NewsAPI, including advanced search queries and filtering.
  • Built with flexibility and extensibility in mind, allowing developers to customize it according to their needs.

Installation

pip install newsapi-python-client

Usage

Create a secrets.json file in the base directory of the project with the following structure:

{
    "NEWS_API_KEY": "YOUR_NEWS_API_KEY"
}
from services.news_service import get_finance_news
from models.request_model import RequestModel

request_model = RequestModel(
    q='finance',
    searchIn='title,content',
    sources='source1,source2',
    domains='domain1.com,domain2.com',
    excludeDomains='excludedomain1.com,excludedomain2.com',
    from_param='2023-05-01T00:00:00',
    to='2023-05-27T23:59:59',
    language='en',
    sortBy='popularity',
    pageSize=100,
    page=1
)

response_model = get_finance_news(request_model)

for article in response_model.articles:
    print(f"Title: {article.title}")
    print(f"URL: {article.url}")
    print("---")

Note: Remember to replace placeholder values in the RequestModel with actual values.

Requirements

  • Python 3.6 or later
  • requests package

Future Plans

  • Improve error handling and validation.
  • Add more examples and use cases.
  • Create more comprehensive documentation.

Contributing

We welcome contributions from the community. Please refer to the CONTRIBUTING.md file for more details.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

newsapi-python-client-0.2.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

newsapi_python_client-0.2.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file newsapi-python-client-0.2.2.tar.gz.

File metadata

  • Download URL: newsapi-python-client-0.2.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.5

File hashes

Hashes for newsapi-python-client-0.2.2.tar.gz
Algorithm Hash digest
SHA256 2a844ef620af9063c7a5204c7805512547b67905b0940e7182ba5927e744d37d
MD5 3c07411c860e224b40c9d3b21715a462
BLAKE2b-256 dbfdd7ac650b1819d58273e70519987b3a8808a0367b76402cea85e58bb11e03

See more details on using hashes here.

File details

Details for the file newsapi_python_client-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for newsapi_python_client-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 200f966b4afc4784affe31bc19beb77f93d4eb89ddb6ccb8e30854467b882357
MD5 0b6410be184f0ca8a2520de502b4de5b
BLAKE2b-256 e9d61bc5c5d2d7d33fbf8847d23645cefc34f84d132787c06bcf759ed0a1a516

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 Sentry Error logging StatusPage Status page