An opinionated Python CLI boilerplate template for GitHub-hosted projects.
- Create a repository directly using this template
- Replace
py-cli-boilerplatewith your distribution name in all files - Replace
py_cli_boilerplatewith your package name in all files (dashes not allowed in package names) - Rename
src/py_cli_boilerplate/directory to your package name - Update pyproject.toml with your project details
- Update badge URLs in
README.mdwith your repository URL
- Enable Dependabot: Go to Settings > Code security and analysis > Dependabot to enable automatic dependency updates
- Enable Codecov: Set up Codecov integration for code coverage tracking
- Publishing on PyPI: See Publishing
- Typed Project: This template is configured as a typed project with the
py.typedmarker andTyping :: Typedclassifier in pyproject.toml. If your project won't provide type hints, removesrc/py_cli_boilerplate/py.typedand the typing classifier from pyproject.toml
uv automatically handles Python installation and setup in the background so you don't have to.
If your package is available on PyPI, the user can simply run the program using uvx:
uvx py-cli-boilerplateMake sure Python v3.10 or higher is installed.
Create a virtual environment (optional):
python -m venv .venv
source .venv/bin/activateInstall the package:
pip install py-cli-boilerplateOr, if the package is not (yet) available on PyPI, clone the repo and:
pip install .$py-cli-boilerplate --help
Usage: py-cli-boilerplate [OPTIONS] FOOBAR
FOOBAR is an example argument, its value is printed to stdout
Options:
-v, --verbose Increase verbosity (-v for INFO, -vv for DEBUG)
--save-log Write log output to log.txt
--version Show the version and exit.
--help Show this message and exit.
Example:
$py-cli-boilerplate "hello world" -vv
2025-12-15 14:14:32 DEBUG cli.py:22 (cli): Debug logging enabled
2025-12-15 14:14:32 INFO cli.py:25 (cli): Program started
hello world
2025-12-15 14:14:32 INFO cli.py:34 (cli): Program finishedRun from Python:
from py_cli_boilerplate import invoke
invoke(["-vv", "hello world"])Install uv. Then, install dependencies & activate the automatically generated virtual environment:
uv sync --locked
source .venv/bin/activateSkip --locked to use the newest dependencies (this might modify uv.lock)
Run tests:
pytestCheck code quality:
ruff check
ruff format --check
ty checkBetter yet, install the pre-commit hook, which runs code quality checks before every commit:
cp hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitThe CI build workflow (.github/workflows/build.yml) automatically runs tests and code quality checks on every push.
Version is derived from git tags using hatch-vcs with local_scheme = "no-local-version":
- Clean tagged commit:
1.0.0 - Commits after tag:
1.0.1.devN(where N is commit count after tag) - No tag exists:
0.1.devN
Create a tag via a GitHub release (see Publishing) or manually using git tag.
This project includes a GitHub Actions workflow (pypi-publish.yml) that uses pypa/gh-action-pypi-publish for publishing to test.pypi.org (the Test Python Package Index).
To publish:
- Create an account on test.pypi.org.
- Add the project to the list of trusted publishers.
- Create a release on GitHub. This triggers the workflow.
To publish on pypi.org instead of test.pypi.org, remove the repository-url line from pypi-publish.yml and remove pypiBaseUrl from the PyPI badge url in README.md.
This template uses:
- Click - For building CLI interfaces
MIT