This demo explains 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.
pip install python-dotenv
pip install requests
- Create
.env
file in your main directory - Add your NYT key from https://developer.nytimes.com/my-apps with the line:
export API_KEY='YOUR_KEY'
- Run command in terminal
python3 lect6-demo.py
- See output with list of election articles