Files, JSON and Web APIs

22 min read

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

  1. Why do you need files, JSON and APIs?
  2. What is a file? Reading and writing text
  3. CSV: a table saved as text
  4. JSON: the language of APIs
  5. What is a web API?
  6. Calling an API with the requests library
  7. Keep your API keys secret
  8. Try it: the API request inspector
  9. Common mistakes
  10. Explain it to a friend
  11. Key takeaways

10 quiz questions at the end.

Start this lesson

The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.

All lessons · Back to the roadmap