## autoargs is argparse made easy
Have you ever felt like using argparse pulled you out of your Pythonic comfort zone? Argparse lets you skip the boilerplate when making apis to the command line:
>>> from autoargs import autocall, cmdable
>>> def str_repeat(s: str, n: int):
... print((s * n).strip())
>>> autocall(str_repeat, ["args are easy!\n", "3"])
args are easy!
args are easy!
args are easy!
>>> @cmdable
>>> def product(*args: float):
... return functools.reduce(operator.mul, args, 1.0)
>>> product.cmd(["5", "10", "0.5"])
25.0
>>> @cmdable
>>> def aggregate(*args: float, op: {'sum', 'mul'}):
... if op == "sum":
... return sum(args)
... elif op == "mul":
... return product(*args)
>>> aggregate.cmd(["--help"])
usage: aggregate [-h] --op {sum,mul} [args [args ...]]
positional arguments:
args float
optional arguments:
-h, --help show this help message and exit
--op {sum,mul}
>>> aggregate.cmd("--op mul 1 2 3 4")
24.0
Want to expose all of your modules functions to the command line, with nice parsers? That should be easy, right?
if __name__ == "__main__":
main = autoargs.namespace_dispatcher(locals(), sys.argv[0], __all__, __doc__)
autoargs.recursive_autocall(main, sys.argv[1:])
And now, suddenly your module is exposed to the command line, and each of the functions in your `__all__` is exposed as a subparser.
Some things to note:
- All args coming in from the command line are by default strings. If you want something else, annotate the arg with a function taking a string and returning the type you want.
- var kwargs are currently not supported (if you have any ideas on what the expected behavior of those should be, please comment on the github)
### TODO:
- finish documentation
- especially on recursive autocall and dispatchers (it's really cool, but a bit arcane)
- add more examples
- better readme...
- custom class for annotating args that lets you do more than one thing at once
- if you have any ideals, send me a note or open an issue on the github at https://github.com/metaperture/autoargs
Have you ever felt like using argparse pulled you out of your Pythonic comfort zone? Argparse lets you skip the boilerplate when making apis to the command line:
>>> from autoargs import autocall, cmdable
>>> def str_repeat(s: str, n: int):
... print((s * n).strip())
>>> autocall(str_repeat, ["args are easy!\n", "3"])
args are easy!
args are easy!
args are easy!
>>> @cmdable
>>> def product(*args: float):
... return functools.reduce(operator.mul, args, 1.0)
>>> product.cmd(["5", "10", "0.5"])
25.0
>>> @cmdable
>>> def aggregate(*args: float, op: {'sum', 'mul'}):
... if op == "sum":
... return sum(args)
... elif op == "mul":
... return product(*args)
>>> aggregate.cmd(["--help"])
usage: aggregate [-h] --op {sum,mul} [args [args ...]]
positional arguments:
args float
optional arguments:
-h, --help show this help message and exit
--op {sum,mul}
>>> aggregate.cmd("--op mul 1 2 3 4")
24.0
Want to expose all of your modules functions to the command line, with nice parsers? That should be easy, right?
if __name__ == "__main__":
main = autoargs.namespace_dispatcher(locals(), sys.argv[0], __all__, __doc__)
autoargs.recursive_autocall(main, sys.argv[1:])
And now, suddenly your module is exposed to the command line, and each of the functions in your `__all__` is exposed as a subparser.
Some things to note:
- All args coming in from the command line are by default strings. If you want something else, annotate the arg with a function taking a string and returning the type you want.
- var kwargs are currently not supported (if you have any ideas on what the expected behavior of those should be, please comment on the github)
### TODO:
- finish documentation
- especially on recursive autocall and dispatchers (it's really cool, but a bit arcane)
- add more examples
- better readme...
- custom class for annotating args that lets you do more than one thing at once
- if you have any ideals, send me a note or open an issue on the github at https://github.com/metaperture/autoargs
Metadata
Release files for autoargs 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| autoargs-0.0.2.tar.gz | 5.9 kB | Without provenance | Details |
Release files / autoargs-0.0.2.tar.gz
| Download URL | autoargs-0.0.2.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85198990627ab43b12524b40e0ec08ec50e1700d49b95c66a8ae7d982c928d6a
|
|
BLAKE2b-256 checksum How to use checksums |
83f6d943a781cf65ca30b621a266e2c0a232c3ac64ec20c30d18da9233935a58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for autoargs 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.