Typer
CLI
Links
Typer
is a Python library for building command-line interface (CLI) applications that are easy to code and user-friendly. It leverages Python’s type hints to provide a natural way of defining CLI parameters, resulting in automatic generation of help messages, argument parsing, and shell completion. Typer is designed to be intuitive, allowing developers to create complex CLI applications with minimal code.
oaicite:0
Usage Example
Here’s a simple example of a Typer application:
import typer
def main(name: str):
typer.echo(f"Hello {name}")
if __name__ == "__main__":
typer.run(main)
To run this application, save it as main.py
and execute:
python main.py --name World
This will output:
Hello World
In this example, Typer uses the type hint str
to automatically handle the --name
argument, providing a seamless CLI experience.
oaicite:1