How to Write a Great Command Line Application
summary
Shows concrete patterns: build a CLI using argparse for the 90% case, parse types at the edge, wrap logic in a testable main that returns an int and a do(...) that accepts keyword args via vars(ns), handle file inputs without relying on deprecated filetype (Python 3.14), fix buffering and suppress broken pipe on pipelines, map -v count to logging levels, and ship a single-file script with a shebang or the uv shebang trick
AI-written summary · about
chapters (15)
- 0:00Command line apps intro
- 1:09How command line arguments work in Python
- 4:59Simple comparison script
- 7:05Type conversion in args
- 8:49Testable CLI with main
- 10:10Efficient file reading
- 12:59File inputs with argparse
- 15:23Optional args & output
- 16:27Business logic abstraction
- 18:54Continuous output with generators
- 20:41Broken pipes & interruptions
- 22:06Logging verbosity control
- 23:09Third-party CLI libraries
- 23:50Shebang lines for scripts
- 25:15CLI best practices summary
related talks
37mLet's Make Better Command Line Applications
36mCLI applications & TDD: Never write scripts again
01h 26mPackage Your Python Code as a CLI
16mBuilding an interactive CLI app in Elixir
29mBuilding Nice Command Line Interfaces — A Look Beyond the stdlib
31mStop writing scripts! CLI applications with TDD
16mHow Not To Build Your CLI’s
54mEmbrace the Unix Command Line and Supercharge Your PyData Workflow
