Skip to main content

typer-swissknife

typer-swissknife is a lightweight companion library for Typer that helps you build cleaner, more expressive CLI applications.

It focuses on a small set of practical helpers for common CLI patterns such as alias-aware commands, nested sub-apps, and richer help output.

Why use it

  • Keep command registration simple and readable.
  • Organize larger CLIs into smaller, reusable Typer components.
  • Improve discoverability with optional visual help text.
  • Stay close to Typer's native behavior while adding a bit more structure.

Features

  • Alias-aware command decorators
  • Nested Typer app registration
  • Optional ASCII-enhanced help sections
  • Undeclared options collected into **kwargs
  • Simple integration into existing Typer projects

Installation

pip install typer-swissknife

Quick example

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():
    """List all items."""
    print("Listing items...")

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

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

if __name__ == "__main__":
    app()
  • list, ls, admin and a all work; the help lists them once as list (ls) and admin (a).
  • ascii_name draws a banner at the top of that command's or group's --help page, while the commands list keeps the plain help text. Use ascii_font to pick any pyfiglet font (default: ansi_shadow).
  • The banner is formatted for the app's rich_markup_mode ("rich", "markdown" or None).

Undeclared options with **kwargs

Typer only accepts options that you declare. With command, a function that takes **kwargs also receives any option you did not declare:

import typer
from typer_swissknife import command

app = typer.Typer()

@command(app)
def some_command(name: str, **options: int):
    print(name, options)

if __name__ == "__main__":
    app()
$ some-command Abdullah --num1 10 --num2 20
Abdullah {'num1': 10, 'num2': 20}

$ some-command Abdullah --num1=10 --page-size=50
Abdullah {'num1': 10, 'page_size': 50}

$ some-command Abdullah --num1 abc
Usage: some-command [OPTIONS] NAME
Try 'some-command --help' for help.
┌─ Error ─────────────────────────────────────────────┐
│ Invalid value for --num1: 'abc' is not a valid int. │
└─────────────────────────────────────────────────────┘
  • Undeclared options can go before, between or after the arguments (some-command --num1 10 Abdullah works too).

  • Both --key value and --key=value work. Dashes in a name become underscores (--page-size gives page_size).

  • Each value is converted with the annotation of **kwargs (int, float, bool, ...). Without an annotation, values stay strings:

    @command(app)
    def tag(**labels):
        print(labels)  # tag --env prod --tier 2  ->  {'env': 'prod', 'tier': '2'}
    
  • Declared parameters work as usual, alongside the undeclared ones.

  • These inputs exit with a usage error: an option with no value (such as a bare --verbose), a stray positional word, and an option that has the same name as a declared parameter.

  • Undeclared options are not listed in --help.

Development

uv sync
uv run pytest

Tests run with branch coverage, and the run fails below 100%.

Project philosophy

This package is intentionally compact and focused. As the project grows, the goal is to keep the documentation high-level and feature-oriented rather than listing every helper in detail.

License

typer-swissknife is licensed under the GNU General Public License v3 (GPLv3).

Metadata

Release files for typer-swissknife 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for typer-swissknife 0.2.0
File Size Uploaded Provenance Actions
typer_swissknife-0.2.0.tar.gz 9.3 kB Without provenance Details for typer_swissknife-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for typer-swissknife 0.2.0
File Interpreter ABI Platform Actions
typer_swissknife-0.2.0-py3-none-any.whl Python 3 none any Details for typer_swissknife-0.2.0-py3-none-any.whl

Total release size: 20.9 kB

Release files / typer_swissknife-0.2.0.tar.gz

Download URL typer_swissknife-0.2.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fdc1cfb739df2dcd86228a526a2383683e263fa4a76e1d03cd7c9b3cd80afd76
BLAKE2b-256 checksum
How to use checksums
251337d42bdaedb46019174184c6814153020e6b74f3691f99d0a3c12402047d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / typer_swissknife-0.2.0-py3-none-any.whl

Download URL typer_swissknife-0.2.0-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4a0499f841b0333fcc15711e1b8e605b2da304945313492a09935389be04259
BLAKE2b-256 checksum
How to use checksums
aa3b10d98777fe9f8a312d15df6c391a4c03aaa43379d692cbedfc30bed1ba22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for typer-swissknife 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page