The Guardian

This module fetches data from The Guardian API.

To use first create TheGuardianCredentials:

>>> from import TheGuardianCredentials
>>> credentials = TheGuardianCredentials('<your-api-key>')

Then create TheGuardianAPI object and use it for searching:

>>> from import TheGuardianAPI
>>> api = TheGuardianAPI(credentials)
>>> corpus ='Slovenia', max_documents=10)
>>> len(corpus)

The Guardian API credentials.


key (str) – The Guardian API key. Use test for testing purposes.

property valid

Check if given API key is valid.

class, on_progress=None, should_break=None)[source]
__init__(credentials, on_progress=None, should_break=None)[source]
  • credentials (TheGuardianCredentials) – The Guardian Creentials.

  • on_progress (callable) – Function for progress reporting.

  • should_break (callable) – Function for early stopping.

search(query, from_date=None, to_date=None, max_documents=None, accumulate=False)[source]

Search The Guardian API for articles.

  • query (str) – A query for searching the articles by

  • from_date (str) – Search only articles newer than the date provided. Date should be in ISO format; e.g. ‘2016-12-31’.

  • to_date (str) – Search only articles older than the date provided. Date should be in ISO format; e.g. ‘2016-12-31’.

  • max_documents (int) – Maximum number of documents to retrieve. When not given, retrieve all documents.

  • accumulate (bool) – A flag indicating whether to accumulate results of multiple consequent search calls.