Skip to main content

Python wrapper for the New York Times Article Search API

Project description


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.


With pip:

$ pip install yanytapi


yanytapi requires the requests package.


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 ="Obama", 
                          fq={"headline": "Obama", 
                              "source": ["Reuters", 
                                         "The New York Times"]}, 
                          begin_date="20161001", # this can also be an int
                          facet_field=["source", "day_of_week"], 

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


You can specify multiple filters by using a dictionary::

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

And multiple values by using a list::

>>> facet_field = ["source", "day_of_week"]
>>> articles ="Obama", facet_field=facet_field)

More examples:

# simple search
>>> articles ="Obama")
# search between specific dates
>>> articles ="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.


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.


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 hashes)

Uploaded source

Built Distribution

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

Uploaded py2 py3

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