Packaging a Python CLI with pyproject.toml and Entry Points Prompt
Turn a Python script into a properly packaged, installable CLI using pyproject.toml, console entry_points, src layout, versioning, and a clean build/distribution workflow.
- Target user
- Developers packaging and distributing a Python command-line tool
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior Python engineer who packages CLIs the modern way — `pyproject.toml`, src layout, entry points, and a reproducible build/publish flow. I will provide: - The existing script/module and its dependencies - The command name users should type and the function it should call - Where it will be distributed (PyPI, private index, internal wheel, pipx) Produce a complete packaging setup that: 1. **Uses a `src/` layout** — `src/<package>/...` so tests run against the installed package, not the working tree, catching missing-data-file bugs early. Show the directory tree. 2. **Has a PEP 621 `pyproject.toml`** — `[project]` metadata (name, description, readme, license, authors, requires-python, classifiers), pinned-but-reasonable `dependencies`, and `[project.optional-dependencies]` for `dev`/`test`. Pick a backend (hatchling or setuptools) and configure it explicitly. 3. **Defines the console entry point** — `[project.scripts]` mapping `mytool = "mypkg.cli:main"` so `pip install` creates the command. The `main()` must be argv-driven and return an exit code. 4. **Handles versioning** — single source of truth (e.g. dynamic version from `__init__` or a VCS tag plugin); document how to bump and tag a release. 5. **Includes package data** — `[tool.hatch.build]`/`MANIFEST`/`package-data` for any non-Python files (templates, configs); show how to read them at runtime via `importlib.resources` (never relative file paths). 6. **Builds and checks** — `python -m build` to make sdist + wheel, `twine check dist/*`, and a smoke test: install the wheel in a fresh venv and run the command. 7. **Documents install paths** — `pip install`, `pipx install` for end-user CLIs, and editable `pip install -e ".[dev]"` for development. Output: (a) the full `pyproject.toml`, (b) the directory tree, (c) the `cli.py` `main()` skeleton, (d) `importlib.resources` example for bundled data, (e) the exact build/check/publish commands and a fresh-venv smoke test. Bias toward: src layout, PEP 621, `importlib.resources` over file paths, and a verifiable build before publishing.
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.
-
Python argparse Parent Parsers and Shared-Flag Layering Prompt
Compose argparse parsers with parents=[...] to share common flags across subcommands and layer config-file, env, and flag precedence
-
Python Click CliRunner Test Suite Prompt
Design a pytest suite that exercises a Click-based CLI end to end using CliRunner, covering exit codes, stdout/stderr separation, prompts, isolated filesystems, and env-var precedence without touching real systems.
-
Python Environment Markers & Platform-Conditional Deps Prompt
Author correct PEP 508 environment markers and platform-conditional dependency specifiers so an automation package installs the right wheels per OS, Python version, and architecture without forcing unneeded packages everywhere.
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.