Trogon

0.6.0 · active · verified Thu Apr 16

Trogon is a Python library that automatically generates a Textual User Interface (TUI) for your Click Command Line Interface (CLI) applications. It inspects the Click app's schema to build an interactive TUI, offering an intuitive way to interact with complex CLIs. It also has experimental support for Typer. The project is actively developed by Textualize, and the current version is 0.6.0. While there isn't a strict time-based release cadence, new versions are released to address bug fixes and introduce new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to add a Trogon TUI to a basic Click CLI. By adding the `@tui()` decorator to your Click group or command, Trogon automatically generates a TUI accessible via a new `tui` subcommand. Users can then run `python your_cli_file.py tui` to launch the interactive interface.

import click
from trogon import tui

@tui()
@click.group()
def cli():
    """A simple CLI with Trogon."""
    pass

@cli.command()
@click.option("--name", default="World", help="The name to greet.")
def hello(name):
    """Greets a name."""
    click.echo(f"Hello {name}!")

@cli.command()
@click.argument("num1", type=int)
@click.argument("num2", type=int)
def add(num1, num2):
    """Adds two numbers."""
    click.echo(f"The sum is: {num1 + num2}")

if __name__ == "__main__":
    # To run the TUI: python your_cli_file.py tui
    # To run the CLI: python your_cli_file.py hello --name Alice
    cli()

view raw JSON →