Chapter 3. Creating Your Database
“You don’t seem to give much thought to the matter in hand,” I said at last, interrupting Holmes’ musical disquisition.
“No data yet,” he answered. “It is a capital mistake to theorize before you have all the evidence. It biases the judgement.”
“You will have your data soon,” I remarked.
Sir Arthur Conan Doyle, A Study in Scarlet (Ward Lock & Co., 1887)
In Chapter 2, you designed the API architecture and set up your GitHub Codespace environment. In this chapter, you will create the database and the Python code to read from it.
Since you are creating a data API, this chapter is important. It will walk you through the process of designing your database structures, creating them in the SQLite database, creating Python code to read the database, and creating unit tests to verify all of these pieces work together.
If you are in a rush to see how this code works, you can use the files in the chapter3/complete folder, and come back later to follow the instructions step by step.
Components of Your API
In the previous chapter, Figure 2-2 showed the application architecture you are implementing. The API in that diagram is made up of several components. Figure 3-1 shows these components and the software you will use to implement them.
Figure 3-1. API components
There are four major subcomponents of the API. The data transfer and validation components ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access