본문으로 건너뛰기
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

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

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월 18일 업데이트

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월 18일 업데이트

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월 18일 업데이트

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월 18일 업데이트

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월 18일 업데이트

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월 18일 업데이트

Jamie-BitFlight의 스킬 모두 보기

이 스킬의 문제 신고