The Project: the Booknook Shelf
Every lesson in this course is set in one place, on one project. Booknook is made up. The café, its owner, its volunteer, its members and every loan are fictional and simulated. The books are real public-domain titles. The real cases that open each lesson are separate, cited, and clearly marked as real.
The place
Kettle and Page is a small café with a lending shelf in the corner, called Booknook. Customers donated twenty-four books. Anyone who signs up as a member can borrow a book for two weeks for free. Bring it back late and you pay a small fee, which goes in the café's charity jar.
The shelf opened on Tuesday 1 September 2026. For two weeks the loans were written in a paper notebook. Since Monday 14 September they have been kept in a spreadsheet. Neither is working well: nobody can say quickly which books are out, who is late, or how much should be in the jar.
The problem
Amira, who owns the café, wants the shelf's records kept by a small program she can trust:
- Which books are on the shelf, and which are out, and with whom?
- Who is overdue, by how many days, and what do they owe?
- Lend a book and take it back, refusing a fourth book to anyone who already has three.
- Read Tom's old notebook and say which lines are wrong, instead of guessing.
- Give the same answer every time it is asked the same question.
- One command each morning that prints the day's report.
You are the person building it. You start knowing no Python at all; by the end you have a tested package with classes, files and a command-line tool.
What this course uses the project for
This course is about Python itself: values, text, decisions, loops, collections, functions, modules, files, errors, classes and tests. The shelf is the instrument. It is small enough to hold in your head (24 books, 6 members, 40 loans) and real enough to need every one of those tools. Each module answers a harder question from Amira, because each module gives you a better tool.
It has nothing to do with the companies in the other courses in this series. No language models are used anywhere.
The people
| Name | Who | In the project |
|---|---|---|
| Amira Haddad | Owns Kettle and Page and runs the shelf | Asks the question that opens each module. Decides what the rules mean when they are unclear |
| Tom Reyes | Saturday volunteer | Kept the paper notebook for the first two weeks and typed it up badly. His notebook is the course's messy data |
| You | The person building the records program | Write every line of it |
The six members:
| Id | Name | Joined | In the examples |
|---|---|---|---|
| M01 | Priya Nair | 1 September | Reads mysteries. Never late. Her book returned exactly on its due date is the course's example of "on time" |
| M02 | Ben Carter | 1 September | Often late. Two late returns and one book 9 days overdue: the "what does Ben owe?" example |
| M03 | Lena Fischer | 4 September | Reads romance and drama. Has Jane Eyre out, 1 day overdue |
| M04 | Kwame Asante | 1 September | Borrows the most. Has 3 books out on 14 October, the limit |
| M05 | Sofia Marin | 21 September | Joins mid-way: the "new member" example. Not in Tom's notebook |
| M06 | Jonah Webb | 2 September | Has Frankenstein out since 14 September, past the fee cap. Lists no favourite genres |
Minor characters (another café customer, a new volunteer) may appear in one lesson. Do not add main characters.
The rules
| Rule | Value |
|---|---|
| Loan period | 14 days. The due date is the borrow date plus 14 days |
| On time | A book returned on or before its due date is on time. It is overdue only from the day after |
| Late fee | 20 pence for each day after the due date |
| Fee cap | At most 300 pence (£3.00) for one loan, reached at 15 days late |
| Limit | At most 3 books out per member at once |
| Due soon | A loan still out is "due soon" when its due date is 1 to 3 days away: DUE_SOON = 3, from Module 4 |
| Money | Always held as whole pence, an int. Pounds appear only when printed, as £3.00 |
| Fee jar | Fees are paid when a late book comes back. The jar holds only fees paid; fees on books still out are owed, not in the jar |
| Today | The course's "today" is Wednesday 14 October 2026. Code that depends on the date is given it as a parameter, never reads the computer's clock |
The rules and data as code are in 06-shared-data.md.
The data
| File | What it holds | First used |
|---|---|---|
data/books.csv | 24 books, ids B01 to B24, in seven genres; 27 copies in all | Module 8 (as a file); Module 5 as a list in code |
data/members.json | 6 members, each with a list of favourite genres | Module 8; Module 5 as a list in code |
data/loans.csv | 40 loans, L01 to L40, from 14 September to 13 October 2026 | Module 8; Module 7 as code |
data/tom_notebook.txt | 12 typed lines from 1 to 13 September, with exactly five faults | Module 3 (a few lines); Module 8 (the whole file) |
Modules 1 to 4 use smaller slices written straight into the lesson: one book and one loan in Module 1, then six books and twelve loans with dates as "shelf days" (14 September is day 14, 14 October is day 44) until the datetime module arrives in Module 7. The exact slices are in 06-shared-data.md.
The answers on 14 October
These come from running the code in 06-shared-data.md. Every lesson that reaches one of them must get the same number.
| Question | Answer |
|---|---|
| Copies out | 9 of 27 |
| Overdue | 4 loans: L04 Jonah, Frankenstein, 16 days, 300p (capped); L13 Ben, The War of the Worlds, 9 days, 180p; L21 Kwame, Pride and Prejudice, 4 days, 80p; L23 Lena, Jane Eyre, 1 day, 20p |
| Owed on overdue loans | 580p (£5.80) |
| Due within 3 days | L24 Priya, The Adventures of Sherlock Holmes, due 15 October; L26 Sofia, Alice's Adventures in Wonderland, due 17 October |
| Fee jar | 280p (£2.80), from four late returns: L02, L07 (Ben), L09 (Kwame), L10 (Lena) |
| At the limit | Kwame, 3 books out |
Never lent in loans.csv | B15, The Call of the Wild |
| Tom's notebook faults | 5: a short date (line 4), Frankenstien (line 5), lena (line 6), a return before the borrow (line 8), a duplicate of line 7 (line 11) |
Dates
- Tuesday 1 September 2026: the shelf opens. Tom records loans in his paper notebook.
- Monday 14 September: Amira starts the loans spreadsheet,
loans.csv. Tom's notebook is never typed in properly. - Monday 21 September: Sofia joins.
- Tuesday 13 October: the last loan in the data (Kwame takes Wuthering Heights).
- Wednesday 14 October 2026: the course's fixed "today", and the date facts in the course were checked. Every module is set on this day. Lessons are told in the present tense.
What Amira asks, module by module
| Module | Amira asks | What you add |
|---|---|---|
| 1. Getting Started | "Can the computer print a card for one book?" | Variables for one book and one loan; a printed shelf card |
| 2. Values, Types and Operators | "What does Ben owe if he is 9 days late?" | The late fee in pence, with input() for days late, capped at 300 |
| 3. Strings and Text | "Can you read Tom's notebook?" | Cleaning notebook lines with string methods; a lined-up loan slip with f-strings |
| 4. Decisions and Loops | "Which of these twelve loans are overdue?" | A loop that labels each loan on time, due soon or overdue, and totals the fees |
| 5. Collections | "What is out, and who has it?" | The catalogue as a list of dictionaries; counts per genre; each member's books |
| 6. Functions | "I want the same answer every time." | due_date, days_late, is_overdue, late_fee and reminder_text, each checked with assert |
| 7. Modules and Packages | "Use real dates." | The booknook package: dates.py, fees.py, catalogue.py; real dates with datetime |
| 8. Errors, Files and Debugging | "Load the real files and fix Tom's notes." | storage.py: read the CSV and JSON files, parse the notebook into a problem list, save clean files |
| 9. Classes and Objects | "Lend and return books properly." | models.py: Book, Member and Loan dataclasses and a Library that enforces the 3-book limit |
| 10. Intermediate Python | "Make sure it never breaks." | tools.py: a generator of overdue loans, a logging decorator, a safe-save context manager; and tests with pytest |
| 11. Capstone | "Give me one command each morning." | python -m booknook report, overdue, lend and return, tested, with a README |
Fixed names
Lessons may add names; they do not rename these.
| Name | Where | What it is |
|---|---|---|
LOAN_DAYS, FEE_PER_DAY, FEE_CAP, MAX_BOOKS | Module 1 onwards; fees.py from Module 7 | The rules: 14, 20, 300, 3 |
DUE_SOON | Module 4 | 3: days before the due date when a loan counts as due soon |
TODAY | Module 7 onwards | date(2026, 10, 14); before Module 7, TODAY_DAY = 44 |
due_date(borrowed) | Module 6; dates.py | The borrow date (a shelf day in Module 6, a date from Module 7) plus 14 days |
days_late(borrowed, today) | Module 6; dates.py | Days after the due date, or 0 |
is_overdue(borrowed, today) | Module 6; dates.py | True when today is after the due date |
late_fee(days_late) | Module 6; fees.py | Pence owed: 20 a day, at most 300, never below 0. The settled body, from the Module 6 lab on, is min(max(days_late, 0) * FEE_PER_DAY, FEE_CAP) |
reminder_text(name, title, days_late) | Module 6; fees.py | The reminder message for one overdue loan, always worded Dear Ben, The War of the Worlds is overdue. Days late: 9. Fee so far: £1.80. |
load_books, load_members, load_loans, parse_notebook, save_loans | Module 8; storage.py | Read and write the data files; parse_notebook returns the clean loans and a list of problems |
Book, Member, Loan, Library | Module 9; models.py | The classes. Library.lend, Library.return_book (return is a Python keyword), Library.overdue(today) |
The function names keep the same meaning when the dates change from shelf days to real dates in Module 7: only what goes in changes.
One repository: which module adds which file
Modules 1 to 6 work inside notebook cells. Small practice scripts such as hello.py are made along the way, but they are not part of the project. From Module 7 everything you keep goes in one folder, booknook, in your Google Drive in Colab (02-setup-colab.md, section 7) or on your own computer (07-run-locally.md). Inside it is the Python package, also called booknook. Every lab from Module 7 on starts with the %%ensure cell, which restores any earlier file that is missing and keeps the ones you already have.
| Module | Adds to the repository |
|---|---|
| 1 to 6 | Nothing yet: the work lives in notebook cells. Module 6's functions are the first code that moves into the package |
| 7 | booknook/__init__.py, booknook/dates.py (due_date, days_late, is_overdue, with real dates), booknook/fees.py (the rules, late_fee, reminder_text), booknook/catalogue.py (counts per genre, copies available); requirements.txt (pytest, pinned); the four data files from 06-shared-data.md, data/books.csv, data/members.json, data/loans.csv, data/tom_notebook.txt (written by the lab) |
| 8 | booknook/storage.py (load, parse with a problem list, save); data/notebook_loans.csv (Tom's clean loans, saved by save_loans). Module 8 is the first to read the data files |
| 9 | booknook/models.py (Book, Member, Loan, Library) |
| 10 | booknook/tools.py (a generator of overdue loans, a logging decorator for lending and returning, a safe-save context manager); requirements-dev.txt (mypy, plus everything in requirements.txt); tests/test_fees.py, tests/test_dates.py, tests/test_storage.py, tests/test_models.py. models.py and storage.py are not changed |
| 11 | booknook/__main__.py (the command line), booknook/report.py (the morning report); tests/test_cli.py; README.md |
The finished repository:
booknook/
booknook/
__init__.py __main__.py dates.py fees.py catalogue.py
storage.py models.py tools.py report.py
data/
books.csv members.json loans.csv tom_notebook.txt notebook_loans.csv
tests/
test_fees.py test_dates.py test_storage.py test_models.py test_cli.py
requirements.txt
requirements-dev.txt
README.mdThe file is called storage.py, not io.py, because io is already the name of a module that comes with Python, and a file with the same name hides it. Module 7 Lesson 1 uses this as its example of why not to name a file random.py.
The finished shelf
- A catalogue, members and loans read from plain files, and saved back safely
- Tom's notebook parsed, with every faulty line reported instead of guessed at
- Lending and returning that refuse a fourth book and a book with no copy left
- Due dates, days late and fees worked out the same way every time, from a date you pass in
- A morning report and an overdue list from one command
- Tests that fail the moment a change breaks a rule
The one idea
A program is a set of rules written so exactly that a computer can follow them. Amira's shelf has only four rules, and each module makes them more exact: first as numbers in variables, then as functions, then as classes, then as tests that prove the rules still hold. The course's job is to make you the person who can write them down that exactly.