Typer

https://typer.tiangolo.com/

Simplest CLI

import typer


def main(name: str):
    print(f"Hello {name}")


if __name__ == "__main__":
    typer.run(main)

Hierarchical CLI (multiple entrypoints)

Please look through https://github.com/ezhang7423/language-control-diffusion/blob/main/src/lcd__main__.py

https://github.com/ezhang7423/language-control-diffusion/blob/main/src/lcd/__main__.py

Save Config Files

The following is all gratefully borrowed from https://maxb2.github.io/typer-config/1.2.1/examples/save_config/. Please attribute all credit to maxb2.

This example shows you how save the parameters of the invoked command to a configuration file using the @dump_config decorator which operates on Typer commands (requested in issue #25).

An example typer app:

  1. This package also provides @dump_yaml_config and @dump_toml_config for those file formats.

  2. If you put @use_json_config before @dump_json_config, you will not capture the config parameter in your config dump. You probably want this behavior to avoid cascading config files.

And invoked with python:

Last updated

Was this helpful?