Skip to main content

An unofficial python helper package to interact with the mediastack API.

Project description

py-mediastack

An unofficial python helper package to interact with the mediastack API.

Drawbacks

  • No historical Data (I don't have a paid account to test it)
  • No News Sources search (I don't have time to implement it)

Feel free to contribute. Make sure that you use the pre-commit hooks.

What can it do ?

It can give you live news updated.

Installation

pip3 install py-mediastack

Usage

Get the api key from here

from mediastack import MediaStack
client = MediaStack("<your-api-key>")

resp = client.get_live_news()

print(resp.pagination)
print(resp.data[0])
Pagination(limit=25, offset=0, count=25, total=10000)

Article(author='Redazione', title='Via agli incontri di quartiere:
primo appuntamento con i residenti di San Lorenzo',
description='Hanno preso il via ieri sera, dalla sala Biasin dove l’Amministrazione ha convocato i residenti del quartiere San Lorenzo, gli ‘Incontri di quartiere’ con cui la Giunta si confronta con i cittadini. Presenti, oltre al Sindaco Gian Francesco Menani, il vicesindaco Camilla Nizzoli e gli assessori Corrado Ruini e Massimo Malagoli, che hanno ascoltato le [&#8230;]',
url='https://www.bologna2000.com/2021/09/07/via-agli-incontri-di-quartiere-primo-appuntamento-con-i-residenti-di-san-lorenzo/',
image=None,
category='general',
language='it',
 country='it',
 published_at='2021-09-07T08:32:52+00:00',
 source='bologna2000')

The parameters for MediaStack.get_live_news are as follow:

  • sources: Optional[list[str]] -> Use this parameter to include or exclude one or multiple news sources. Example: To include CNN, but exclude BBC: sources=["cnn", "-bbc"]

  • categories: Optional[list[str]] Use this parameter to include or exclude one or multiple news categories. Example: To include business, but exclude sports: categories=["business", "-sports"].

  • countries: Optional[list[str]] -> Use this parameter to include or exclude one or multiple countries. Example: To include Australia, but exclude the US: countries=["au", "-us"].

  • languages: Optional[list[str]] -> Use this parameter to include or exclude one or multiple languages. Example: To include English, but exclude German: languages=["en", "-de"].

  • keywords: Optional[str] -> Use this parameter to search for sentences, you can also exclude words that you do not want to appear in your search results. Example: To search for "New movies 2021" but exclude "Matrix": keywords='new movies 2021 -matrix'

  • date: Optional[str] -> Use this parameter to specify a date or date range. Example: date=2020-01-01 for news on Jan 1st and date='2020-12-24,2020-12-31' for news between Dec 24th and 31st.

  • sort: Optional[str] -> Use this parameter to specify a sorting order. Available values: published_desc (default), published_asc, popularity

  • limit: Optional[int] -> Use this parameter to specify a pagination limit (number of results per page) for your API request. Default limit value is 25, maximum allowed limit value is 100.

  • offset: Optional[int] -> Use this parameter to specify a pagination offset value for your API request. Example: An offset value of 100 combined with a limit value of 10 would show results 100-110. Default value is 0, starting with the first available result.


The get_live_news methods returns a LiveNewsResponse data class. It contains the pagination details and the data.


The LiveNewsResponse.pagination is of type Pagination and has the following attributes.

  • Pagination.limit -> your pagination limit value.
  • Pagination.offset -> your pagination offset value.
  • Pagination.count -> the results count on the current page.
  • Pagination.total -> the total count of results available.

The LiveNewsResponse.data is a list[Article] and each Article has the following attributes.

  • Article.author -> the name of the author of the given news article.
  • Article.title -> the title text of the given news article.
  • Article.description -> the description text of the given news article.
  • Article.url - > the URL leading to the given news article.
  • Article.image -> an image URL associated with the given news article.
  • Article.category -> the category associated with the given news article.
  • Article.language -> the language the given news article is in.
  • Article.country -> the country code associated with the given news article.
  • Article.published_at -> the exact time stamp the given news article was published.
  • Article.source -> the source from which the article was taken

Supported News Categories

  • general - Uncategorized News
  • business - Business News
  • entertainment - Entertainment News
  • health - Health News
  • science - Science News
  • sports - Sports News
  • technology - Technology News

Supported Countries

Click Here to see the list of all the supported countries.

Supported Languages

  • ar - Arabic
  • de - German
  • en - English
  • es - Spanish
  • fr - French
  • he - Hebrew
  • it - Italian
  • nl - Dutch
  • no - Norwegian
  • pt - Portuguese
  • ru - Russian
  • se - Swedish
  • zh - Chinese

Most of the docs are directly taken from the mediastacks api docs

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

py-mediastack-0.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

py_mediastack-0.1.1-py2.py3-none-any.whl (7.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file py-mediastack-0.1.1.tar.gz.

File metadata

  • Download URL: py-mediastack-0.1.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for py-mediastack-0.1.1.tar.gz
Algorithm Hash digest
SHA256 936d8ce97ca8e0714e975464473fc8fb306dfdea0516708a667b3c746886304f
MD5 8064d582ffdee4eb67008a08aa015372
BLAKE2b-256 bac997110ef204579e06451d7e27e323f5e6ed23d15a93d5a1e20dbbc32b1b62

See more details on using hashes here.

File details

Details for the file py_mediastack-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: py_mediastack-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for py_mediastack-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c380dd01633340b5da527469ae7c822aaf08f28cb6bf5c714f8273d188f79190
MD5 f1f119f32303efd3c184821a301c17d1
BLAKE2b-256 1b538c4e5b9cab31c813153f4c5ec38a7773d9f268eb0b3faf57522d5c91fe0a

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