Library Typer
Typer is a library for creating command-line interface applications in Python. It makes it easy to create CLI applications with support for arguments, options, subcommands, and automatic help generation.
Main features of Typer:
- @typer.command() decorator for defining commands and subcommands.
- Automatic parsing of arguments and options.
- Validation and type annotations for arguments and options.
- Automatic help generation with descriptions.
- Built-in Click support for backward compatibility.
Typer is commonly used for creating command-line utilities, CLI interfaces for Python applications, API clients, DevOps tools, and other tasks where a simple and convenient command-line interface is needed.
import typer
app = typer.Typer()
@app.command()
def hello(name: str):
# Translation: "User greeting"
print(f"Hello {name}")
@app.command()
def goodbye(name: str, formal: bool = False):
# Translation: "Farewell to user"
if formal:
print(f"Goodbye Ms./Mr. {name}. Have a good day.")
else:
print(f"Bye {name}!")
if __name__ == "__main__":
app()
Page of .
Leave a comment
You must be logged in to leave a comment.
Log in or
sign up to join the discussion.
Comments (0)