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 ospip install python-dotenv- Create
.envfile and add key toNYT_KEYvariable - Get
NYT_KEYfrom environment variable using dotenv - Create
.gitignoreand add.envto it