A modern Python CLI template with best practices, featuring Typer, Ruff, pre-commit hooks, and comprehensive tooling setup.
- π Modern CLI with Typer and Rich
- π§ Development tools with Ruff for linting and formatting
- π‘οΈ Security with pre-commit hooks and secret detection
- π§ͺ Testing with pytest and coverage reporting
- π¦ Easy installation with uv support
- π― Type safety with mypy
- π Code quality with comprehensive linting rules
- π CI/CD with GitHub Actions for testing, linting, and releases
- π Coverage reporting with Codecov integration
This template includes comprehensive security scanning tools that run automatically in CI/CD pipelines and can be used during development:
-
OSV-Scanner - Vulnerability scanner based on the OSV.dev database
- Scans for known vulnerabilities in dependencies
- Uploads results to the GitHub Security tab via SARIF
- Integrated into CI pipeline and as a release gate
-
Bandit - Security linter for Python code
- Identifies common security issues in Python code
- Configurable via
pyproject.toml - Runs automatically in CI pipeline
-
Safety - Dependency vulnerability scanner
- Checks Python dependencies against known security vulnerabilities
- Integrates with requirements and package files
- Provides detailed vulnerability reports
-
detect-secrets - Prevents secrets from being committed
- Scans for API keys, tokens, and other sensitive data
- Uses baseline file to track known false positives
- Runs as pre-commit hook and in CI pipeline
All security tools generate JSON reports that are included as artifacts in GitHub releases, providing transparency and audit trails for security compliance.
uv is the recommended way to install Python CLI applications. Its uv tool command installs packages in isolated environments while making their entry points available globally.
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On macOS with Homebrew
brew install uv
# On Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# With pip
pip install uv# Install from PyPI (when published)
uv tool install py-plate-template
# Or install from local directory
uv tool install .
# Or install in development mode
uv tool install --editable .# Show help
py-plate --help
# Greet someone
py-plate hello Alice
# Greet with options
py-plate hello Bob --count 3 --shout
# Show system information
py-plate info
# Show version
py-plate --version
# Manage configuration
py-plate config --show
py-plate config --set debug true- Python 3.9 or higher
- uv (recommended) or pip
# Clone the repository
git clone https://github.com/GRodolphe/py_plate.git
cd py_plate
# Install in development mode with all dependencies
pip install -e ".[dev]"
# Or use uv for isolated development
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"# Install pre-commit hooks
pre-commit install
# Run hooks on all files (optional)
pre-commit run --all-files# Run all tests
pytest
# Run with coverage
pytest --cov
# Run specific test file
pytest tests/test_cli.py
# Run with verbose output
pytest -v# Format code
ruff format
# Lint code
ruff check
# Fix linting issues automatically
ruff check --fix
# Type check
mypy src/
# Run all quality checks
ruff check && ruff format --check && mypy src/ && pytest# Build the package
python -m build
# Upload to PyPI (requires authentication)
python -m twine upload dist/*py_plate/
βββ src/
β βββ py_plate/
β βββ __init__.py # Package version and metadata
β βββ cli.py # Main CLI application
βββ tests/
β βββ __init__.py
β βββ conftest.py # Pytest configuration and fixtures
β βββ test_cli.py # CLI tests
βββ .gitignore # Git ignore rules
βββ .pre-commit-config.yaml # Pre-commit hooks configuration
βββ .secrets.baseline # Secrets detection baseline
βββ pyproject.toml # Project configuration and dependencies
βββ README.md # This file
The project uses pyproject.toml for all configuration:
- Build system: Hatchling
- Dependencies: Typer, Rich
- Development tools: Ruff, mypy, pytest
- Code quality: Pre-commit hooks with multiple checkers
- Ruff: Linting and formatting rules
- Pytest: Test configuration and coverage
- MyPy: Type checking settings
- Pre-commit: Hook definitions for code quality
The template includes comprehensive CI/CD pipelines:
- Multi-version testing: Tests against Python 3.9, 3.10, 3.11, and 3.12
- Code quality: Ruff linting and formatting checks
- Type safety: MyPy type checking
- Test coverage: Pytest with coverage reporting
- Security scanning: Bandit and Safety checks
- Secret detection: Automated secret scanning
- Build verification: Package building and artifact upload
- Automated releases: Triggered on version tags
- PyPI publishing: Automatic package publishing
- GitHub releases: Automated release notes generation
- Pre-release validation: Full test suite before release
- Code quality gates: Automated pre-commit hook validation
- Consistent formatting: Ensures code standards across contributions
- Secret detection with detect-secrets
- Dependency vulnerability scanning with Safety
- Security linting with Bandit
- Pre-commit hooks for automated checking
- Automated security scans in CI pipeline
- Type hints throughout the codebase
- Comprehensive error handling
- Rich console output for better UX
- Structured logging ready for implementation
- Configuration management pattern
- Test coverage tracking
- Documentation with examples
- Fork the repository
- Create a feature branch
- Make your changes
- Run the test suite
- Submit a pull request
The pre-commit hooks will automatically run code quality checks on each commit.
This project is licensed under the MIT License - see the LICENSE file for details.
