Python CLI Framework
Build beautiful, professional command-line tools with Click, Rich, and TOML configuration — from first command to PyPI package.
What You Get
-
Click-based CLI — Group commands with
--verbose,--output-format, and--config - Rich output — Tables, JSON, YAML, and CSV formatters with color and progress bars
- TOML configuration — Read/write config files with environment variable fallback
-
Project scaffolding —
initcommand generates new project structure from Jinja2 templates -
Task runner —
runcommand with Rich progress bars and error handling - Structured logging — Rich console handler with optional file rotation
- Full test suite — Click CliRunner tests for every command
- Best practices guide — Building, testing, and distributing CLI apps
File Tree
python-cli-framework/
├── src/
│ └── cli/
│ ├── main.py # CLI entry point with Click group
│ ├── commands/
│ │ ├── init.py # Project scaffolding command
│ │ ├── run.py # Task runner command
│ │ └── config.py # Config management command
│ ├── config.py # TOML config read/write
│ ├── output.py # Table/JSON/YAML/CSV formatters
│ ├── logging_setup.py # Structured logging
│ └── utils.py # Utility functions
├── templates/
│ ├── pyproject.toml.j2 # Project template
│ └── README.md.j2 # README template
├── tests/
│ ├── test_cli.py # CLI command tests
│ └── test_config.py # Config tests
├── guides/
│ └── building-cli-apps.md # Best practices guide
└── pyproject.toml # Package configuration
Getting Started
1. Install
pip install -e ".[dev]"
2. Try the CLI
# Initialize a new project
mycli init my-project --template default
# View configuration
mycli config list
mycli config get project.name
mycli config set project.version "2.0.0"
# Run tasks with progress bars
mycli run build --verbose
# Change output format
mycli --output-format json config list
mycli --output-format table config list
3. Use as a starting point
# src/cli/main.py — extend with your own commands
from cli.main import cli
@cli.command()
@click.argument("name")
def greet(name: str) -> None:
"""Say hello to NAME."""
click.echo(f"Hello, {name}!")
Requirements
- Python 3.10+
- click >= 8.1
- rich >= 13.0
- tomli >= 2.0 (Python < 3.11) / tomllib (Python 3.11+)
- tomli-w >= 1.0
- jinja2 >= 3.1
Architecture
┌─────────────────────────────────────────────┐
│ CLI Entry Point │
│ main.py: @click.group() + options │
│ --verbose --output-format --config │
└──────────────────┬──────────────────────────┘
│
┌──────────────┼──────────────┐
▼ ▼ ▼
┌────────┐ ┌────────┐ ┌──────────┐
│ init │ │ run │ │ config │
│scaffold│ │ tasks │ │ get/set │
└───┬────┘ └───┬────┘ └────┬─────┘
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────┐
│ Shared Layers │
│ config.py │ output.py │ utils.py │
│ (TOML) │ (Rich) │ (helpers) │
└──────────────────────────────────────┘
Running Tests
pytest tests/ -v
Related Products
- Python Automation Scripts — Ready-to-use automation script templates
- Python Packaging Guide — Package, distribute, and publish Python projects
- Python Logging & Config — Production logging configurations
This is 1 of 14 resources in the Python Developer Pro toolkit. Get the complete [Python CLI Framework] with all files, templates, and documentation for $29.
Or grab the entire Python Developer Pro bundle (14 products) for $159 — save 30%.
Top comments (0)