This demo shows how to call the New York Times API using the Python requests library and parse its JSON data.
It also shows how you can store and hide your API keys with a .env
file and .gitignore
file, respectively.
- Check out NYT API
- Create app using NYT Dev console: https://developer.nytimes.com/my-apps
- Get API key for sending requests
pip install requests
- Write initial article search request code
- Read JSON from response
- Print JSON into a nicer format
- Get article headlines from JSON
import os
pip install python-dotenv
- Create
.env
file and add key toNYT_KEY
variable - Get
NYT_KEY
from environment variable using dotenv - Create
.gitignore
and add.env
to it