Skip to main content

Official Python SDK for the SportNews API - Access sports news in real time

Project description

SportNews API SDK

An official Python SDK for the SportNews API, providing streamlined access to real-time sports news. This library allows developers to easily integrate sports news feeds into their Python applications.

Installation

pip install sportnews-api

Usage

from sportnews import SportNewsAPI

# Initialize the client with your API key
api = SportNewsAPI('YOUR_API_KEY')

# Retrieve the latest news
news = api.get_latest_news(
    limit=10,
    language='en'
)

# Display an article
article = news[0]
print(f"Title: {article.title}")
print(f"Date: {article.published}")
print(f"Description: {article.description}")
print(f"Sport: {article.sport}")

Searching for Articles

# Search for articles about football from the last 7 days
from datetime import datetime, timedelta

search_results = api.search_news(
    query="football",
    from_date=datetime.utcnow() - timedelta(days=7),
    language="en",
    size=5
)

for article in search_results['items']:
    print(f"Title: {article.title} | Published: {article.published}")

Key Features

  • Retrieve the latest sports news
  • Search articles with advanced filters
  • Multilingual support (FR, EN, ES, IT, DE)
  • Pagination of results
  • Robust error handling
  • Automatic parameter validation
  • Date-based search for temporal filtering

NewsArticle Object

Each news article returned by the API has the following attributes:

  • title (str): The title of the article.
  • published (datetime): The publication date.
  • description (str): A brief summary of the article.
  • sport (str): The sport associated with the article.
  • language (str): The language of the article.

Error Handling

The SDK raises a SportNewsAPIError for any issues during API requests. Make sure to handle these exceptions in your application:

from sportnews import SportNewsAPI, SportNewsAPIError

try:
    news = api.get_latest_news(language='fr')
except SportNewsAPIError as e:
    print(f"An error occurred: {e}")

Supported Languages

  • French (fr)
  • English (en)
  • Spanish (es)
  • Italian (it)
  • German (de)

License

This project is licensed under the MIT License.

Running Tests

The SDK includes a suite of unit tests to validate its functionality. Run the following command to execute the tests:

python -m unittest discover tests

Support

Developed and maintained by the SportNews API team.

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

sportnews_api-0.1.5.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

sportnews_api-0.1.5-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file sportnews_api-0.1.5.tar.gz.

File metadata

  • Download URL: sportnews_api-0.1.5.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for sportnews_api-0.1.5.tar.gz
Algorithm Hash digest
SHA256 4b32b45fc400d2e2b854c8cc8dd6d49abf341b4f8c5a95fd971b6c64966ee85a
MD5 6ea3ea1716b8d1403ad912f6d12ec876
BLAKE2b-256 286529bbb5245bbf54f230903d5efe9b10a9c5c7340fe811e2921d7995245a58

See more details on using hashes here.

File details

Details for the file sportnews_api-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sportnews_api-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 88ba8eb3b42965edf0bd4d7fd1e1c10bbf0e3c38d72ad114dcdce68a9a7e5bed
MD5 4684db2f79df7acfd4042780f69c9043
BLAKE2b-256 bce97afdcc50cad6fc27880c02f016e8adfb6a962c4841ea7d4e3d6005074da0

See more details on using hashes here.

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