python-typer
Use when building or structuring Python CLI commands with Typer, including commands, options, and multi-command apps.
What this skill does
# Python CLI with Typer
## Overview
Use Typer for ergonomic CLI construction. Core principle: keep command wiring thin, explicit, and testable while moving business logic into regular Python functions.
## Use When
- Building a Python CLI with Typer.
- Adding commands, arguments, options, prompts, or confirmations.
- Wiring a module entry point or console script.
- Testing CLI behavior separately from business logic.
## Install
```bash
uv add typer
```
## Quick Reference
| Task | Pattern |
| --- | --- |
| Single command | `@app.command()` |
| Options | function args with defaults |
| Multiple commands | multiple `@app.command()` |
| Module run | `uv run python -m <package>.cli --help` |
| Script run | `uv run python cli.py --help` |
| CLI tests | `CliRunner().invoke(app, [...])` |
## Workflow
- Define a `typer.Typer()` app in `cli.py`.
- Keep command functions small; move business logic into separate modules.
- Wire either `if __name__ == "__main__": app()` for script/module execution or a project console script in `pyproject.toml`.
- Run CLI via `uv run python -m <module>` or `uv run python cli.py`.
- Test command parsing and exit behavior with `typer.testing.CliRunner`.
- Test business logic directly with normal function tests.
## Example
```python
import typer
app = typer.Typer()
@app.command()
def greet(name: str, count: int = 1) -> None:
for _ in range(count):
typer.echo(f"Hello, {name}!")
if __name__ == "__main__":
app()
```
Usage:
```bash
uv run python cli.py --help
uv run python cli.py Alice
uv run python cli.py Alice --count 3
```
Module entry point:
```bash
uv run python -m my_package.cli --help
```
Multiple commands:
```python
import typer
app = typer.Typer()
@app.command()
def create(name: str) -> None:
"""Create a new item."""
typer.echo(f"Creating {name}...")
@app.command()
def delete(name: str, force: bool = False) -> None:
"""Delete an item."""
if not force:
if not typer.confirm(f"Delete {name}?"):
raise typer.Abort()
typer.echo(f"Deleted {name}")
if __name__ == "__main__":
app()
```
CLI test:
```python
from typer.testing import CliRunner
from my_package.cli import app
runner = CliRunner()
def test_greet() -> None:
result = runner.invoke(app, ["Alice", "--count", "2"])
assert result.exit_code == 0
assert "Hello, Alice!" in result.stdout
```
## Common Mistakes
- Putting heavy business logic inside CLI functions.
- Forgetting to wire `if __name__ == "__main__"` for script entry.
- Testing only the underlying functions and missing CLI parsing or exit-code behavior.
- Adding shell parsing manually instead of using Typer arguments and options.
## Red Flags
- CLI guidance that ignores Typer when Typer is the chosen framework.
- CLI commands that cannot be run through `uv run`.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.