Package: pynytimes
pynytimesUse all (actually most) New York Times APIs, get all the data you need from the Times!DocumentationExtensive documentation is available at:https://pynytimes.michadenheijer.com/.InstallationThere are multiple options to install and ugprade pynytimes, but the easiest is by just installing it usingpip(orpip3).Linux and Macpipinstall--upgradepynytimesWindowspython-mpipinstall--upgradepynytimesUsageYou can easily import this library using:frompynytimesimportNYTAPIThen you can simply add your API key (get your API key fromThe New York Times Dev Portal):nyt=NYTAPI("Your API key",parse_dates=True)Make sure that if you commit your code to GitHub youdon't accidentially commit your API key.Supported APIsWhen you have imported this library you can use the following features from the New York Times API.SearchArticle searchBook reviewsMovie reviewsPopularTop storiesMost viewed articlesMost shared articlesBest sellers listsMetadataArticle metadataArchive metadataLoad latest articlesOtherTag query (TimesTags)Top storiesTo get the current top stories use:top_stories=nyt.top_stories()Readthe documentationto find the top stories per section.Most viewed articlesYou can also get todays most viewed articles:most_viewed=nyt.most_viewed()Readthe documentationto get the most viewed articles per week or month.Most shared articlesTo get the most shared articles (shared over email) use:most_shared=nyt.most_shared()Readthe documentationto get the most shared articles using facebook.Article searchSearch articles using a query using:articles=nyt.article_search(query="Obama")In this example we have just defined the content of the search query (Obama), but we can add many more search parameters. Readthe documentationto see how.Book reviewsYou can easily find book reviews for every book you've read. You can find those reviews by searching for the author, ISBN or title of the book.# Get reviews by author (first and last name)reviews=nyt.book_reviews(author="George Orwell")# Get reviews by ISBNreviews=nyt.book_reviews(isbn="9780062963673")# Get book reviews by titlereviews=nyt.book_reviews(title="Becoming")Readthe documentationto find more information about additional parameters.Movie reviewsYou can not only get the book reviews, but the movie reviews too.reviews=nyt.movie_reviews(keyword="Green Book")Readthe documentationto find more information about additional parameters.Best sellers listsThe New York Times has multiple best sellers lists. To get from the fiction best seller list:# Get fiction best sellers listbooks=nyt.best_sellers_list()Read how to get the other best seller lists inthe documentation.Article metadataWith an URL from a New York Times article you can easily get all the metadata you need from it.metadata=nyt.article_metadata(url="https://www.nytimes.com/2019/10/20/world/middleeast/erdogan-turkey-nuclear-weapons-trump.html")Read additional parameters inthe documentation.Load latest articlesYou can easily load the latest articles published by the New York Times.latest=nyt.latest_articles(source="nyt",section="books")Additional parameters can be found inthe documentation.Tag queryThe New York Times has their own tags library. You can query this library with this API.tags=nyt.tag_query("pentagon",max_results=20)Additional parameters can be found inthe documentation.Archive metadataIf you want to load all the metadata from a specific month, then this API makes that possible. Be aware you'll download a big JSON file (about 20 Mb), so it can take a while.importdatetimedata=nyt.archive_metadata(date=datetime.datetime(2019,1,1))Read more in the documentation.Citing this RepositoryIf you usepynytimes, a citation would be very much appriciated. If you're using BibTeX you can use the following citation:@software{Den_Heijer_pynytimes_2023,author={Den Heijer, Micha},license={MIT},title={{pynytimes}},url={https://github.com/michadenheijer/pynytimes},version={0.10.0},year={2023},doi={10.5281/zenodo.7821090}}If you're not using BibTeX, you canretrieve the preferred citation from Zenodo.LicenseDisclaimer:This project is not made by anyone from the New York Times, nor is it affiliated with The New York Times Company.