本文へ移動
cccskills
無料GitHub で公開

python3-cli

Use when building CLI applications with Typer and Rich — creating commands with Annotated parameter syntax, defining arguments and options, composing subcommands, async concurrent CLI tasks with semaphores, testing with CliRunner, PEP 723 shebang scripts, progress bars, Rich terminal output, or non-TTY display width handling.

インストール方法を見る

含まれるファイル(38)

  • SKILL.md4.8 KB
  • assets/nested-typer-exceptions/.gitignore12 B
  • assets/nested-typer-exceptions/nested-typer-exception-explosion_corrected_rich_console.py6.3 KB
  • assets/nested-typer-exceptions/nested-typer-exception-explosion_corrected_typer_echo.py6.1 KB
  • assets/nested-typer-exceptions/nested-typer-exception-explosion_naive_workaround.py7.0 KB
  • assets/nested-typer-exceptions/nested-typer-exception-explosion.py6.3 KB
  • assets/python-cli-demo.py16.7 KB
  • assets/typer_examples/console_containers_no_wrap.py6.4 KB
  • assets/typer_examples/console_no_wrap_example.py2.7 KB
  • assets/typer_examples/index.md5.6 KB
  • references/architecture-spec-patterns.md9.2 KB
  • references/project-structure.md787 B
  • references/python-version-feature-matrix.md12.8 KB
  • references/quality-gate.md3.4 KB
  • references/rich-advanced-patterns.md8.0 KB
  • references/rich-console-and-markup.md11.1 KB
  • references/rich-logging-and-tracebacks.md6.3 KB
  • references/rich-progress-and-live.md9.7 KB
  • references/rich-renderables.md9.5 KB
  • references/rich-text-and-syntax.md8.2 KB
  • references/testing-spec-guidance.md3.9 KB
  • references/textual/app-and-screens.md8.8 KB
  • references/textual/events-and-actions.md12.1 KB
  • references/textual/layout-and-css.md9.8 KB
  • references/textual/reactivity.md7.8 KB
  • references/textual/testing-and-workers.md9.7 KB
  • references/textual/widgets.md14.7 KB
  • references/type-system-design-patterns.md13.7 KB
  • references/typer-advanced-patterns.md6.0 KB
  • references/typer-app-and-commands.md3.5 KB
  • references/typer-parameter-types.md4.7 KB
  • references/typer-parameters.md7.1 KB
  • references/typer-rich-exception-handling.md14.5 KB
  • references/typer-rich-non-tty-patterns.md23.5 KB
  • references/typer-rich-tables.md4.8 KB
  • references/typer-rich-testing-patterns.md14.4 KB
  • references/typer-subcommands.md3.6 KB
  • references/typer-testing.md3.7 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

CLI Development

Consult standards-for-python-development for the shared rules. Load python3-testing for test patterns.

Audience First

Before choosing presentation libraries, identify the primary consumer.

  • A CLI implemented inside an Agent Skill or plugin is agent-facing by default. Do not use Rich for its command output. Emit compact JSON on stdout, preferably from a Pydantic response model with model_dump_json(); do not indent it. Send diagnostics to stderr and keep the JSON schema stable.
  • Human-facing CLIs may use Typer + Rich for terminal presentation.
  • For mixed audiences, compact JSON is the automation contract; human formatting is an explicit presentation mode.

Agents must not need to parse tables, colours, progress bars, panels, or explanatory prose to consume a tool result.

Standards

  • Annotated[Type, typer.Option(...)] syntax for all CLI params
  • rich_help_panel to group options
  • Rich emoji tokens (:white_check_mark:) not Unicode literals for human-facing output
  • Architecture: CLI → Business Logic → Services → Output boundary (compact JSON for agents; Rich display for humans)
  • uv run <script> over python3 <script>
  • Factory pattern for dependency injection

App Structure

import typer
from rich.console import Console

app = typer.Typer()
console = Console()


@app.command()
def process(
    input_file: Annotated[Path, typer.Argument(help="Input file")],
    verbose: Annotated[bool, typer.Option("--verbose", "-v")] = False,
) -> None:
    """Process input file."""
    ...

Rich Width Handling

from rich.console import Console
from rich.table import Table
from rich.measure import Measurement


def get_table_width(table: Table) -> int:
    temp = Console(width=9999)
    m = Measurement.get(temp, temp.options, table)
    return int(m.maximum)

Testing

from typer.testing import CliRunner

runner = CliRunner()


def test_app_runs() -> None:
    result = runner.invoke(app, ["--help"])
    assert result.exit_code == 0

Async Patterns

Use semaphores for I/O-bound CLI tasks:

import asyncio
import typer
from typing import Annotated


@app.command()
def fetch(urls: Annotated[list[str], typer.Argument()], max_concurrent: Annotated[int, typer.Option()] = 10) -> None:
    """Fetch multiple URLs concurrently."""
    results = asyncio.run(_fetch_all(urls, max_concurrent))
    for result in results:
        console.print(result)


async def _fetch_all(urls: list[str], limit: int) -> list[str]:
    sem = asyncio.Semaphore(limit)
    async with httpx.AsyncClient() as client:
        tasks = [_fetch_one(client, u, sem) for u in urls]
        return await asyncio.gather(*tasks)

PEP 723 Shebang

#!/usr/bin/env -S uv run --quiet --script
# /// script
# requires-python = ">=3.11"
# dependencies = ["typer>=0.21", "rich>=13.0"]  # human-facing example only
# ///

References

  • references/typer-app-and-commands.md, references/typer-parameters.md, references/typer-parameter-types.md, references/typer-advanced-patterns.md, references/typer-subcommands.md, references/typer-testing.md — Typer commands, arguments, parameters, subcommands
  • references/rich-console-and-markup.md, references/rich-renderables.md, references/rich-text-and-syntax.md, references/rich-advanced-patterns.md, references/rich-progress-and-live.md, references/rich-logging-and-tracebacks.md — Rich tables, panels, progress, live displays
  • references/typer-rich-non-tty-patterns.md, references/typer-rich-tables.md, references/typer-rich-exception-handling.md, references/typer-rich-testing-patterns.md — Typer+Rich integration, non-TTY, width, testing

Related Skills

Load python-engineering:textual when the task involves Textual TUI widgets, screen stack, CSS styling, reactive attributes, Pilot testing, or background workers.

Load python-engineering:typer when the task is focused on Typer commands, parameter configuration, subcommand composition, or Typer-specific documentation.

Load python-engineering:typer-and-rich when the task involves Rich table rendering in non-TTY contexts, Typer/Rich integration pitfalls, or correctness review of CLI output handling.

Assets

  • assets/python-cli-demo.py — complete working example
  • assets/typer_examples/index.md — working scripts demonstrating non-TTY display solutions (Panel/Table width, wrapping, cropping)
  • assets/nested-typer-exceptions/ — runnable demos of Typer nested exception anti-patterns and fixes

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Add automated documentation updater to any Claude skill. Creates a Python sync script that downloads upstream docs, processes markdown for AI consumption, and maintains local cache with configurable refresh. Collects template variables, then delegates implementation through 5-phase workflow. Use when adding auto-updating reference documentation to plugins or skills.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

SAM-style feature initiation workflow — discovery through codebase analysis, architecture spec, task decomposition, validation, and context manifest. Use when a user asks to add a feature, plan a feature, or convert an idea into an executable SAM plan.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Browser automation for AI agents using the agent-browser CLI and Playwright. Use when navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, logging into sites, or automating any browser task. Triggers on "open a website", "fill out a form", "click a button", "scrape data", "test this web app", "automate browser actions", or any programmatic web interaction request.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Runs the description-drift experiment — spawns all Claude Code agents simultaneously to collect self-reported capabilities, then compares them against static frontmatter descriptions to reveal how reliable orchestrator routing based on descriptions actually is. Use when measuring description drift across the agent fleet, re-running the capability collection experiment, analyzing a specific agent's self-reported capabilities, or auditing whether frontmatter descriptions accurately reflect agent behavior.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Create or adapt Claude Code agent definitions. Use when creating an agent, changing subagent configuration, selecting agent scope, or designing a specialized delegation role.

日本語の概要は準備中です。原文の説明を表示しています。

Jamie-BitFlight/claude_skills672026年10月9日 更新

Jamie-BitFlight のスキルをすべて見る

このスキルの問題を報告する