Package: arguably
The best Python CLI library, arguably.arguablyturns functions and docstrings into command line interfaces (CLIs).arguablyhas a tiny API and is
extremely easy to integrate. You can also use it directly throughpython3 -m arguably your_script.py, more on thathere.To usearguablyin a script, decorate any functions that should appear on the command line with@arguably.command,
then callarguably.run(). If multiple functions are decorated, they'll all appear as subcommands. You can even havemultiple levelsof subcommands:def s3__ls()becomess3 ls.[source]#!/usr/bin/env python3importarguably@arguably.commanddefsome_function(required,not_required=2,*others:int,option:float=3.14):"""this function is on the command line!Args:required: a required argumentnot_required: this one isn't required, since it has a default value*others: all the other positional arguments go hereoption: [-x] keyword-only args are options, short name is in brackets"""print(f"{required=},{not_required=},{others=},{option=}")if__name__=="__main__":arguably.run()becomesuser@machine:~$./intro.py-husage: intro.py [-h] [-x OPTION] required [not-required] [others ...]this function is on the command line!positional arguments:required             a required argument (type: str)not-required         this one isn't required, since it has a default value (type: int, default: 2)others               all the other positional arguments go here (type: int)options:-h, --help           show this help message and exit-x, --option OPTION  keyword-only args are options, short name is in brackets (type: float, default: 3.14)Arguments to the CLI look just like calling the Python function.>>>fromintroimportsome_function>>>some_function("asdf",0,7,8,9,option=2.71)required='asdf', not_required=0, others=(7, 8, 9), option=2.71user@machine:~$./intro.pyasdf0789--option2.71required='asdf', not_required=0, others=(7, 8, 9), option=2.71arguablyuses your docstrings to automatically generate help messages. It supports all major formats for docstrings:
reStructuredText, Google, Numpydoc, and Epydoc.Type annotations are optional, butarguablycan use them to automatically convert arguments. It has smart handling for
mapping built-in types to the command line, includingtuple,list,enum.Enum, andenum.Flag.There are also a few special behaviors you can attach to a parameter viaAnnotated[]and thearguably.arg.*functions. Usingarguably.arg.builder(), you can even build an object to pass in from the command line (using syntax
inspired by QEMU):[source]user@machine:~$./build.py--nictap,model=e1000--nicuser,hostfwd=tcp::10022-:22nic=[TapNic(model='e1000'), UserNic(hostfwd='tcp::10022-:22')]No integration requiredDon't want to write any code? Simply pass any Python script toarguablyto give it a command line interface.[source]user@machine:~$python3-marguablyparty-trick.py-husage: party-trick [-h] [--version] command ...this is the docstring for the whole scriptpositional arguments:commandhello                   this is hello's docstringgoodbye                 any function from a script can be calledsome-class              so can any __init__ for objects defined in the scriptsome-class.func-static  a @staticmethod on a class can be calledsome-class.func-cls     so can a @classmethodoptions:-h, --help                show this help message and exit--version                 show program's version number and exitInstallationInstall usingpip install arguably. If you want to install usingconda, please comment onthis issue.DocumentationWhy arguably?:https://treykeown.github.io/arguably/why/Examples:https://treykeown.github.io/arguably/examples/Tutorial:https://treykeown.github.io/arguably/tutorial/intro/API Reference:https://treykeown.github.io/arguably/api-reference/DependenciesAll ofarguablyis built on top ofargparse. It has two dependencies:docstring-parserfor parsing function docstringstyping-extensionsforAnnotated[]support in Python 3.8 (only needed for that version)ContributingIdeas and help are very much appreciated! There's a guide for getting started with contributing toarguablythat shows
you how to run tests and pre-commit hooks.Contributing:https://treykeown.github.io/arguably/contributing/Future roadmapIf you have any interest in these (either as a user or implementer), please leave a comment!#8 - Display all enum options in a command group#9 - Both positive and negative boolean flags#10 - Take inputs from environment variables#13 - Implement config interface#16 - Integration with rich for formatted CLI output