Skip to main content

Claude/ChatGPT Prompt to Build a Type-Safe Python CLI with Click

Prompt to scaffold a production Python CLI with Click: type hints, Rich output, pyproject entry points, pytest tests, and proper exit codes.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt casts the model as a senior Python engineer who ships internal tooling and asks it to build a production-ready CLI using Click, returning working code and a full file tree rather than pseudocode. It defines six deliverables: a src-layout project with pyproject.toml and console_scripts entry points, a Click command group with type hints on every function, Rich for colored output, tables, and progress spinners, clear per-subcommand help and sensible exit codes, a pytest suite using Click's CliRunner, and packaging notes. The structure works because it bakes types, tests, and real exit codes in from the start, which is exactly what stops a one-off script from rotting.

Four variables drive it. [cli_name] names the tool (default devops-cli) and seeds the entry point. [python_version] sets the language target, like Python 3.12. [commands] lists the subcommands — deploy, rollback, status, logs — each becoming a typed Click command. [distribution] describes how it ships, such as internal PyPI plus pipx install, which the packaging notes target. The CliRunner tests in deliverable five are the load-bearing part: wiring them early covers success and error paths and prevents silent breakage as the tool grows and teammates start depending on it.

When to use it

  • You are turning a one-off Python script into a real, installable command-line tool.
  • You want type hints, tests, and proper exit codes designed in rather than bolted on later.
  • A teammate needs to install and trust the CLI, so packaging matters.
  • You want Rich output with tables and a progress spinner for long-running calls.
  • You need per-subcommand help text and exit codes that distinguish failure classes.
  • You want a pytest suite with Click's CliRunner covering success and error paths.

Example output

Expect the file tree first, then each file's full contents in order, all targeting [python_version]. You get a src-layout project with pyproject.toml and console_scripts wiring [cli_name], a Click command group where each entry in [commands] is a typed subcommand, Rich-based colored output with tables and a spinner, clear --help per subcommand with exit codes (0 for success, non-zero per failure class), a pytest suite using CliRunner across success and error paths, and install notes for [distribution]. It is a buildable, installable scaffold rather than a finished product.

Pro tips

  • Choose a clean, importable [cli_name], since it seeds the entry point and the package's module names.
  • List the real subcommands in [commands]; each becomes a typed Click command, so vague names produce vague stubs.
  • Set [python_version] to what you actually run so type-hint syntax and features match your interpreter.
  • Describe [distribution] accurately (pipx, internal PyPI) so the packaging notes are usable, not generic.
  • Wire the CliRunner cases early; they cover success and error paths and stop silent breakage later.
  • Use exit codes per failure class so automation can branch on them rather than parsing stdout.

Frequently Asked Questions

Does this prompt include tests for the CLI?
Yes, a pytest suite using Click's CliRunner is a required deliverable, covering both success and error paths. Wiring these tests early is what stops silent breakage as the tool grows and teammates start depending on it.
Can I choose which subcommands the CLI has?
The `[commands]` variable lists the subcommands, defaulting to deploy, rollback, status, and logs. Each entry becomes a typed Click command, so list the real subcommands you need rather than leaving them generic.
How does it package the tool for distribution?
It produces a pyproject.toml with console_scripts entry points and packaging notes targeting your `[distribution]` value, such as internal PyPI plus pipx install. Set that variable accurately so the install instructions match how you actually ship.
Does it use type hints throughout?
The prompt requires type hints on every function in the Click command group, targeting your chosen `[python_version]`. This is part of making a one-off script into something durable that a teammate can read, test, and trust.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Python & Automation Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support