Midterm Project: Build a Real CLI Tool
মিডটার্ম প্রোজেক্ট — একটি বাস্তব CLI টুল তৈরি করুন
1. Ship Something Real
You have learned the core of Python. Now it is time to build a project that actually runs — something you can show on GitHub, use yourself, and keep improving. You will pick one of four tracks, design it, code it, test it, document it, and publish it.
2. Choose Your Track
Add, list, complete, delete todos. Store in a JSON file.
Bangla: কাজের তালিকা ব্যবস্থাপনা।
Secure passwords with length, symbol, digit options.
Bangla: নিরাপদ পাসওয়ার্ড জেনারেটর।
Rename files by pattern in a directory — with dry-run mode.
Bangla: পাইকারি ফাইল পুনঃনামকরণ।
Read a CSV, compute mean/median/min/max per column.
Bangla: CSV পরিসংখ্যান।
3. Core Skills You'll Apply
argparsefor parsing command-line arguments- File I/O — reading and writing JSON or text
- Functions with clear signatures and docstrings
- Error handling —
try/except, exit codes - Multi-file structure — separate logic from CLI
- README.md — installation, usage, examples
4. argparse Quick Primer
argparse turns a Python script into a professional CLI in a dozen lines — with --help,
default values, type checking, and subcommands.
import argparse
parser = argparse.ArgumentParser(description="Greet someone")
parser.add_argument("name", help="person's name")
parser.add_argument("--loud", action="store_true", help="shout")
parser.add_argument("--times", type=int, default=1)
# In a real CLI: args = parser.parse_args()
# Here we simulate a call for the demo:
args = parser.parse_args(["Ayesha", "--times", "3", "--loud"])
greeting = f"Hello, {args.name}!"
if args.loud:
greeting = greeting.upper()
for _ in range(args.times):
print(greeting)
5. Example: Track A Skeleton (Todo Manager)
import json
from pathlib import Path
DATA = Path("todos.json")
def load():
if DATA.exists():
return json.loads(DATA.read_text())
return []
def save(items):
DATA.write_text(json.dumps(items, indent=2))
def add(text):
items = load()
items.append({"text": text, "done": False})
save(items)
print(f"Added: {text}")
def list_all():
for i, t in enumerate(load(), 1):
mark = "✔" if t["done"] else " "
print(f"{i}. [{mark}] {t['text']}")
# Demo run
add("Finish Module 19")
add("Push to GitHub")
list_all()
Wrap this logic in an argparse front-end with subcommands add, list,
done N, delete N, and you have a full CLI todo manager.
6. Deliverables Checklist
| Must have | Nice to have |
|---|---|
README.md with install + usage | Logging |
requirements.txt (even if empty) | Config file (.ini, .toml) |
Works with --help | Basic tests (module 29 will cover) |
| Handles bad input gracefully | Color output with rich or ANSI codes |
| On GitHub with a clear commit history | Packaged with pipx |
7. Vocabulary (শব্দভাণ্ডার)
| Term | Meaning | বাংলায় |
|---|---|---|
| CLI | Command-line interface. | কমান্ড-লাইন ইন্টারফেস। |
| argparse | Stdlib module for parsing CLI args. | CLI argument parse করার stdlib module। |
| Subcommand | A secondary verb (git add, git commit). | দ্বিতীয়-স্তরের command (যেমন git add)। |
| Exit code | 0 = success, non-zero = error. | 0 = সফল, অন্য কিছু = error। |
| Dry run | Show what would happen without doing it. | কী হতে যাচ্ছে দেখানো, কিন্তু বাস্তবে না করা। |
8. Mini-Exercises Before You Start
-
Write an
argparse-based script that sums two numbers passed on the command line.argparseদিয়ে দুটি সংখ্যা যোগ করার script লিখুন।✨ Show Answer (উত্তর দেখুন)
ans1.pyimport argparse p = argparse.ArgumentParser() p.add_argument("a", type=int) p.add_argument("b", type=int) args = p.parse_args(["7", "12"]) # simulated print(args.a + args.b) -
Write a function that writes a list of dicts to a JSON file.Dict-এর একটি list-কে JSON ফাইলে লেখার ফাংশন লিখুন।
✨ Show Answer (উত্তর দেখুন)
ans2.pyimport json def save_json(path, data): with open(path, "w") as f: json.dump(data, f, indent=2) save_json("/tmp/demo.json", [{"id": 1, "text": "hello"}]) print(open("/tmp/demo.json").read()) -
Draft the top-level module layout for your chosen track (folder/file names only).আপনার বেছে নেওয়া track-এর top-level folder/file structure লিখুন।
✨ Show Answer (উত্তর দেখুন)
Example for Track A:
todo-cli/ ├── todo/ │ ├── __init__.py │ ├── storage.py # load/save JSON │ └── cli.py # argparse entry point ├── tests/ │ └── test_storage.py ├── README.md └── requirements.txt
-
Write a password generator that accepts
lengthand returns a random string.Length-ভিত্তিক random password generator ফাংশন লিখুন।✨ Show Answer (উত্তর দেখুন)
ans4.pyimport secrets, string def password(n=16): alphabet = string.ascii_letters + string.digits + "!@#$%^&*" return "".join(secrets.choice(alphabet) for _ in range(n)) print(password(12)) -
Write a README outline for your project (just the section headings).প্রোজেক্টের README-এর section heading-গুলো লিখুন।
✨ Show Answer (উত্তর দেখুন)
A solid README structure:
# Project Name A one-line tagline. ## Installation ## Quick Start ## Commands / Usage ## Examples ## Configuration ## Development / Testing ## License
Summary — Module 19
Pick one of the four tracks, scope it small, ship it. A working small project is worth far more than an ambitious abandoned one. By the end of this module you should have a GitHub repo with a README, a runnable script, and at least one real user (you).