Files, JSON and Web APIs
Almost every AI project moves data around. It may be a file of training examples, a table of results, or a reply from a model. In this lesson you will read and write files, and learn JSON, the text format that web services use. You will also see how a Python program calls a web API. You will learn to keep your secret key out of your code.
New words
- file
- Data saved on a disk under a name, such as notes.txt.
- JSON
- A text format for data that looks like Python dictionaries and lists.
- API
- A doorway that lets one program ask another program to do work.
- request and response
- Your message to a server, and the answer it sends back.
- status code
- A three-digit number that tells you how a request went.
- API key
- A secret code that tells a service who you are, like a UPI PIN.
- environment variable
- A setting stored outside your code, where you can keep secrets safe.
What you will learn
- Why do you need files, JSON and APIs?
- What is a file? Reading and writing text
- CSV: a table saved as text
- JSON: the language of APIs
- What is a web API?
- Calling an API with the requests library
- Keep your API keys secret
- Try it: the API request inspector
- Common mistakes
- Explain it to a friend
- Key takeaways
10 quiz questions at the end.
The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.