Skip to content

typer-swissknife

A lightweight companion library for Typer.

Three helpers that cover common CLI patterns while staying close to Typer's own behaviour:

  • command: register a command with aliases, an optional ASCII-art banner, and undeclared options collected into **kwargs.
  • add_typer: add a sub-app as a command group with aliases and an optional banner.
  • get_ascii_help_text / render_ascii_art: build banner help text yourself.

A first taste

import typer

from typer_swissknife import add_typer, command

app = typer.Typer()
admin = typer.Typer()


@command(app, name="list", aliases=("ls",), ascii_name="List")
def list_items() -> None:
    """List all items."""
    print("Listing items...")


@command(admin, aliases=("rm",))
def remove(item: str) -> None:
    print(f"Removing {item}")


add_typer(
    app,
    admin,
    name="admin",
    ascii_name="Admin",
    aliases=("a",),
    help="Administrative commands",
)

if __name__ == "__main__":
    app()
$ python app.py ls
Listing items...

$ python app.py a rm report.txt
Removing report.txt
  • list, ls, admin and a all work. --help lists each one once, as list (ls) and admin (a).
  • python app.py list --help and python app.py admin --help start with a big LIST / ADMIN banner. The commands list keeps the plain one-line help.

Collect options you did not declare

import typer

from typer_swissknife import command

app = typer.Typer()


@command(app)
def report(name: str, **filters: int) -> None:
    print(name, filters)


@command(app)
def version() -> None:
    print("1.0")

if __name__ == "__main__":
    app()
$ python app.py report sales --year 2026 --page-size=50
sales {'year': 2026, 'page_size': 50}

Each value is converted with the **kwargs annotation; a bad value is a normal usage error. See Undeclared options.

Where to next