App

The App object is the implementations of your console application. It handles configuration, lifecycle management, command processing, and user interaction, coordinating the work of all components: routers, handlers, and system messages.


Initialization

 1def __init__(
 2    self,
 3    *,
 4    prompt: str = ">>> ",
 5    initial_message: str = "Argenta",
 6    farewell_message: str = "See you",
 7    exit_command: Command = Command("q", description="Exit command"),
 8    system_router_title: str = "System points:",
 9    dividing_line: StaticDividingLine | DynamicDividingLine | None = None,
10    repeat_command_groups_printing: bool = False,
11    override_system_messages: bool = False,
12    autocompleter: AutoCompleter | None = None,
13    printer: Printer = Console().print,
14) -> None:

Creates and configures an application instance.

  • prompt: Input prompt displayed before each command.

  • initial_message: Message displayed when the application starts.

  • farewell_message: Message displayed when exiting the application.

  • exit_command: Command that is marked as a trigger for exiting the application.

  • system_router_title: Title for the system router (contains the exit command).

  • dividing_line: Type of dividing line (StaticDividingLine or DynamicDividingLine).

  • repeat_command_groups_printing: If True, the list of available commands is displayed before each input.

  • override_system_messages: If True, standard formatting (colors, ASCII art) is disabled.

  • autocompleter: Instance of the AutoCompleter class responsible for command autocompletion.

  • printer: Функция для вывода всех системных сообщений.


Note

In applications on Argenta, the case of the entered commands is not important, checking for the existence and routing of commands is performed based on triggers reduced to lowercase.

Main Methods

  • include_router(self, router: Router) None

    Registers a router in the application. All commands from this router become available for invocation.

    Parameters:

    routerRouter instance to register.

  • include_routers(self, *routers: Router) None

    Registers multiple routers simultaneously.

    Parameters:

    routers – Sequence of Router instances to register.

  • add_message_on_startup(self, message: str) None

    Adds a text message that is displayed when the application starts after initial_message.

    Parameters:

    message – String with the message.

    See also

    For outputting standard messages, you can use ready-made templates from PredefinedMessages.


Handler Setup Methods

App allows you to configure responses to various events, such as input errors or unknown commands.

Hint

For more details on exceptions and their handling, see the corresponding documentation section.


set_description_message_pattern(self, handler: Callable[[str, str], str]) None

Sets the template for formatting command descriptions.

The handler accepts the command trigger (str) and its description (str).


set_incorrect_input_syntax_handler(self, handler: Callable[[str], None]) None

Sets the handler for incorrect flag syntax input.

The handler accepts the string entered by the user.


set_repeated_input_flags_handler(self, handler: Callable[[str], None]) None

Sets the handler for duplicate flags in the entered command.

The handler accepts the string entered by the user.


set_unknown_command_handler(self, handler: Callable[[InputCommand], None]) None

Sets the handler for entering an unknown command.

The handler accepts an InputCommand object - the entered command object.


set_empty_command_handler(self, handler: Callable[[], None]) None

Sets the handler for entering an empty string.

The handler accepts no arguments.


set_exit_command_handler(self, handler: Callable[[Response], None]) None

Overrides the default behavior when the exit command is invoked.

The handler accepts a Response object.


PredefinedMessages

PredefinedMessages is a container containing a set of ready-to-use messages. They are formatted using rich syntax and are intended for displaying standard information, such as usage hints.

It is recommended to use them when starting the application.

 1from argenta import App, Orchestrator
 2from argenta.app import PredefinedMessages
 3
 4app: App = App()
 5orchestrator: Orchestrator = Orchestrator()
 6
 7def main():
 8   app.add_message_on_startup(PredefinedMessages.USAGE)
 9   app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE)
10   app.add_message_on_startup(PredefinedMessages.HELP)
11
12   orchestrator.start_polling(app)
13
14if __name__ == "__main__":
15   main()
class PredefinedMessages
USAGE

String: [b dim]Usage[/b dim]: [i]<command> <[green]flags[/green]>[/i]

Displayed as: Usage: <command> <flags>

HELP

String: [b dim]Help[/b dim]: [i]<command>[/i] [b red]--help[/b red]

Displayed as: Help: <command> --help

AUTOCOMPLETE

String: [b dim]Autocomplete[/b dim]: [i]<part>[/i] [bold]<tab>

Displayed as: Autocomplete: <part> <tab>