Loading lesson…
Tie it all together. A command-line tool that reads a file, calls Claude, and prints a summary. Real code, real errors, real polish.
A good capstone is a script you'll actually use. This one reads any text file and streams a Claude summary to your terminal, with sensible errors and retries.
pip install anthropic
export ANTHROPIC_API_KEY=sk-ant-...One dependency, one env var. That is the setup.# summarize.py
import argparse
import sys
import time
from pathlib import Path
import anthropic
def read_text(path: Path) -> str:
if not path.exists():
sys.exit(f"error: {path} does not exist")
if path.stat().st_size > 500_000:
sys.exit(f"error: {path} is larger than 500 KB")
return path.read_text(encoding="utf-8")
def summarize(text: str, bullets: int, tries: int = 3) -> None:
client = anthropic.Anthropic()
prompt = (
f"Summarize the following text in exactly {bullets} bullet points. "
f"Each bullet under 20 words.\n\n{text}"
)
for attempt in range(1, tries + 1):
try:
with client.messages.stream(
model="claude-opus-4-7",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}],
) as stream:
for chunk in stream.text_stream:
print(chunk, end="", flush=True)
print()
return
except anthropic.APIStatusError as e:
if e.status_code in (429, 529) and attempt < tries:
wait = 2 ** attempt
print(f"\n[retry in {wait}s: {e.status_code}]", file=sys.stderr)
time.sleep(wait)
continue
raise
def main() -> None:
p = argparse.ArgumentParser(description="Summarize a text file with Claude.")
p.add_argument("file", type=Path)
p.add_argument("--bullets", type=int, default=5)
args = p.parse_args()
text = read_text(args.file)
summarize(text, bullets=args.bullets)
if __name__ == "__main__":
main()argparse for args, streaming for UX, exponential backoff on 429/529, size guard on input. Production-ish in 40 lines.# usage
python summarize.py README.md --bullets 3
python summarize.py meeting-notes.txt --bullets 7One script, many files. The kind of tool you keep on your PATH.The big idea: programming with AI is still programming. The skills you built across this track — types, tests, error handling, prompting — all show up in one small script that actually does something useful.
15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-progx-python-ai-builder-capstone-creators
What is the core idea behind "Capstone — Python CLI That Summarizes With Claude"?
Which term best describes a foundational idea in "Capstone — Python CLI That Summarizes With Claude"?
A learner studying Capstone — Python CLI That Summarizes With Claude would need to understand which concept?
Which of these is directly relevant to Capstone — Python CLI That Summarizes With Claude?
What is the recommended tip about "Always review AI output" in the context of Capstone — Python CLI That Summarizes With Claude?
What is the key insight about "Extend it carefully" in the context of Capstone — Python CLI That Summarizes With Claude?
Which statement accurately describes an aspect of Capstone — Python CLI That Summarizes With Claude?
What does working with Capstone — Python CLI That Summarizes With Claude typically involve?
Which best describes the scope of "Capstone — Python CLI That Summarizes With Claude"?
Which of the following is a concept covered in Capstone — Python CLI That Summarizes With Claude?
Which of the following is a concept covered in Capstone — Python CLI That Summarizes With Claude?
Which of the following is a concept covered in Capstone — Python CLI That Summarizes With Claude?
Which of the following is a concept covered in Capstone — Python CLI That Summarizes With Claude?
Which of the following is a concept covered in Capstone — Python CLI That Summarizes With Claude?
Which of the following is a concept covered in Capstone — Python CLI That Summarizes With Claude?