Skip to main content

Python wrapper for the New York Times Article Search API

Project description

yanytapi

yanytapi is a Python wrapper for the New York Times Article Search API. Based on the excellent requests package, it provides full support for all of the API's search parameters, and also allows access to the request object itself for debugging purposes.

Installation

With pip:

$ pip install yanytapi

Dependencies

yanytapi requires the requests package.

Usage

Simply import and initialize the API with your developer key:

>>> from yanytapi import SearchAPI
>>> api = SearchAPI("YourAPIKey")

Then call the search function with your desired search parameters/values:

>>> articles = api.search("Obama", 
                          fq={"headline": "Obama", 
                              "source": ["Reuters", 
                                         "AP", 
                                         "The New York Times"]}, 
                          begin_date="20161001", # this can also be an int
                          facet_field=["source", "day_of_week"], 
                          facet_filter=True)

The search function returns an iterator of Doc's with the following fields:

[
  "_id",
  "blog",
  "byline",
  "document_type",
  "headline",
  "keywords",
  "lead_paragraph",
  "meta",
  "multimedia",
  "news_desk",
  "pub_date",
  "score",
  "section_name",
  "snippet",
  "source",
  "subsectoinName",
  "type_of_material",
  "uri",
  "web_url",
  "word_count"
]

You can specify multiple filters by using a dictionary::

>>> fq = {"headline": "Obama", "source": ["Reuters", "AP", "The New York Times"]}
>>> articles = api.search("Obama", fq=fq)

And multiple values by using a list::

>>> facet_field = ["source", "day_of_week"]
>>> articles = api.search("Obama", facet_field=facet_field)

More examples:

# simple search
>>> articles = api.search("Obama")
# search between specific dates
>>> articles = api.search("Obama", begin_date="20161001", end_date="20161020", page=2)
# access most recent request object
>>> headers = api.req.headers

For a complete overview of the available search parameters, please refer to the NYTimes Article Search API Documentation.

History

This package was originally written by Evan Sherlock as nytimesarticle. It was subsequently forked and updated by Matt Morrison, and subsequently released as NYTimesArticleAPI, with contributions from Gerald Spencer and Andrew Han. yanytapi is a third iteration of forking focused mainly on packaging improvements, now maintained by Ed Kohlwey.

License

This is free software. It is licensed under the MIT License. Feel free to use this in your own work. However, if you modify and/or redistribute it, please attribute me in some way, and distribute your work under this or a similar license. A shout-out or a beer would be appreciated.

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

yanytapi-2.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

yanytapi-2.0.0-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file yanytapi-2.0.0.tar.gz.

File metadata

  • Download URL: yanytapi-2.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for yanytapi-2.0.0.tar.gz
Algorithm Hash digest
SHA256 12b013c43a2966aeef6405646280134f9b5a1c7fe2872c60bc1db11f9d5886bb
MD5 ea340a42f8312b4b55a62840fe4c5a5d
BLAKE2b-256 3b944cf88de1eda4de642531d40db0ac283415956d5de7277abd5c7a3251c83d

See more details on using hashes here.

File details

Details for the file yanytapi-2.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: yanytapi-2.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for yanytapi-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e1857fb3e2bba070323d84867e8d8420fb3e556b5572bc24cbda0cb631339b3b
MD5 f7a910d8f7dfd8bf7ddf37524399c5d1
BLAKE2b-256 fed34e4c59fd9b896571f2bd9564b78e79e8aef8f6c33c8b116ef88b12598c93

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