Build CLI tools with Click or Typer in Python
✓Works with OpenClaudeYou are a Python CLI developer. The user wants to build command-line tools using Click or Typer frameworks in Python.
What to check first
- Run
pip list | grep -i clickorpip list | grep -i typerto verify the framework is installed - Check Python version with
python --version— Click requires Python 3.7+, Typer requires Python 3.6+ - Verify the entry point in
setup.pyorpyproject.tomlif building a distributable CLI
Steps
- Install Click with
pip install clickor Typer withpip install typer— choose one framework based on your preference (Click is more mature, Typer is more modern with type hints) - Import the framework at the top:
import clickorfrom typer import Typer - Create a Click group or Typer app instance with
@click.group()decorator orapp = Typer() - Define command functions and decorate them with
@click.command()or attach them directly to the Typer app with@app.command() - Add parameters using
@click.option()or@click.argument()for Click, or function parameters with type hints for Typer - Implement help text with the
help=parameter in decorators or docstrings for Typer - Test the CLI locally with
python your_script.py --helpto verify all commands and options display correctly - Configure entry points in
setup.pyunderentry_points['console_scripts']to make the CLI installable as a command-line tool
Code
import click
from typing import Optional
@click.group()
def cli():
"""Main CLI application for managing users."""
pass
@cli.command()
@click.option(
'--name',
prompt='User name',
help='Full name of the user'
)
@click.option(
'--email',
required=True,
help='Email address'
)
@click.option(
'--verbose',
'-v',
is_flag=True,
help='Enable verbose output'
)
def create_user(name: str, email: str, verbose: bool):
"""Create a new user with name and email."""
if verbose:
click.echo(f"Creating user: {name} ({email})")
click.echo(f"✓ User {name} created successfully")
@cli.command()
@click.argument('user_id', type=int)
@click.option(
'--format',
type=click.Choice(['json', 'text']),
default='text',
help='Output format'
)
def get_user(user_id: int, format: str):
"""Retrieve user information by ID."""
user_data = {'id': user_id, 'name': 'John Doe', 'email': 'john
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Python Skills
Other Claude Code skills in the same category — free to download.
Django Setup
Scaffold Django project with models, views, and URLs
Flask Setup
Scaffold Flask application with blueprints and extensions
FastAPI Setup
Scaffold FastAPI with async endpoints and auto-docs
Pytest Setup
Configure pytest with fixtures, plugins, and coverage
Python Venv
Set up Python virtual environments and dependency management
Poetry Setup
Set up Poetry for Python dependency and package management
Python Typing
Add comprehensive type hints and mypy configuration to Python code
Django REST Framework
Set up Django REST Framework with serializers and viewsets
Want a Python skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.