๐Ÿ“ LLM & AI

Typer: CLI Applications Without the Boilerplate

P
Author
PyLand Team
๐Ÿ“…
Published
30.06.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
367
๐ŸŒฟ
Level
Medium

Typer builds CLIs from Python type annotations. No argparse, no manual parsing โ€” just decorators and types.

Installation

uv add typer

Basic application

import typer

app = typer.Typer()

@app.command()
def greet(name: str, times: int = 1):
    """Greets the user."""
    for _ in range(times):
        typer.echo(f"Hello, {name}!")

if __name__ == "__main__":
    app()
uv run python main.py Alice          # Hello, Alice!
uv run python main.py Alice --times 3  # Three times
uv run python main.py --help         # Auto-generated docs

Multiple commands

import typer

app = typer.Typer(help="AI agent CLI")

@app.command()
def chat(message: str = typer.Argument(..., help="Message for Claude")):
    """Send a message to Claude."""
    typer.echo(f"Sending: {message}")

@app.command()
def history(limit: int = typer.Option(10, help="Number of messages")):
    """Show conversation history."""
    typer.echo(f"Last {limit} messages")

@app.command()
def clear():
    """Clear the history."""
    typer.echo("History cleared")

if __name__ == "__main__":
    app()
uv run python main.py chat "Hello!"
uv run python main.py history --limit 5
uv run python main.py clear

Argument vs Option

@app.command()
def analyze(
    text: str = typer.Argument(...),           # required positional
    model: str = typer.Option("claude-sonnet-4-6"),  # --model
    verbose: bool = typer.Option(False, "--verbose", "-v"),  # flag
):
    pass
  • Argument(...) โ€” positional, required
  • Argument("default") โ€” positional with a default value
  • Option(default) โ€” named --param value

Colors and formatting

from rich.console import Console

console = Console()

@app.command()
def status():
    console.print("[bold green]โœ“[/] Agent running")
    console.print("[bold red]โœ—[/] Connection error")
    typer.echo(typer.style("Done", fg=typer.colors.GREEN, bold=True))

Interactive input

@app.command()
def setup():
    api_key = typer.prompt("Enter your API key", hide_input=True)
    confirm = typer.confirm("Save to .env?")
    if confirm:
        typer.echo("Saved!")

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

httpx: A Modern HTTP Client for Python

httpx is a next-generation HTTP client. Its interface is similar to requests, but it supports...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 329
๐Ÿ“

AI Agents: ReAct Loop and Autonomous Actions

A chatbot answers questions. An agent takes action: it calls tools, retrieves real data, and...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 334
๐Ÿ“

Document Chunking Strategies for RAG

Embedding a long document averages out its meanings โ€” a specific question won't find the...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 375
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Neural Networks in Code: 5 AI Projects in Python with Claude Open course curriculum