clap-python
Command Line Argument Parser for Python
Licensed under Apache 2.0.
About
A full-featured, fast Command Line Argument Parser for Python
For more details, see:
Quick Start
pip install clap_python
from clap_python import App, Arg
app = (
App()
.version("0.1.0")
.arg_required_else_help(True)
.arg(Arg("--name", "-n").help("Name of the person to greet").required(True))
.arg(
Arg("--count", "-c")
.help("Number of times to greet")
.default(1)
.value_parser(int)
)
)
if __name__ == "__main__":
args = app.parse_args()
for _ in range(args["count"]):
print(f"Hello {args['name']}!")
Positionals
from clap_python import App, Arg
if __name__ == "__main__":
args = App().arg(Arg("names").multiple_values(True)).parse_args()
print(f"names: {args['names']}")
Autocomplete
from clap_python import App, Arg
from clap_python.complete import autocomplete
app = App().arg(Arg("-c")).arg(Arg("--files").multiple_values(True))
autocomplete(app)
args = app.parse_args()
print(args)
You can read more at docs