Command-line to-do app
A to-do manager you run from the terminal: add, list, complete and delete tasks, saved to a file.
What you'll learn
- โCommand-line arguments with argparse
- โReading and writing JSON
- โOrganising code into functions and modules
What you'll build
- โtodo add "Buy milk" --due 2026-12-01
- โtodo list (pending first, overdue in red)
- โtodo done 3 and todo delete 3
- โTasks saved in tasks.json
Step-by-step guide
- 1
Design the data
Each task is a dict: {"id": 1, "title": "...", "due": "2026-12-01", "done": false}. All tasks live in a list saved to tasks.json.
- 2
Load and save
Write load_tasks() (return [] if the file does not exist) and save_tasks(tasks) using json.load / json.dump with indent=2.
- 3
Set up argparse sub-commands
Create a parser with add_subparsers(): add (title, --due), list, done (id), delete (id).
- 4
Implement add and list
add assigns the next id (max id + 1). list prints a table with id, title, due date and status; sort pending tasks by due date.
- 5
Implement done and delete
Find the task by id, show a friendly error if it does not exist, then update or remove it and save.
- 6
Highlight overdue tasks
Compare due with datetime.date.today(); print overdue rows in red using ANSI codes (\033[31m ... \033[0m).
- 7
Make it installable
Add a pyproject.toml with a [project.scripts] entry so pip install -e . gives you a real "todo" command.
๐ Make it stand out
- +Add priorities and tags with filtering
- +Switch storage to SQLite
- +Add a weekly summary command