Typer makes it easy to compose your cli applications, like you might with a web router if you are more familiar with that. This allows you to build smaller applications that compose into a larger application.
You will see similar patterns in the wild, namely the aws cli which always has the aws <command> <subcommand> pattern.
Lets setup the cli app itself first. You can put it in project/cli/cli.py.
import typer from project.cli.api import api_app from project.cli.config import config_app from project.cli.user import user_app from project.cli.run import run_app app = typer.Typer() app.add_typer(api_app, name="api") app.add_typer(config_app, name="config") app.add_typer(user_app, name="user") app.add_typer(run_app, name="run")
Creating an app that will become a command is the same as creating a regular app in Typer. We need to create a callback that will become our command, and a command that will become our subcommand in the parent app.
...