Python Typer CLI App Scaffold Prompt
Generate a modern, type-hint-driven CLI using Typer — subcommands, validated options, rich help, shell completion, and clean exit codes — for operations tools that need to feel like first-class CLIs.
- Target user
- Python developers building internal ops CLIs
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior Python engineer who builds internal operations CLIs that other teams actually enjoy using. You prefer Typer because the type hints ARE the interface contract. I will provide: - What the tool does and its subcommands (e.g. `deploy`, `rollback`, `status`) - The inputs each command needs (args vs options, required vs optional) - Any dangerous operations that need confirmation - Where it runs and how it's installed Your job: 1. **Model the command tree** — top-level `typer.Typer()` app, sub-apps via `app.add_typer()` for grouping, and one function per command. Use clear help text drawn from docstrings. 2. **Express every input as a typed parameter** — `typer.Argument(...)` for positionals, `typer.Option(...)` for flags. Lean on type hints (`Path`, `int`, `bool`, `Enum`, `Optional[str]`) so Typer handles parsing, validation, and `--help` automatically. Use `Enum` for choice options so invalid values are rejected before your code runs. 3. **Validate at the boundary** — `Path(exists=True, dir_okay=False)` for input files, `min`/`max` on ints, custom callbacks for cross-field rules. Fail with a clear message and a non-zero exit, never a traceback for user error. 4. **Confirmation + dry-run for destructive commands** — `typer.confirm()` or `--yes` to skip, plus a global `--dry-run` that logs intended actions without executing. Abort with `raise typer.Abort()`. 5. **Exit codes that mean something** — `raise typer.Exit(code=N)` with a documented table (0 ok, 1 generic error, 2 usage, custom codes for known failure modes) so scripts and CI can branch on them. 6. **Rich output, quiet when piped** — use `rich`/`typer.echo` for human output; add `--json` for machine-readable output and `--quiet`/`--verbose` to control log level. Detect non-TTY and drop color. 7. **Shell completion + entry point** — show the `pyproject.toml` `[project.scripts]` entry, and the `--install-completion` story. 8. **Testability** — structure so logic lives in importable functions and the Typer layer is thin; show a `CliRunner`/`typer.testing.CliRunner` test for one command including an error path. Output: (a) the full app module, (b) `pyproject.toml` snippet with the entry point and deps, (c) two example invocations with expected output, (d) one CliRunner test. Keep the CLI layer thin and push real work into plain typed functions.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Multi-Command Python CLI Tool Scaffold Prompt
Design a production-ready Python CLI tool with subcommands, global flags, config-file precedence, machine-readable output, and clean exit codes that an ops team can extend without rework.
-
Bash getopts Long-Options Parser Prompt
Build a robust Bash option parser that supports both short flags and GNU-style long options with validation and a generated usage block
-
Bash Terminal Color and Styling Library with tput Prompt
Build a reusable Bash output library that uses tput for colors, bold, and status glyphs, auto-disables styling when output is not a TTY or NO_COLOR is set, and degrades gracefully on dumb terminals.
-
Python argparse Subcommand CLI Without Dependencies Prompt
Scaffold a multi-command Python CLI using only the standard-library argparse — subparsers, shared global flags, env-var defaults, and clean exit codes — for scripts that must run with zero pip installs.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.